Move fabric.Binding* to Kotlin (#44438)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44438

# Changelog:
[Internal] -

As in the title.

Reviewed By: javache

Differential Revision: D57046289

fbshipit-source-id: 383141821cc73c1cbbfc3aa168441cd051c4c2d6
This commit is contained in:
Ruslan Shestopalyuk
2024-05-07 08:23:44 -07:00
committed by Facebook GitHub Bot
parent c7dcdc1c09
commit b63a523c16
5 changed files with 186 additions and 191 deletions
@@ -2474,7 +2474,7 @@ public abstract interface class com/facebook/react/fabric/Binding {
public abstract fun unregisterSurface (Lcom/facebook/react/fabric/SurfaceHandlerBinding;)V
}
public class com/facebook/react/fabric/BindingImpl : com/facebook/react/fabric/Binding {
public final class com/facebook/react/fabric/BindingImpl : com/facebook/react/fabric/Binding {
public fun <init> ()V
public fun driveCxxAnimations ()V
public fun getInspectorDataForInstance (Lcom/facebook/react/fabric/events/EventEmitterWrapper;)Lcom/facebook/react/bridge/ReadableNativeMap;
@@ -1,69 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.fabric;
import androidx.annotation.NonNull;
import com.facebook.react.bridge.NativeMap;
import com.facebook.react.bridge.ReadableNativeMap;
import com.facebook.react.bridge.RuntimeExecutor;
import com.facebook.react.bridge.RuntimeScheduler;
import com.facebook.react.fabric.events.EventBeatManager;
import com.facebook.react.fabric.events.EventEmitterWrapper;
public interface Binding {
void startSurface(int surfaceId, @NonNull String moduleName, @NonNull NativeMap initialProps);
void startSurfaceWithConstraints(
int surfaceId,
String moduleName,
NativeMap initialProps,
float minWidth,
float maxWidth,
float minHeight,
float maxHeight,
float offsetX,
float offsetY,
boolean isRTL,
boolean doLeftAndRightSwapInRTL);
void stopSurface(int surfaceId);
void setPixelDensity(float pointScaleFactor);
void setConstraints(
int surfaceId,
float minWidth,
float maxWidth,
float minHeight,
float maxHeight,
float offsetX,
float offsetY,
boolean isRTL,
boolean doLeftAndRightSwapInRTL);
void driveCxxAnimations();
void reportMount(int surfaceId);
ReadableNativeMap getInspectorDataForInstance(EventEmitterWrapper eventEmitterWrapper);
void register(
@NonNull RuntimeExecutor runtimeExecutor,
@NonNull RuntimeScheduler runtimeScheduler,
@NonNull FabricUIManager fabricUIManager,
@NonNull EventBeatManager eventBeatManager,
@NonNull ComponentFactory componentFactory,
@NonNull ReactNativeConfig reactNativeConfig);
void unregister();
void registerSurface(SurfaceHandlerBinding surfaceHandler);
void unregisterSurface(SurfaceHandlerBinding surfaceHandler);
}
@@ -0,0 +1,72 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.fabric
import com.facebook.react.bridge.NativeMap
import com.facebook.react.bridge.ReadableNativeMap
import com.facebook.react.bridge.RuntimeExecutor
import com.facebook.react.bridge.RuntimeScheduler
import com.facebook.react.fabric.events.EventBeatManager
import com.facebook.react.fabric.events.EventEmitterWrapper
public interface Binding {
public fun startSurface(surfaceId: Int, moduleName: String, initialProps: NativeMap)
public fun startSurfaceWithConstraints(
surfaceId: Int,
moduleName: String,
initialProps: NativeMap,
minWidth: Float,
maxWidth: Float,
minHeight: Float,
maxHeight: Float,
offsetX: Float,
offsetY: Float,
isRTL: Boolean,
doLeftAndRightSwapInRTL: Boolean
)
public fun stopSurface(surfaceId: Int)
public fun setPixelDensity(pointScaleFactor: Float)
public fun setConstraints(
surfaceId: Int,
minWidth: Float,
maxWidth: Float,
minHeight: Float,
maxHeight: Float,
offsetX: Float,
offsetY: Float,
isRTL: Boolean,
doLeftAndRightSwapInRTL: Boolean
)
public fun driveCxxAnimations()
public fun reportMount(surfaceId: Int)
public fun getInspectorDataForInstance(
eventEmitterWrapper: EventEmitterWrapper?
): ReadableNativeMap?
public fun register(
runtimeExecutor: RuntimeExecutor,
runtimeScheduler: RuntimeScheduler,
fabricUIManager: FabricUIManager,
eventBeatManager: EventBeatManager,
componentFactory: ComponentFactory,
reactNativeConfig: ReactNativeConfig
)
public fun unregister()
public fun registerSurface(surfaceHandler: SurfaceHandlerBinding)
public fun unregisterSurface(surfaceHandler: SurfaceHandlerBinding)
}
@@ -1,121 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.fabric;
import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.NativeMap;
import com.facebook.react.bridge.ReadableNativeMap;
import com.facebook.react.bridge.RuntimeExecutor;
import com.facebook.react.bridge.RuntimeScheduler;
import com.facebook.react.common.mapbuffer.MapBufferSoLoader;
import com.facebook.react.fabric.events.EventBeatManager;
import com.facebook.react.fabric.events.EventEmitterWrapper;
import com.facebook.react.uimanager.PixelUtil;
@Nullsafe(Nullsafe.Mode.LOCAL)
@DoNotStrip
@SuppressLint("MissingNativeLoadLibrary")
public class BindingImpl implements Binding {
static {
FabricSoLoader.staticInit();
MapBufferSoLoader.staticInit();
}
@DoNotStrip private final HybridData mHybridData;
private static native HybridData initHybrid();
public BindingImpl() {
mHybridData = initHybrid();
}
private native void installFabricUIManager(
RuntimeExecutor runtimeExecutor,
RuntimeScheduler runtimeScheduler,
FabricUIManager uiManager,
EventBeatManager eventBeatManager,
ComponentFactory componentsRegistry,
Object reactNativeConfig);
@Override
public native void startSurface(
int surfaceId, @NonNull String moduleName, @NonNull NativeMap initialProps);
@Override
public native void startSurfaceWithConstraints(
int surfaceId,
String moduleName,
NativeMap initialProps,
float minWidth,
float maxWidth,
float minHeight,
float maxHeight,
float offsetX,
float offsetY,
boolean isRTL,
boolean doLeftAndRightSwapInRTL);
@Override
public native void stopSurface(int surfaceId);
@Override
public native void setPixelDensity(float pointScaleFactor);
@Override
public native void setConstraints(
int surfaceId,
float minWidth,
float maxWidth,
float minHeight,
float maxHeight,
float offsetX,
float offsetY,
boolean isRTL,
boolean doLeftAndRightSwapInRTL);
public native void driveCxxAnimations();
public native void reportMount(int surfaceId);
public native ReadableNativeMap getInspectorDataForInstance(
EventEmitterWrapper eventEmitterWrapper);
public void register(
@NonNull RuntimeExecutor runtimeExecutor,
@NonNull RuntimeScheduler runtimeScheduler,
@NonNull FabricUIManager fabricUIManager,
@NonNull EventBeatManager eventBeatManager,
@NonNull ComponentFactory componentFactory,
@NonNull ReactNativeConfig reactNativeConfig) {
fabricUIManager.setBinding(this);
installFabricUIManager(
runtimeExecutor,
runtimeScheduler,
fabricUIManager,
eventBeatManager,
componentFactory,
reactNativeConfig);
setPixelDensity(PixelUtil.getDisplayMetricDensity());
}
private native void uninstallFabricUIManager();
public void unregister() {
uninstallFabricUIManager();
}
public native void registerSurface(SurfaceHandlerBinding surfaceHandler);
public native void unregisterSurface(SurfaceHandlerBinding surfaceHandler);
}
@@ -0,0 +1,113 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.fabric
import android.annotation.SuppressLint
import com.facebook.jni.HybridData
import com.facebook.proguard.annotations.DoNotStrip
import com.facebook.react.bridge.NativeMap
import com.facebook.react.bridge.ReadableNativeMap
import com.facebook.react.bridge.RuntimeExecutor
import com.facebook.react.bridge.RuntimeScheduler
import com.facebook.react.common.mapbuffer.MapBufferSoLoader
import com.facebook.react.fabric.events.EventBeatManager
import com.facebook.react.fabric.events.EventEmitterWrapper
import com.facebook.react.uimanager.PixelUtil.getDisplayMetricDensity
@DoNotStrip
@SuppressLint("MissingNativeLoadLibrary")
public class BindingImpl : Binding {
@DoNotStrip @Suppress("NoHungarianNotation") private val mHybridData: HybridData = initHybrid()
private external fun installFabricUIManager(
runtimeExecutor: RuntimeExecutor,
runtimeScheduler: RuntimeScheduler,
uiManager: FabricUIManager,
eventBeatManager: EventBeatManager,
componentsRegistry: ComponentFactory,
reactNativeConfig: Any
)
external override fun startSurface(surfaceId: Int, moduleName: String, initialProps: NativeMap)
external override fun startSurfaceWithConstraints(
surfaceId: Int,
moduleName: String,
initialProps: NativeMap,
minWidth: Float,
maxWidth: Float,
minHeight: Float,
maxHeight: Float,
offsetX: Float,
offsetY: Float,
isRTL: Boolean,
doLeftAndRightSwapInRTL: Boolean
)
external override fun stopSurface(surfaceId: Int)
external override fun setPixelDensity(pointScaleFactor: Float)
external override fun setConstraints(
surfaceId: Int,
minWidth: Float,
maxWidth: Float,
minHeight: Float,
maxHeight: Float,
offsetX: Float,
offsetY: Float,
isRTL: Boolean,
doLeftAndRightSwapInRTL: Boolean
)
external override fun driveCxxAnimations()
external override fun reportMount(surfaceId: Int)
external override fun getInspectorDataForInstance(
eventEmitterWrapper: EventEmitterWrapper?
): ReadableNativeMap?
override fun register(
runtimeExecutor: RuntimeExecutor,
runtimeScheduler: RuntimeScheduler,
fabricUIManager: FabricUIManager,
eventBeatManager: EventBeatManager,
componentFactory: ComponentFactory,
reactNativeConfig: ReactNativeConfig
) {
fabricUIManager.setBinding(this)
installFabricUIManager(
runtimeExecutor,
runtimeScheduler,
fabricUIManager,
eventBeatManager,
componentFactory,
reactNativeConfig)
setPixelDensity(getDisplayMetricDensity())
}
private external fun uninstallFabricUIManager()
override fun unregister() {
uninstallFabricUIManager()
}
external override fun registerSurface(surfaceHandler: SurfaceHandlerBinding)
external override fun unregisterSurface(surfaceHandler: SurfaceHandlerBinding)
private companion object {
init {
FabricSoLoader.staticInit()
MapBufferSoLoader.staticInit()
}
@JvmStatic private external fun initHybrid(): HybridData
}
}