diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 085cd2e001ee32..b4513cccf9e92c 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2578,39 +2578,6 @@ public abstract interface class com/facebook/react/devsupport/interfaces/StackFr public abstract fun toJSON ()Lorg/json/JSONObject; } -public abstract interface class com/facebook/react/fabric/Binding { - public abstract fun drainPreallocateViewsQueue ()V - public abstract fun driveCxxAnimations ()V - public abstract fun getInspectorDataForInstance (Lcom/facebook/react/fabric/events/EventEmitterWrapper;)Lcom/facebook/react/bridge/ReadableNativeMap; - public abstract fun register (Lcom/facebook/react/bridge/RuntimeExecutor;Lcom/facebook/react/bridge/RuntimeScheduler;Lcom/facebook/react/fabric/FabricUIManager;Lcom/facebook/react/fabric/events/EventBeatManager;Lcom/facebook/react/fabric/ComponentFactory;Lcom/facebook/react/fabric/ReactNativeConfig;)V - public abstract fun reportMount (I)V - public abstract fun setConstraints (IFFFFFFZZ)V - public abstract fun setPixelDensity (F)V - public abstract fun startSurface (ILjava/lang/String;Lcom/facebook/react/bridge/NativeMap;)V - public abstract fun startSurfaceWithConstraints (ILjava/lang/String;Lcom/facebook/react/bridge/NativeMap;FFFFFFZZ)V - public abstract fun startSurfaceWithSurfaceHandler (Lcom/facebook/react/fabric/SurfaceHandlerBinding;)V - public abstract fun stopSurface (I)V - public abstract fun stopSurfaceWithSurfaceHandler (Lcom/facebook/react/fabric/SurfaceHandlerBinding;)V - public abstract fun unregister ()V -} - -public final class com/facebook/react/fabric/BindingImpl : com/facebook/react/fabric/Binding { - public fun ()V - public fun drainPreallocateViewsQueue ()V - public fun driveCxxAnimations ()V - public fun getInspectorDataForInstance (Lcom/facebook/react/fabric/events/EventEmitterWrapper;)Lcom/facebook/react/bridge/ReadableNativeMap; - public fun register (Lcom/facebook/react/bridge/RuntimeExecutor;Lcom/facebook/react/bridge/RuntimeScheduler;Lcom/facebook/react/fabric/FabricUIManager;Lcom/facebook/react/fabric/events/EventBeatManager;Lcom/facebook/react/fabric/ComponentFactory;Lcom/facebook/react/fabric/ReactNativeConfig;)V - public fun reportMount (I)V - public fun setConstraints (IFFFFFFZZ)V - public fun setPixelDensity (F)V - public fun startSurface (ILjava/lang/String;Lcom/facebook/react/bridge/NativeMap;)V - public fun startSurfaceWithConstraints (ILjava/lang/String;Lcom/facebook/react/bridge/NativeMap;FFFFFFZZ)V - public fun startSurfaceWithSurfaceHandler (Lcom/facebook/react/fabric/SurfaceHandlerBinding;)V - public fun stopSurface (I)V - public fun stopSurfaceWithSurfaceHandler (Lcom/facebook/react/fabric/SurfaceHandlerBinding;)V - public fun unregister ()V -} - public final class com/facebook/react/fabric/ComponentFactory { public fun ()V } @@ -2715,7 +2682,7 @@ public class com/facebook/react/fabric/FabricUIManager : com/facebook/react/brid public fun resolveView (I)Landroid/view/View; public fun sendAccessibilityEvent (II)V public fun sendAccessibilityEventFromJS (IILjava/lang/String;)V - public fun setBinding (Lcom/facebook/react/fabric/Binding;)V + public fun setBinding (Lcom/facebook/react/fabric/FabricUIManagerBinding;)V public fun setJSResponder (IIIZ)V public fun startSurface (Landroid/view/View;Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;II)I public fun startSurface (Lcom/facebook/react/interfaces/fabric/SurfaceHandler;Landroid/content/Context;Landroid/view/View;)V @@ -2759,7 +2726,7 @@ public class com/facebook/react/fabric/StateWrapperImpl : com/facebook/react/uim public fun updateStateImpl (Lcom/facebook/react/bridge/NativeMap;)V } -public class com/facebook/react/fabric/SurfaceHandlerBinding : com/facebook/react/interfaces/fabric/SurfaceHandler { +public class com/facebook/react/fabric/SurfaceHandlerBinding : com/facebook/jni/HybridClassBase, com/facebook/react/interfaces/fabric/SurfaceHandler { public static final field DISPLAY_MODE_HIDDEN I public static final field DISPLAY_MODE_SUSPENDED I public static final field DISPLAY_MODE_VISIBLE I @@ -2770,10 +2737,6 @@ public class com/facebook/react/fabric/SurfaceHandlerBinding : com/facebook/reac public fun setLayoutConstraints (IIIIZZF)V public fun setMountable (Z)V public fun setProps (Lcom/facebook/react/bridge/NativeMap;)V - public fun setSurfaceId (I)V -} - -public abstract interface annotation class com/facebook/react/fabric/SurfaceHandlerBinding$DisplayModeTypeDef : java/lang/annotation/Annotation { } public final class com/facebook/react/fabric/events/EventBeatManager : com/facebook/react/uimanager/events/BatchEventDispatchedListener { @@ -2963,7 +2926,6 @@ public abstract interface class com/facebook/react/interfaces/fabric/SurfaceHand public abstract fun setLayoutConstraints (IIIIZZF)V public abstract fun setMountable (Z)V public abstract fun setProps (Lcom/facebook/react/bridge/NativeMap;)V - public abstract fun setSurfaceId (I)V } public final class com/facebook/react/jscexecutor/JSCExecutor : com/facebook/react/bridge/JavaScriptExecutor { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/Binding.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/Binding.kt deleted file mode 100644 index 12551259616838..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/Binding.kt +++ /dev/null @@ -1,74 +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 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 startSurfaceWithSurfaceHandler(surfaceHandler: SurfaceHandlerBinding) - - public fun stopSurface(surfaceId: Int) - - public fun stopSurfaceWithSurfaceHandler(surfaceHandler: SurfaceHandlerBinding) - - 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 drainPreallocateViewsQueue() - - 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() -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index 263ba93a21cf99..e73cdff47d3cb5 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -158,7 +158,7 @@ public class FabricUIManager FabricSoLoader.staticInit(); } - @Nullable private Binding mBinding; + @Nullable private FabricUIManagerBinding mBinding; @NonNull private final ReactApplicationContext mReactApplicationContext; @NonNull private final MountingManager mMountingManager; @NonNull private final EventDispatcher mEventDispatcher; @@ -328,12 +328,11 @@ public void startSurface( mReactApplicationContext, context, surfaceHandler.getModuleName(), rootTag); mMountingManager.startSurface(rootTag, reactContext, rootView); - surfaceHandler.setSurfaceId(rootTag); - surfaceHandler.setMountable(rootView != null); if (!(surfaceHandler instanceof SurfaceHandlerBinding)) { throw new IllegalArgumentException("Invalid SurfaceHandler"); } - mBinding.startSurfaceWithSurfaceHandler((SurfaceHandlerBinding) surfaceHandler); + mBinding.startSurfaceWithSurfaceHandler( + rootTag, (SurfaceHandlerBinding) surfaceHandler, rootView != null); } public void attachRootView(final SurfaceHandler surfaceHandler, final View rootView) { @@ -873,7 +872,7 @@ public void runGuarded() { } } - public void setBinding(Binding binding) { + public void setBinding(FabricUIManagerBinding binding) { mBinding = binding; } @@ -1272,7 +1271,7 @@ public void didMountItems(@Nullable List mountItems) { public void run() { mMountNotificationScheduled = false; - final @Nullable Binding binding = mBinding; + final @Nullable FabricUIManagerBinding binding = mBinding; if (binding == null || mDestroyed) { mMountedSurfaceIds.clear(); return; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/BindingImpl.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerBinding.kt similarity index 71% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/BindingImpl.kt rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerBinding.kt index f45383cbe663d3..3bdcae4464775b 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/BindingImpl.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerBinding.kt @@ -8,7 +8,7 @@ package com.facebook.react.fabric import android.annotation.SuppressLint -import com.facebook.jni.HybridData +import com.facebook.jni.HybridClassBase import com.facebook.proguard.annotations.DoNotStrip import com.facebook.react.bridge.NativeMap import com.facebook.react.bridge.ReadableNativeMap @@ -21,8 +21,12 @@ import com.facebook.react.uimanager.PixelUtil.getDisplayMetricDensity @DoNotStrip @SuppressLint("MissingNativeLoadLibrary") -public class BindingImpl : Binding { - @DoNotStrip @Suppress("NoHungarianNotation") private val mHybridData: HybridData = initHybrid() +internal class FabricUIManagerBinding : HybridClassBase() { + init { + initHybrid() + } + + private external fun initHybrid() private external fun installFabricUIManager( runtimeExecutor: RuntimeExecutor, @@ -33,9 +37,9 @@ public class BindingImpl : Binding { reactNativeConfig: Any ) - external override fun startSurface(surfaceId: Int, moduleName: String, initialProps: NativeMap) + public external fun startSurface(surfaceId: Int, moduleName: String, initialProps: NativeMap) - external override fun startSurfaceWithConstraints( + public external fun startSurfaceWithConstraints( surfaceId: Int, moduleName: String, initialProps: NativeMap, @@ -49,15 +53,19 @@ public class BindingImpl : Binding { doLeftAndRightSwapInRTL: Boolean ) - external override fun startSurfaceWithSurfaceHandler(surfaceHandler: SurfaceHandlerBinding) + public external fun startSurfaceWithSurfaceHandler( + surfaceId: Int, + surfaceHandler: SurfaceHandlerBinding, + isMountable: Boolean + ) - external override fun stopSurface(surfaceId: Int) + public external fun stopSurface(surfaceId: Int) - external override fun stopSurfaceWithSurfaceHandler(surfaceHandler: SurfaceHandlerBinding) + public external fun stopSurfaceWithSurfaceHandler(surfaceHandler: SurfaceHandlerBinding) - external override fun setPixelDensity(pointScaleFactor: Float) + public external fun setPixelDensity(pointScaleFactor: Float) - external override fun setConstraints( + public external fun setConstraints( surfaceId: Int, minWidth: Float, maxWidth: Float, @@ -69,17 +77,17 @@ public class BindingImpl : Binding { doLeftAndRightSwapInRTL: Boolean ) - external override fun driveCxxAnimations() + public external fun driveCxxAnimations() - external override fun drainPreallocateViewsQueue() + public external fun drainPreallocateViewsQueue() - external override fun reportMount(surfaceId: Int) + public external fun reportMount(surfaceId: Int) - external override fun getInspectorDataForInstance( + public external fun getInspectorDataForInstance( eventEmitterWrapper: EventEmitterWrapper? ): ReadableNativeMap? - override fun register( + public fun register( runtimeExecutor: RuntimeExecutor, runtimeScheduler: RuntimeScheduler, fabricUIManager: FabricUIManager, @@ -100,7 +108,7 @@ public class BindingImpl : Binding { private external fun uninstallFabricUIManager() - override fun unregister() { + public fun unregister() { uninstallFabricUIManager() } @@ -109,7 +117,5 @@ public class BindingImpl : Binding { FabricSoLoader.staticInit() MapBufferSoLoader.staticInit() } - - @JvmStatic private external fun initHybrid(): HybridData } } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerProviderImpl.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerProviderImpl.java index cdb7249b0bab8a..e456226a0306e4 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerProviderImpl.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerProviderImpl.java @@ -47,7 +47,7 @@ public UIManager createUIManager(ReactApplicationContext reactApplicationContext Systrace.beginSection( Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.registerBinding"); - final Binding binding = new BindingImpl(); + final FabricUIManagerBinding binding = new FabricUIManagerBinding(); CatalystInstance catalystInstance = reactApplicationContext.getCatalystInstance(); diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/SurfaceHandlerBinding.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/SurfaceHandlerBinding.java index 70381160c8a300..ca03205c016d61 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/SurfaceHandlerBinding.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/SurfaceHandlerBinding.java @@ -10,17 +10,13 @@ import static com.facebook.react.fabric.mounting.LayoutMetricsConversions.getMaxSize; import static com.facebook.react.fabric.mounting.LayoutMetricsConversions.getMinSize; -import androidx.annotation.IntDef; import com.facebook.infer.annotation.Nullsafe; -import com.facebook.jni.HybridData; -import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.jni.HybridClassBase; import com.facebook.react.bridge.NativeMap; import com.facebook.react.interfaces.fabric.SurfaceHandler; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; @Nullsafe(Nullsafe.Mode.LOCAL) -public class SurfaceHandlerBinding implements SurfaceHandler { +public class SurfaceHandlerBinding extends HybridClassBase implements SurfaceHandler { static { FabricSoLoader.staticInit(); } @@ -32,45 +28,20 @@ public class SurfaceHandlerBinding implements SurfaceHandler { public static final int DISPLAY_MODE_SUSPENDED = 1; public static final int DISPLAY_MODE_HIDDEN = 2; - @Retention(RetentionPolicy.SOURCE) - @IntDef({DISPLAY_MODE_VISIBLE, DISPLAY_MODE_SUSPENDED, DISPLAY_MODE_HIDDEN}) - public @interface DisplayModeTypeDef {} - - @DoNotStrip private final HybridData mHybridData; - - private static native HybridData initHybrid(int surfaceId, String moduleName); + private native void initHybrid(int surfaceId, String moduleName); public SurfaceHandlerBinding(String moduleName) { - mHybridData = initHybrid(NO_SURFACE_ID, moduleName); + initHybrid(NO_SURFACE_ID, moduleName); } @Override - public int getSurfaceId() { - return getSurfaceIdNative(); - } - - private native int getSurfaceIdNative(); - - @Override - public void setSurfaceId(int surfaceId) { - setSurfaceIdNative(surfaceId); - } - - private native void setSurfaceIdNative(int surfaceId); + public native int getSurfaceId(); @Override - public String getModuleName() { - return getModuleNameNative(); - } - - private native String getModuleNameNative(); + public native String getModuleName(); @Override - public boolean isRunning() { - return isRunningNative(); - } - - private native boolean isRunningNative(); + public native boolean isRunning(); @Override public void setLayoutConstraints( @@ -105,16 +76,12 @@ private native void setLayoutConstraintsNative( float pixelDensity); @Override - public void setProps(NativeMap props) { - setPropsNative(props); - } - - private native void setPropsNative(NativeMap props); + public native void setProps(NativeMap props); @Override public void setMountable(boolean mountable) { - setDisplayModeNative(mountable ? DISPLAY_MODE_VISIBLE : DISPLAY_MODE_SUSPENDED); + setDisplayMode(mountable ? DISPLAY_MODE_VISIBLE : DISPLAY_MODE_SUSPENDED); } - private native void setDisplayModeNative(@DisplayModeTypeDef int mode); + private native void setDisplayMode(int mode); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/interfaces/fabric/SurfaceHandler.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/interfaces/fabric/SurfaceHandler.kt index f8cc8c3680dec9..0c519049c49e22 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/interfaces/fabric/SurfaceHandler.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/interfaces/fabric/SurfaceHandler.kt @@ -29,7 +29,7 @@ public interface SurfaceHandler { /** * Updates current surface id. Id should be updated after each call to {@link SurfaceHandler#stop} */ - public fun setSurfaceId(surfaceId: Int) + // public fun setSurfaceId(surfaceId: Int) public fun setLayoutConstraints( widthMeasureSpec: Int, diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.java index 26fb9b93dbe5ba..2edfe157f03329 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.java @@ -40,10 +40,9 @@ import com.facebook.react.bridge.queue.ReactQueueConfigurationSpec; import com.facebook.react.devsupport.StackTraceHelper; import com.facebook.react.devsupport.interfaces.DevSupportManager; -import com.facebook.react.fabric.Binding; -import com.facebook.react.fabric.BindingImpl; import com.facebook.react.fabric.ComponentFactory; import com.facebook.react.fabric.FabricUIManager; +import com.facebook.react.fabric.FabricUIManagerBinding; import com.facebook.react.fabric.events.EventBeatManager; import com.facebook.react.interfaces.exceptionmanager.ReactJsExceptionHandler; import com.facebook.react.internal.AndroidChoreographerProvider; @@ -272,7 +271,7 @@ final class ReactInstance { // Misc initialization that needs to be done before Fabric init DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(mBridgelessReactContext); - Binding binding = new BindingImpl(); + FabricUIManagerBinding binding = new FabricUIManagerBinding(); binding.register( getBufferedRuntimeExecutor(), getRuntimeScheduler(), diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp similarity index 85% rename from packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp rename to packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp index fee956d5efec54..afeb88aa648364 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -#include "Binding.h" +#include "FabricUIManagerBinding.h" #include "AsyncEventBeat.h" #include "ComponentFactory.h" @@ -34,13 +34,12 @@ namespace facebook::react { -jni::local_ref Binding::initHybrid( - jni::alias_ref) { - return makeCxxInstance(); +void FabricUIManagerBinding::initHybrid(jni::alias_ref jobj) { + setCxxInstance(jobj); } // Thread-safe getter -std::shared_ptr Binding::getScheduler() { +std::shared_ptr FabricUIManagerBinding::getScheduler() { std::shared_lock lock(installMutex_); // Need to return a copy of the shared_ptr to make sure this is safe if called // concurrently with uninstallFabricUIManager @@ -48,7 +47,7 @@ std::shared_ptr Binding::getScheduler() { } jni::local_ref -Binding::getInspectorDataForInstance( +FabricUIManagerBinding::getInspectorDataForInstance( jni::alias_ref eventEmitterWrapper) { auto scheduler = getScheduler(); if (!scheduler) { @@ -81,18 +80,18 @@ static bool getFeatureFlagValue(const char* name) { static const auto reactFeatureFlagsClass = jni::findClassStatic(kReactFeatureFlagsJavaDescriptor); const auto field = reactFeatureFlagsClass->getStaticField(name); - return reactFeatureFlagsClass->getStaticFieldValue(field); + return reactFeatureFlagsClass->getStaticFieldValue(field) != 0; } -void Binding::setPixelDensity(float pointScaleFactor) { +void FabricUIManagerBinding::setPixelDensity(float pointScaleFactor) { pointScaleFactor_ = pointScaleFactor; } -void Binding::driveCxxAnimations() { +void FabricUIManagerBinding::driveCxxAnimations() { getScheduler()->animationTick(); } -void Binding::drainPreallocateViewsQueue() { +void FabricUIManagerBinding::drainPreallocateViewsQueue() { auto mountingManager = getMountingManager("drainPreallocateViewsQueue"); if (!mountingManager) { return; @@ -100,7 +99,7 @@ void Binding::drainPreallocateViewsQueue() { mountingManager->drainPreallocateViewsQueue(); } -void Binding::reportMount(SurfaceId surfaceId) { +void FabricUIManagerBinding::reportMount(SurfaceId surfaceId) { if (ReactNativeFeatureFlags:: fixMountingCoordinatorReportedPendingTransactionsOnAndroid()) { // This is a fix for `MountingCoordinator::hasPendingTransactions` on @@ -141,19 +140,23 @@ void Binding::reportMount(SurfaceId surfaceId) { #pragma mark - Surface management // Used by bridgeless -void Binding::startSurfaceWithSurfaceHandler( - jni::alias_ref - surfaceHandlerBinding) { +void FabricUIManagerBinding::startSurfaceWithSurfaceHandler( + jint surfaceId, + jni::alias_ref surfaceHandlerBinding, + jboolean isMountable) { SystraceSection s("FabricUIManagerBinding::startSurfaceWithSurfaceHandler"); - - const auto& surfaceHandler = - surfaceHandlerBinding->cthis()->getSurfaceHandler(); if (enableFabricLogs_) { LOG(WARNING) << "Binding::startSurfaceWithSurfaceHandler() was called (address: " - << this << ", surfaceId: " << surfaceHandler.getSurfaceId() << ")."; + << this << ", surfaceId: " << surfaceId << ")."; } + const auto& surfaceHandler = + surfaceHandlerBinding->cthis()->getSurfaceHandler(); + surfaceHandler.setSurfaceId(surfaceId); + surfaceHandler.setDisplayMode( + isMountable != 0 ? DisplayMode::Visible : DisplayMode::Suspended); + auto scheduler = getScheduler(); if (!scheduler) { LOG(ERROR) @@ -181,7 +184,7 @@ void Binding::startSurfaceWithSurfaceHandler( } // Used by non-bridgeless+Fabric -void Binding::startSurface( +void FabricUIManagerBinding::startSurface( jint surfaceId, jni::alias_ref moduleName, NativeMap* initialProps) { @@ -228,7 +231,7 @@ void Binding::startSurface( } // Used by non-bridgeless+Fabric -void Binding::startSurfaceWithConstraints( +void FabricUIManagerBinding::startSurfaceWithConstraints( jint surfaceId, jni::alias_ref moduleName, NativeMap* initialProps, @@ -263,12 +266,12 @@ void Binding::startSurfaceWithConstraints( context.viewportOffset = Point{offsetX / pointScaleFactor_, offsetY / pointScaleFactor_}; context.pointScaleFactor = {pointScaleFactor_}; - context.swapLeftAndRightInRTL = doLeftAndRightSwapInRTL; + context.swapLeftAndRightInRTL = doLeftAndRightSwapInRTL != 0; LayoutConstraints constraints = {}; constraints.minimumSize = minimumSize; constraints.maximumSize = maximumSize; constraints.layoutDirection = - isRTL ? LayoutDirection::RightToLeft : LayoutDirection::LeftToRight; + isRTL != 0 ? LayoutDirection::RightToLeft : LayoutDirection::LeftToRight; auto surfaceHandler = SurfaceHandler{moduleName->toStdString(), surfaceId}; surfaceHandler.setContextContainer(scheduler->getContextContainer()); @@ -299,7 +302,7 @@ void Binding::startSurfaceWithConstraints( } // Used by non-bridgeless+Fabric -void Binding::stopSurface(jint surfaceId) { +void FabricUIManagerBinding::stopSurface(jint surfaceId) { SystraceSection s("FabricUIManagerBinding::stopSurface"); if (enableFabricLogs_) { LOG(WARNING) << "Binding::stopSurface() was called (address: " << this @@ -338,7 +341,7 @@ void Binding::stopSurface(jint surfaceId) { } // Used by bridgeless -void Binding::stopSurfaceWithSurfaceHandler( +void FabricUIManagerBinding::stopSurfaceWithSurfaceHandler( jni::alias_ref surfaceHandlerBinding) { SystraceSection s("FabricUIManagerBinding::stopSurfaceWithSurfaceHandler"); @@ -371,7 +374,7 @@ void Binding::stopSurfaceWithSurfaceHandler( mountingManager->onSurfaceStop(surfaceHandler.getSurfaceId()); } -void Binding::setConstraints( +void FabricUIManagerBinding::setConstraints( jint surfaceId, jfloat minWidth, jfloat maxWidth, @@ -398,7 +401,7 @@ void Binding::setConstraints( context.viewportOffset = Point{offsetX / pointScaleFactor_, offsetY / pointScaleFactor_}; context.pointScaleFactor = {pointScaleFactor_}; - context.swapLeftAndRightInRTL = doLeftAndRightSwapInRTL; + context.swapLeftAndRightInRTL = doLeftAndRightSwapInRTL != 0; LayoutConstraints constraints = {}; constraints.minimumSize = minimumSize; constraints.maximumSize = maximumSize; @@ -422,7 +425,7 @@ void Binding::setConstraints( #pragma mark - Install/uninstall java binding -void Binding::installFabricUIManager( +void FabricUIManagerBinding::installFabricUIManager( jni::alias_ref runtimeExecutorHolder, jni::alias_ref runtimeSchedulerHolder, jni::alias_ref javaUIManager, @@ -502,7 +505,7 @@ void Binding::installFabricUIManager( std::make_shared(toolbox, animationDriver_.get(), this); } -void Binding::uninstallFabricUIManager() { +void FabricUIManagerBinding::uninstallFabricUIManager() { if (enableFabricLogs_) { LOG(WARNING) << "Binding::uninstallFabricUIManager() was called (address: " << this << ")."; @@ -515,8 +518,8 @@ void Binding::uninstallFabricUIManager() { reactNativeConfig_ = nullptr; } -std::shared_ptr Binding::getMountingManager( - const char* locationHint) { +std::shared_ptr +FabricUIManagerBinding::getMountingManager(const char* locationHint) { std::shared_lock lock(installMutex_); if (!mountingManager_) { LOG(ERROR) << "FabricMountingManager::" << locationHint @@ -527,7 +530,7 @@ std::shared_ptr Binding::getMountingManager( return mountingManager_; } -void Binding::schedulerDidFinishTransaction( +void FabricUIManagerBinding::schedulerDidFinishTransaction( const MountingCoordinator::Shared& mountingCoordinator) { // We shouldn't be pulling the transaction here (which triggers diffing of // the trees to determine the mutations to run on the host platform), @@ -556,8 +559,8 @@ void Binding::schedulerDidFinishTransaction( } } -void Binding::schedulerShouldRenderTransactions( - const MountingCoordinator::Shared& mountingCoordinator) { +void FabricUIManagerBinding::schedulerShouldRenderTransactions( + const MountingCoordinator::Shared& /* mountingCoordinator */) { auto mountingManager = getMountingManager("schedulerShouldRenderTransactions"); if (!mountingManager) { @@ -588,7 +591,7 @@ void Binding::schedulerShouldRenderTransactions( } } -void Binding::schedulerDidRequestPreliminaryViewAllocation( +void FabricUIManagerBinding::schedulerDidRequestPreliminaryViewAllocation( const ShadowNode& shadowNode) { auto mountingManager = getMountingManager("preallocateView"); if (!mountingManager) { @@ -610,7 +613,7 @@ void Binding::schedulerDidRequestPreliminaryViewAllocation( } } -void Binding::schedulerDidDispatchCommand( +void FabricUIManagerBinding::schedulerDidDispatchCommand( const ShadowView& shadowView, const std::string& commandName, const folly::dynamic& args) { @@ -621,7 +624,7 @@ void Binding::schedulerDidDispatchCommand( mountingManager->dispatchCommand(shadowView, commandName, args); } -void Binding::schedulerDidSendAccessibilityEvent( +void FabricUIManagerBinding::schedulerDidSendAccessibilityEvent( const ShadowView& shadowView, const std::string& eventType) { auto mountingManager = @@ -632,7 +635,7 @@ void Binding::schedulerDidSendAccessibilityEvent( mountingManager->sendAccessibilityEvent(shadowView, eventType); } -void Binding::schedulerDidSetIsJSResponder( +void FabricUIManagerBinding::schedulerDidSetIsJSResponder( const ShadowView& shadowView, bool isJSResponder, bool blockNativeResponder) { @@ -644,7 +647,7 @@ void Binding::schedulerDidSetIsJSResponder( shadowView, isJSResponder, blockNativeResponder); } -void Binding::onAnimationStarted() { +void FabricUIManagerBinding::onAnimationStarted() { auto mountingManager = getMountingManager("onAnimationStarted"); if (!mountingManager) { return; @@ -652,7 +655,7 @@ void Binding::onAnimationStarted() { mountingManager->onAnimationStarted(); } -void Binding::onAllAnimationsComplete() { +void FabricUIManagerBinding::onAllAnimationsComplete() { auto mountingManager = getMountingManager("onAnimationComplete"); if (!mountingManager) { return; @@ -660,31 +663,39 @@ void Binding::onAllAnimationsComplete() { mountingManager->onAllAnimationsComplete(); } -void Binding::registerNatives() { +void FabricUIManagerBinding::registerNatives() { registerHybrid({ - makeNativeMethod("initHybrid", Binding::initHybrid), + makeNativeMethod("initHybrid", FabricUIManagerBinding::initHybrid), + makeNativeMethod( + "installFabricUIManager", + FabricUIManagerBinding::installFabricUIManager), + makeNativeMethod("startSurface", FabricUIManagerBinding::startSurface), + makeNativeMethod( + "getInspectorDataForInstance", + FabricUIManagerBinding::getInspectorDataForInstance), + makeNativeMethod( + "startSurfaceWithConstraints", + FabricUIManagerBinding::startSurfaceWithConstraints), + makeNativeMethod("stopSurface", FabricUIManagerBinding::stopSurface), makeNativeMethod( - "installFabricUIManager", Binding::installFabricUIManager), - makeNativeMethod("startSurface", Binding::startSurface), + "setConstraints", FabricUIManagerBinding::setConstraints), makeNativeMethod( - "getInspectorDataForInstance", Binding::getInspectorDataForInstance), + "setPixelDensity", FabricUIManagerBinding::setPixelDensity), makeNativeMethod( - "startSurfaceWithConstraints", Binding::startSurfaceWithConstraints), - makeNativeMethod("stopSurface", Binding::stopSurface), - makeNativeMethod("setConstraints", Binding::setConstraints), - makeNativeMethod("setPixelDensity", Binding::setPixelDensity), - makeNativeMethod("driveCxxAnimations", Binding::driveCxxAnimations), + "driveCxxAnimations", FabricUIManagerBinding::driveCxxAnimations), makeNativeMethod( - "drainPreallocateViewsQueue", Binding::drainPreallocateViewsQueue), - makeNativeMethod("reportMount", Binding::reportMount), + "drainPreallocateViewsQueue", + FabricUIManagerBinding::drainPreallocateViewsQueue), + makeNativeMethod("reportMount", FabricUIManagerBinding::reportMount), makeNativeMethod( - "uninstallFabricUIManager", Binding::uninstallFabricUIManager), + "uninstallFabricUIManager", + FabricUIManagerBinding::uninstallFabricUIManager), makeNativeMethod( "startSurfaceWithSurfaceHandler", - Binding::startSurfaceWithSurfaceHandler), + FabricUIManagerBinding::startSurfaceWithSurfaceHandler), makeNativeMethod( "stopSurfaceWithSurfaceHandler", - Binding::stopSurfaceWithSurfaceHandler), + FabricUIManagerBinding::stopSurfaceWithSurfaceHandler), }); } diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.h b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.h similarity index 89% rename from packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.h rename to packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.h index 97579ecef4d3dd..28941791ee7fc2 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.h @@ -35,16 +35,12 @@ class LayoutAnimationDriver; class ReactNativeConfig; class Scheduler; -struct JBinding : public jni::JavaClass { - constexpr static auto kJavaDescriptor = "Lcom/facebook/react/fabric/Binding;"; -}; - -class Binding : public jni::HybridClass, - public SchedulerDelegate, - public LayoutAnimationStatusDelegate { +class FabricUIManagerBinding : public jni::HybridClass, + public SchedulerDelegate, + public LayoutAnimationStatusDelegate { public: constexpr static const char* const kJavaDescriptor = - "Lcom/facebook/react/fabric/BindingImpl;"; + "Lcom/facebook/react/fabric/FabricUIManagerBinding;"; static void registerNatives(); @@ -65,7 +61,7 @@ class Binding : public jni::HybridClass, jni::local_ref getInspectorDataForInstance( jni::alias_ref eventEmitterWrapper); - static jni::local_ref initHybrid(jni::alias_ref); + static void initHybrid(jni::alias_ref jobj); void installFabricUIManager( jni::alias_ref runtimeExecutorHolder, @@ -96,7 +92,10 @@ class Binding : public jni::HybridClass, void stopSurface(jint surfaceId); void startSurfaceWithSurfaceHandler( - jni::alias_ref surfaceHandler); + jint surfaceId, + jni::alias_ref + surfaceHandlerBinding, + jboolean isMountable); void stopSurfaceWithSurfaceHandler( jni::alias_ref surfaceHandler); @@ -148,8 +147,6 @@ class Binding : public jni::HybridClass, std::shared_ptr animationDriver_; - BackgroundExecutor backgroundExecutor_; - // Roots not created through ReactSurface (non-bridgeless) will store their // SurfaceHandler here, for other roots we keep a weak reference to the Java // owner diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp index 48326b97c260b3..dbaff4920f5dc7 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.cpp @@ -7,15 +7,14 @@ #include "JFabricUIManager.h" -#include "Binding.h" +#include "FabricUIManagerBinding.h" namespace facebook::react { -Binding* JFabricUIManager::getBinding() { +FabricUIManagerBinding* JFabricUIManager::getBinding() { static const auto bindingField = - javaClassStatic()->getField("mBinding"); - - return jni::static_ref_cast(getFieldValue(bindingField)) - ->cthis(); + javaClassStatic()->getField( + "mBinding"); + return getFieldValue(bindingField)->cthis(); } } // namespace facebook::react diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.h b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.h index 5134ed59e50ae4..c19701fe871fb1 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/JFabricUIManager.h @@ -11,14 +11,14 @@ namespace facebook::react { -class Binding; +class FabricUIManagerBinding; class JFabricUIManager : public jni::JavaClass { public: static constexpr auto kJavaDescriptor = "Lcom/facebook/react/fabric/FabricUIManager;"; - Binding* getBinding(); + FabricUIManagerBinding* getBinding(); }; } // namespace facebook::react diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp index bcdf164ffab430..7ebee5641c7d02 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp @@ -7,19 +7,19 @@ #include -#include "Binding.h" #include "ComponentFactory.h" #include "EventBeatManager.h" #include "EventEmitterWrapper.h" +#include "FabricUIManagerBinding.h" #include "JEmptyReactNativeConfig.h" #include "StateWrapperImpl.h" #include "SurfaceHandlerBinding.h" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) { return facebook::jni::initialize(vm, [] { - facebook::react::Binding::registerNatives(); facebook::react::EventBeatManager::registerNatives(); facebook::react::EventEmitterWrapper::registerNatives(); + facebook::react::FabricUIManagerBinding::registerNatives(); facebook::react::StateWrapperImpl::registerNatives(); facebook::react::ComponentFactory::registerNatives(); facebook::react::SurfaceHandlerBinding::registerNatives(); diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.cpp index 32518f1e42dab9..37e5624fced319 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.cpp @@ -23,10 +23,6 @@ jint SurfaceHandlerBinding::getSurfaceId() { return surfaceHandler_.getSurfaceId(); } -void SurfaceHandlerBinding::setSurfaceId(jint surfaceId) { - surfaceHandler_.setSurfaceId(surfaceId); -} - jboolean SurfaceHandlerBinding::isRunning() { return surfaceHandler_.getStatus() == SurfaceHandler::Status::Running; } @@ -35,12 +31,11 @@ jni::local_ref SurfaceHandlerBinding::getModuleName() { return jni::make_jstring(surfaceHandler_.getModuleName()); } -jni::local_ref -SurfaceHandlerBinding::initHybrid( - jni::alias_ref, +void SurfaceHandlerBinding::initHybrid( + jni::alias_ref jobj, jint surfaceId, jni::alias_ref moduleName) { - return makeCxxInstance(surfaceId, moduleName->toStdString()); + return setCxxInstance(jobj, surfaceId, moduleName->toStdString()); } void SurfaceHandlerBinding::setLayoutConstraints( @@ -78,19 +73,14 @@ const SurfaceHandler& SurfaceHandlerBinding::getSurfaceHandler() { void SurfaceHandlerBinding::registerNatives() { registerHybrid({ makeNativeMethod("initHybrid", SurfaceHandlerBinding::initHybrid), - makeNativeMethod( - "getSurfaceIdNative", SurfaceHandlerBinding::getSurfaceId), - makeNativeMethod( - "setSurfaceIdNative", SurfaceHandlerBinding::setSurfaceId), - makeNativeMethod("isRunningNative", SurfaceHandlerBinding::isRunning), - makeNativeMethod( - "getModuleNameNative", SurfaceHandlerBinding::getModuleName), + makeNativeMethod("getSurfaceId", SurfaceHandlerBinding::getSurfaceId), + makeNativeMethod("isRunning", SurfaceHandlerBinding::isRunning), + makeNativeMethod("getModuleName", SurfaceHandlerBinding::getModuleName), makeNativeMethod( "setLayoutConstraintsNative", SurfaceHandlerBinding::setLayoutConstraints), - makeNativeMethod("setPropsNative", SurfaceHandlerBinding::setProps), - makeNativeMethod( - "setDisplayModeNative", SurfaceHandlerBinding::setDisplayMode), + makeNativeMethod("setProps", SurfaceHandlerBinding::setProps), + makeNativeMethod("setDisplayMode", SurfaceHandlerBinding::setDisplayMode), }); } diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.h b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.h index cba7e8f131db80..7ecc6d4f94f071 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.h @@ -27,7 +27,6 @@ class SurfaceHandlerBinding : public jni::HybridClass { void setDisplayMode(jint mode); jint getSurfaceId(); - void setSurfaceId(jint surfaceId); jni::local_ref getModuleName(); jboolean isRunning(); @@ -50,10 +49,8 @@ class SurfaceHandlerBinding : public jni::HybridClass { private: const SurfaceHandler surfaceHandler_; - jni::alias_ref jhybridobject_; - - static jni::local_ref initHybrid( - jni::alias_ref, + static void initHybrid( + jni::alias_ref jobj, jint surfaceId, jni::alias_ref moduleName); }; diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/runtime/ReactSurfaceTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/runtime/ReactSurfaceTest.kt index 084eb11dd90c2f..5c1e4f9837dbd1 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/runtime/ReactSurfaceTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/runtime/ReactSurfaceTest.kt @@ -165,11 +165,8 @@ class ReactSurfaceTest { internal class TestSurfaceHandler : SurfaceHandler { override var isRunning = false - override val moduleName: String = "TestSurfaceHandler" - override val surfaceId - get() = _surfaceId - - private var _surfaceId = 0 + override val moduleName = "TestSurfaceHandler" + override val surfaceId = 0 var heightMeasureSpec = 0 var widthMeasureSpec = 0 @@ -202,9 +199,5 @@ class ReactSurfaceTest { override fun setProps(props: NativeMap) { // no-op } - - override fun setSurfaceId(surfaceId: Int) { - _surfaceId = surfaceId - } } }