diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 3c701b5930c..2ca2680741b 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2632,7 +2632,7 @@ public class com/facebook/react/fabric/FabricUIManager : com/facebook/react/brid public fun updateRootLayoutSpecs (IIIII)V } -public class com/facebook/react/fabric/FabricUIManagerProviderImpl : com/facebook/react/bridge/UIManagerProvider { +public final class com/facebook/react/fabric/FabricUIManagerProviderImpl : com/facebook/react/bridge/UIManagerProvider { public fun (Lcom/facebook/react/fabric/ComponentFactory;Lcom/facebook/react/uimanager/ViewManagerRegistry;)V public fun createUIManager (Lcom/facebook/react/bridge/ReactApplicationContext;)Lcom/facebook/react/bridge/UIManager; } 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 deleted file mode 100644 index e694c36f4aa..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerProviderImpl.java +++ /dev/null @@ -1,67 +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.infer.annotation.Nullsafe; -import com.facebook.react.bridge.CatalystInstance; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.RuntimeExecutor; -import com.facebook.react.bridge.RuntimeScheduler; -import com.facebook.react.bridge.UIManager; -import com.facebook.react.bridge.UIManagerProvider; -import com.facebook.react.fabric.events.EventBeatManager; -import com.facebook.react.uimanager.ViewManagerRegistry; -import com.facebook.systrace.Systrace; - -@Nullsafe(Nullsafe.Mode.LOCAL) -public class FabricUIManagerProviderImpl implements UIManagerProvider { - - private final ComponentFactory mComponentFactory; - private final ViewManagerRegistry mViewManagerRegistry; - - public FabricUIManagerProviderImpl( - ComponentFactory componentFactory, ViewManagerRegistry viewManagerRegistry) { - mComponentFactory = componentFactory; - mViewManagerRegistry = viewManagerRegistry; - } - - public UIManager createUIManager(ReactApplicationContext reactApplicationContext) { - Systrace.beginSection( - Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.create"); - EventBeatManager eventBeatManager = new EventBeatManager(); - Systrace.beginSection( - Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.createUIManager"); - - FabricUIManager fabricUIManager = - new FabricUIManager(reactApplicationContext, mViewManagerRegistry, eventBeatManager); - Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); - - Systrace.beginSection( - Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.registerBinding"); - final FabricUIManagerBinding binding = new FabricUIManagerBinding(); - - CatalystInstance catalystInstance = reactApplicationContext.getCatalystInstance(); - - RuntimeExecutor runtimeExecutor = catalystInstance.getRuntimeExecutor(); - RuntimeScheduler runtimeScheduler = catalystInstance.getRuntimeScheduler(); - - if (runtimeExecutor != null && runtimeScheduler != null) { - binding.register( - runtimeExecutor, runtimeScheduler, fabricUIManager, eventBeatManager, mComponentFactory); - } else { - throw new IllegalStateException( - "Unable to register FabricUIManager with CatalystInstance, runtimeExecutor and" - + " runtimeScheduler must not be null"); - } - - Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); - Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); - - return fabricUIManager; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerProviderImpl.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerProviderImpl.kt new file mode 100644 index 00000000000..1398c4d487e --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManagerProviderImpl.kt @@ -0,0 +1,73 @@ +/* + * 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.ReactApplicationContext +import com.facebook.react.bridge.UIManager +import com.facebook.react.bridge.UIManagerProvider +import com.facebook.react.fabric.events.EventBeatManager +import com.facebook.react.uimanager.ViewManagerRegistry +import com.facebook.systrace.Systrace + +/** + * Implementation of the UIManagerProvider for Fabric renderer on bridge mode + * + * @param [componentFactory] The factory for creating components. + * @param [viewManagerRegistry] The registry of view managers. + */ +public class FabricUIManagerProviderImpl( + private val componentFactory: ComponentFactory, + private val viewManagerRegistry: ViewManagerRegistry +) : UIManagerProvider { + + /** + * Creates a UIManager instance for the provided ReactApplicationContext. + * + * This method initializes tracing sections for performance monitoring, creates a FabricUIManager + * using the supplied ReactApplicationContext and ViewManagerRegistry, manages event beats, and + * registers FabricUIManagerBinding with the runtime environment of the provided + * ReactApplicationContext. + * + * @param context The React application context. + * @return A newly created FabricUIManager instance. + * @throws IllegalStateException If runtimeExecutor or runtimeScheduler is null. + */ + override fun createUIManager(context: ReactApplicationContext): UIManager { + Systrace.beginSection( + Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.create") + val eventBeatManager = EventBeatManager() + Systrace.beginSection( + Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.createUIManager") + + val fabricUIManager = FabricUIManager(context, viewManagerRegistry, eventBeatManager) + Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE) + + Systrace.beginSection( + Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManagerProviderImpl.registerBinding") + val binding = FabricUIManagerBinding() + + val catalystInstance = context.catalystInstance + + val runtimeExecutor = catalystInstance?.runtimeExecutor + val runtimeScheduler = catalystInstance?.runtimeScheduler + + if (runtimeExecutor != null && runtimeScheduler != null) { + binding.register( + runtimeExecutor, runtimeScheduler, fabricUIManager, eventBeatManager, componentFactory) + } else { + throw IllegalStateException( + "Unable to register FabricUIManager with CatalystInstance, runtimeExecutor and" + + " runtimeScheduler must not be null") + } + + Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE) + Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE) + + return fabricUIManager + } +}