From 18faf68b4825118253cf247572084c4da8f6366e Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 30 Sep 2024 07:31:56 -0700 Subject: [PATCH] Rename Binding to FabricUIManagerBinding (#46705) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46705 We have multiple classes in React Native Android acting as a binding layer (between C++ and Java, between C++ and JS). Make it more obvious this Binding is for (Android) FabricUIManager and flatten the (now) unused Binding interface. Changelog: [Android][Removed] BindingImpl is no longer part of the public interface Reviewed By: cortinico Differential Revision: D63536329 fbshipit-source-id: 329d184c1889fbe804995211cdd339b50a7c9234 --- .../ReactAndroid/api/ReactAndroid.api | 35 +----- .../java/com/facebook/react/fabric/Binding.kt | 78 ------------- .../react/fabric/FabricUIManager.java | 6 +- ...ndingImpl.kt => FabricUIManagerBinding.kt} | 38 ++++--- .../fabric/FabricUIManagerProviderImpl.java | 2 +- .../facebook/react/runtime/ReactInstance.java | 5 +- ...Binding.cpp => FabricUIManagerBinding.cpp} | 103 ++++++++++-------- .../{Binding.h => FabricUIManagerBinding.h} | 16 +-- .../jni/react/fabric/JFabricUIManager.cpp | 11 +- .../main/jni/react/fabric/JFabricUIManager.h | 4 +- .../src/main/jni/react/fabric/OnLoad.cpp | 4 +- 11 files changed, 96 insertions(+), 206 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/Binding.kt rename packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/{BindingImpl.kt => FabricUIManagerBinding.kt} (72%) rename packages/react-native/ReactAndroid/src/main/jni/react/fabric/{Binding.cpp => FabricUIManagerBinding.cpp} (86%) rename packages/react-native/ReactAndroid/src/main/jni/react/fabric/{Binding.h => FabricUIManagerBinding.h} (91%) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 5442b762839..b4513cccf9e 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 (ILcom/facebook/react/fabric/SurfaceHandlerBinding;Z)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 (ILcom/facebook/react/fabric/SurfaceHandlerBinding;Z)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 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 5d121d88068..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/Binding.kt +++ /dev/null @@ -1,78 +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( - surfaceId: Int, - surfaceHandler: SurfaceHandlerBinding, - isMountable: Boolean - ) - - 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 46307cb4200..e73cdff47d3 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; @@ -872,7 +872,7 @@ public class FabricUIManager } } - public void setBinding(Binding binding) { + public void setBinding(FabricUIManagerBinding binding) { mBinding = binding; } @@ -1271,7 +1271,7 @@ public class FabricUIManager 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 72% 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 ef414fe33c9..3bdcae44647 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,19 +53,19 @@ public class BindingImpl : Binding { doLeftAndRightSwapInRTL: Boolean ) - external override fun startSurfaceWithSurfaceHandler( + 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, @@ -73,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, @@ -104,7 +108,7 @@ public class BindingImpl : Binding { private external fun uninstallFabricUIManager() - override fun unregister() { + public fun unregister() { uninstallFabricUIManager() } @@ -113,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 cdb7249b0ba..e456226a030 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 class FabricUIManagerProviderImpl implements UIManagerProvider { 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/runtime/ReactInstance.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.java index 26fb9b93dbe..2edfe157f03 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.ReactQueueConfigurationImpl; 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 86% 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 dbfad6e5d92..afeb88aa648 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,7 +140,7 @@ void Binding::reportMount(SurfaceId surfaceId) { #pragma mark - Surface management // Used by bridgeless -void Binding::startSurfaceWithSurfaceHandler( +void FabricUIManagerBinding::startSurfaceWithSurfaceHandler( jint surfaceId, jni::alias_ref surfaceHandlerBinding, jboolean isMountable) { @@ -185,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) { @@ -232,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, @@ -267,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()); @@ -303,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 @@ -342,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"); @@ -375,7 +374,7 @@ void Binding::stopSurfaceWithSurfaceHandler( mountingManager->onSurfaceStop(surfaceHandler.getSurfaceId()); } -void Binding::setConstraints( +void FabricUIManagerBinding::setConstraints( jint surfaceId, jfloat minWidth, jfloat maxWidth, @@ -402,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; @@ -426,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, @@ -506,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 << ")."; @@ -519,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 @@ -531,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), @@ -560,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) { @@ -592,7 +591,7 @@ void Binding::schedulerShouldRenderTransactions( } } -void Binding::schedulerDidRequestPreliminaryViewAllocation( +void FabricUIManagerBinding::schedulerDidRequestPreliminaryViewAllocation( const ShadowNode& shadowNode) { auto mountingManager = getMountingManager("preallocateView"); if (!mountingManager) { @@ -614,7 +613,7 @@ void Binding::schedulerDidRequestPreliminaryViewAllocation( } } -void Binding::schedulerDidDispatchCommand( +void FabricUIManagerBinding::schedulerDidDispatchCommand( const ShadowView& shadowView, const std::string& commandName, const folly::dynamic& args) { @@ -625,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 = @@ -636,7 +635,7 @@ void Binding::schedulerDidSendAccessibilityEvent( mountingManager->sendAccessibilityEvent(shadowView, eventType); } -void Binding::schedulerDidSetIsJSResponder( +void FabricUIManagerBinding::schedulerDidSetIsJSResponder( const ShadowView& shadowView, bool isJSResponder, bool blockNativeResponder) { @@ -648,7 +647,7 @@ void Binding::schedulerDidSetIsJSResponder( shadowView, isJSResponder, blockNativeResponder); } -void Binding::onAnimationStarted() { +void FabricUIManagerBinding::onAnimationStarted() { auto mountingManager = getMountingManager("onAnimationStarted"); if (!mountingManager) { return; @@ -656,7 +655,7 @@ void Binding::onAnimationStarted() { mountingManager->onAnimationStarted(); } -void Binding::onAllAnimationsComplete() { +void FabricUIManagerBinding::onAllAnimationsComplete() { auto mountingManager = getMountingManager("onAnimationComplete"); if (!mountingManager) { return; @@ -664,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", Binding::installFabricUIManager), - makeNativeMethod("startSurface", Binding::startSurface), + "installFabricUIManager", + FabricUIManagerBinding::installFabricUIManager), + makeNativeMethod("startSurface", FabricUIManagerBinding::startSurface), makeNativeMethod( - "getInspectorDataForInstance", Binding::getInspectorDataForInstance), + "getInspectorDataForInstance", + FabricUIManagerBinding::getInspectorDataForInstance), makeNativeMethod( - "startSurfaceWithConstraints", Binding::startSurfaceWithConstraints), - makeNativeMethod("stopSurface", Binding::stopSurface), - makeNativeMethod("setConstraints", Binding::setConstraints), - makeNativeMethod("setPixelDensity", Binding::setPixelDensity), - makeNativeMethod("driveCxxAnimations", Binding::driveCxxAnimations), + "startSurfaceWithConstraints", + FabricUIManagerBinding::startSurfaceWithConstraints), + makeNativeMethod("stopSurface", FabricUIManagerBinding::stopSurface), makeNativeMethod( - "drainPreallocateViewsQueue", Binding::drainPreallocateViewsQueue), - makeNativeMethod("reportMount", Binding::reportMount), + "setConstraints", FabricUIManagerBinding::setConstraints), makeNativeMethod( - "uninstallFabricUIManager", Binding::uninstallFabricUIManager), + "setPixelDensity", FabricUIManagerBinding::setPixelDensity), + makeNativeMethod( + "driveCxxAnimations", FabricUIManagerBinding::driveCxxAnimations), + makeNativeMethod( + "drainPreallocateViewsQueue", + FabricUIManagerBinding::drainPreallocateViewsQueue), + makeNativeMethod("reportMount", FabricUIManagerBinding::reportMount), + makeNativeMethod( + "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 91% 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 7fa7fe01190..28941791ee7 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, @@ -151,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 48326b97c26..dbaff4920f5 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 5134ed59e50..c19701fe871 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 bcdf164ffab..7ebee5641c7 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();