From d3a3ce857ef5a54e7014e06af194b596ec18a03e Mon Sep 17 00:00:00 2001 From: David Vacca Date: Wed, 6 Jan 2021 00:47:36 -0800 Subject: [PATCH] Refactor initialization of Fabric to avoid loading UIManagerModule Summary: This diff refactors the intialization of Fabric in order to avoid loading UIManagerModule as part of the creation of FabricJSIModuleProvider. One caveat is that now we are not taking into consideration the flag mLazyViewManagersEnabled ``` master/xplat/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java177 if (mLazyViewManagersEnabled) { ``` As a side effect of this diff view managers will be initialized twice if the user has fabric and paper enabled This diff was originally backed out in D25739854 (https://github.com/facebook/react-native/commit/4984c1e525e310f15c7d89230fdb2fa8fea91f05) because it produced a couple of bugs: - https://fb.workplace.com/groups/rn.support/permalink/4917641074951135/ - https://fb.workplace.com/groups/rn.support/permalink/4918163014898941/ These bugs are fixed by D25667987 (https://github.com/facebook/react-native/commit/2e631471092090e743245377742166ecae1d7e26). changelog: [internal] internal Reviewed By: JoshuaGross Differential Revision: D25746024 fbshipit-source-id: 3d12d29973a12b1edfea75f4dd954790f835e9bd --- .../react/fabric/FabricJSIModuleProvider.java | 18 ++++++++---------- .../react/uiapp/RNTesterApplication.java | 11 ++++++++++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricJSIModuleProvider.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricJSIModuleProvider.java index 86e5cf383739be..4ffef756aa1410 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricJSIModuleProvider.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricJSIModuleProvider.java @@ -8,7 +8,6 @@ package com.facebook.react.fabric; import androidx.annotation.NonNull; -import com.facebook.infer.annotation.Assertions; import com.facebook.react.bridge.JSIModuleProvider; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.UIManager; @@ -26,9 +25,10 @@ import com.facebook.react.fabric.mounting.mountitems.PreAllocateViewMountItem; import com.facebook.react.fabric.mounting.mountitems.SendAccessibilityEvent; import com.facebook.react.uimanager.StateWrapper; -import com.facebook.react.uimanager.UIManagerModule; +import com.facebook.react.uimanager.ViewManagerRegistry; import com.facebook.react.uimanager.events.BatchEventDispatchedListener; import com.facebook.react.uimanager.events.EventDispatcher; +import com.facebook.react.uimanager.events.EventDispatcherImpl; import com.facebook.systrace.Systrace; public class FabricJSIModuleProvider implements JSIModuleProvider { @@ -36,14 +36,17 @@ public class FabricJSIModuleProvider implements JSIModuleProvider { @NonNull private final ReactApplicationContext mReactApplicationContext; @NonNull private final ComponentFactory mComponentFactory; @NonNull private final ReactNativeConfig mConfig; + @NonNull private final ViewManagerRegistry mViewManagerRegistry; public FabricJSIModuleProvider( @NonNull ReactApplicationContext reactApplicationContext, @NonNull ComponentFactory componentFactory, - @NonNull ReactNativeConfig config) { + @NonNull ReactNativeConfig config, + @NonNull ViewManagerRegistry viewManagerRegistry) { mReactApplicationContext = reactApplicationContext; mComponentFactory = componentFactory; mConfig = config; + mViewManagerRegistry = viewManagerRegistry; } @Override @@ -79,15 +82,10 @@ public UIManager get() { private FabricUIManager createUIManager(@NonNull EventBeatManager eventBeatManager) { Systrace.beginSection( Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricJSIModuleProvider.createUIManager"); - UIManagerModule nativeModule = - Assertions.assertNotNull(mReactApplicationContext.getNativeModule(UIManagerModule.class)); - EventDispatcher eventDispatcher = nativeModule.getEventDispatcher(); + EventDispatcher eventDispatcher = new EventDispatcherImpl(mReactApplicationContext); FabricUIManager fabricUIManager = new FabricUIManager( - mReactApplicationContext, - nativeModule.getViewManagerRegistry_DO_NOT_USE(), - eventDispatcher, - eventBeatManager); + mReactApplicationContext, mViewManagerRegistry, eventDispatcher, eventBeatManager); Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); return fabricUIManager; diff --git a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java index b892f527c0e4a9..e8eec3ae80b7a3 100644 --- a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java +++ b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java @@ -34,6 +34,7 @@ import com.facebook.react.module.model.ReactModuleInfoProvider; import com.facebook.react.shell.MainReactPackage; import com.facebook.react.turbomodule.core.TurboModuleManager; +import com.facebook.react.uimanager.ViewManagerRegistry; import com.facebook.react.views.text.ReactFontManager; import com.facebook.soloader.SoLoader; import java.lang.reflect.InvocationTargetException; @@ -168,6 +169,13 @@ public JSIModuleType getJSIModuleType() { public JSIModuleProvider getJSIModuleProvider() { final ComponentFactory ComponentFactory = new ComponentFactory(); CoreComponentsRegistry.register(ComponentFactory); + final ReactInstanceManager reactInstanceManager = getReactInstanceManager(); + + ViewManagerRegistry viewManagerRegistry = + new ViewManagerRegistry( + reactInstanceManager.getOrCreateViewManagers( + reactApplicationContext)); + return new FabricJSIModuleProvider( reactApplicationContext, ComponentFactory, @@ -192,7 +200,8 @@ public String getString(final String s) { public double getDouble(final String s) { return 0; } - }); + }, + viewManagerRegistry); } }); }