From 939cbf12bcbb01e4dc464dace1576827630dbe13 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Wed, 25 Oct 2023 15:47:23 -0700 Subject: [PATCH] FabricJSIModuleProvider -> FabricUIManagerProviderImpl (#231) Summary: X-link: https://github.com/facebook/react-native/pull/39545 1. Refactoring `FabricJSIModuleProvider` to implement the newly added `UIManagerProvider` interface instead of the `JSIModuleProvider` in order to get rid of JSI Module thereby renaming it to `FabricUIManagerProviderImpl` 2. Adding `setTurboModuleRegistry(TurboModuleRegistry turboModuleRegistry)`, `setFabricUIManager(UIManager fabricUIManager)`, `getFabricUIManager()` instead of `setTurboModuleManager(JSIModule getter)` 3. Replacing `mJSIModuleRegistry.notifyJSInstanceDestroy()` with `mTurboModuleRegistry.invalidate();` Changelog: [Internal] internal Differential Revision: D49259735 --- .../MainApplicationReactNativeHost.java | 61 ++++++------------- 1 file changed, 17 insertions(+), 44 deletions(-) diff --git a/app/android/app/src/main/java/dev/playtorch/newarchitecture/MainApplicationReactNativeHost.java b/app/android/app/src/main/java/dev/playtorch/newarchitecture/MainApplicationReactNativeHost.java index 3da21d2d6..3e19f9f93 100644 --- a/app/android/app/src/main/java/dev/playtorch/newarchitecture/MainApplicationReactNativeHost.java +++ b/app/android/app/src/main/java/dev/playtorch/newarchitecture/MainApplicationReactNativeHost.java @@ -14,22 +14,16 @@ import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; 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.JavaScriptContextHolder; 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.CoreComponentsRegistry; -import com.facebook.react.fabric.FabricJSIModuleProvider; +import com.facebook.react.fabric.FabricUIManagerProviderImpl; import com.facebook.react.fabric.ReactNativeConfig; import com.facebook.react.uimanager.ViewManagerRegistry; import dev.playtorch.BuildConfig; import dev.playtorch.newarchitecture.components.MainComponentsRegistry; import dev.playtorch.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate; -import java.util.ArrayList; import java.util.List; /** @@ -76,47 +70,26 @@ protected String getJSMainModuleName() { } @Override - protected JSIModulePackage getJSIModulePackage() { - return new JSIModulePackage() { + protected Function1 getUIManagerProviderFunction() { + return new Function1() { @Override - public List getJSIModules( - final ReactApplicationContext reactApplicationContext, - final JavaScriptContextHolder jsContext) { - final List specs = new ArrayList<>(); + public UIManagerProvider invoke(ReactApplicationContext reactApplicationContext) { + final ComponentFactory componentFactory = new ComponentFactory(); + CoreComponentsRegistry.register(componentFactory); - // Here we provide a new JSIModuleSpec that will be responsible of providing the - // custom Fabric Components. - specs.add( - new JSIModuleSpec() { - @Override - public JSIModuleType getJSIModuleType() { - return JSIModuleType.UIManager; - } + // Here we register a Components Registry. + // The one that is generated with the template contains no components + // and just provides you the one from React Native core. + MainComponentsRegistry.register(componentFactory); - @Override - public JSIModuleProvider getJSIModuleProvider() { - final ComponentFactory componentFactory = new ComponentFactory(); - CoreComponentsRegistry.register(componentFactory); + final ReactInstanceManager reactInstanceManager = getReactInstanceManager(); - // Here we register a Components Registry. - // The one that is generated with the template contains no components - // and just provides you the one from React Native core. - MainComponentsRegistry.register(componentFactory); + ViewManagerRegistry viewManagerRegistry = + new ViewManagerRegistry( + reactInstanceManager.getOrCreateViewManagers(reactApplicationContext)); - final ReactInstanceManager reactInstanceManager = getReactInstanceManager(); - - ViewManagerRegistry viewManagerRegistry = - new ViewManagerRegistry( - reactInstanceManager.getOrCreateViewManagers(reactApplicationContext)); - - return new FabricJSIModuleProvider( - reactApplicationContext, - componentFactory, - ReactNativeConfig.DEFAULT_CONFIG, - viewManagerRegistry); - } - }); - return specs; + return new FabricUIManagerProviderImpl( + componentFactory, ReactNativeConfig.DEFAULT_CONFIG, viewManagerRegistry); } }; }