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

https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java?commit=4fb6c5ae79bb8e78e852a811128f03cf6fbed9aa&lines=177

As a side effect of this diff view managers will be initialized twice if the user has fabric and paper enabled

changelog: [internal] internal

Reviewed By: shergin

Differential Revision: D25468183

fbshipit-source-id: 78d8069007c5a98f9a6825eaa0c174603c8b9b4f
This commit is contained in:
David Vacca
2020-12-29 10:42:18 -08:00
committed by Facebook GitHub Bot
parent 72ddd69222
commit c776f09e5f
2 changed files with 18 additions and 11 deletions
@@ -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;
@@ -34,9 +33,10 @@ import com.facebook.react.fabric.mounting.mountitems.UpdatePaddingMountItem;
import com.facebook.react.fabric.mounting.mountitems.UpdatePropsMountItem;
import com.facebook.react.fabric.mounting.mountitems.UpdateStateMountItem;
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<UIManager> {
@@ -44,14 +44,17 @@ public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
@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
@@ -87,15 +90,10 @@ public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
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;