From eb3ee4d1322ac266f394008f7602c5881e367d0d Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Fri, 10 Nov 2023 02:30:18 -0800 Subject: [PATCH] Refactor DefaultReactNativeHost to use the new way of Fabric initialization (#41374) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41374 Refactoring `DefaultReactNativeHost` to use the new way of Fabric initialization through `FabricUIManagerProviderImpl` Changelog: [Internal] internal Reviewed By: philIip, luluwu2032 Differential Revision: D50926872 fbshipit-source-id: be2bcea7b2ce7cb1b3f903dc92fcd2c91be267da --- .../react/defaults/DefaultReactNativeHost.kt | 36 ++++++------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactNativeHost.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactNativeHost.kt index 60c1e791912b42..e5683059a68bdb 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactNativeHost.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactNativeHost.kt @@ -14,12 +14,8 @@ import com.facebook.react.ReactHost import com.facebook.react.ReactInstanceManager import com.facebook.react.ReactNativeHost import com.facebook.react.ReactPackageTurboModuleManagerDelegate -import com.facebook.react.bridge.JSIModulePackage -import com.facebook.react.bridge.JSIModuleProvider -import com.facebook.react.bridge.JSIModuleSpec -import com.facebook.react.bridge.JSIModuleType import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.bridge.UIManager +import com.facebook.react.bridge.UIManagerProvider import com.facebook.react.fabric.ComponentFactory import com.facebook.react.fabric.FabricUIManagerProviderImpl import com.facebook.react.fabric.ReactNativeConfig @@ -46,30 +42,20 @@ protected constructor( null } - override fun getJSIModulePackage(): JSIModulePackage? = + override fun getUIManagerProvider(): UIManagerProvider? = if (isNewArchEnabled) { - JSIModulePackage { reactApplicationContext: ReactApplicationContext, _ -> - listOf( - object : JSIModuleSpec { - override fun getJSIModuleType(): JSIModuleType = JSIModuleType.UIManager + UIManagerProvider { reactApplicationContext: ReactApplicationContext -> + val componentFactory = ComponentFactory() - override fun getJSIModuleProvider(): JSIModuleProvider { - val componentFactory = ComponentFactory() + DefaultComponentsRegistry.register(componentFactory) - DefaultComponentsRegistry.register(componentFactory) + val reactInstanceManager: ReactInstanceManager = getReactInstanceManager() - val reactInstanceManager: ReactInstanceManager = getReactInstanceManager() - - val viewManagers = - reactInstanceManager.getOrCreateViewManagers(reactApplicationContext) - val viewManagerRegistry = ViewManagerRegistry(viewManagers) - return FabricUIManagerProviderImpl( - reactApplicationContext, - componentFactory, - ReactNativeConfig.DEFAULT_CONFIG, - viewManagerRegistry) - } - }) + val viewManagers = reactInstanceManager.getOrCreateViewManagers(reactApplicationContext) + val viewManagerRegistry = ViewManagerRegistry(viewManagers) + FabricUIManagerProviderImpl( + componentFactory, ReactNativeConfig.DEFAULT_CONFIG, viewManagerRegistry) + .createUIManager(reactApplicationContext) } } else { null