mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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).
This diff was reverted a couple of times because of the change in the registration of eventDispatcher. That's why I'm gating that behavior change as part of the "StaticViewConfig" QE.
changelog: [internal] internal
Reviewed By: JoshuaGross
Differential Revision: D25858934
fbshipit-source-id: a632799ccac728d4efca44ee685519713b4a7cbb
This commit is contained in:
committed by
Facebook GitHub Bot
parent
280f524b49
commit
34351fd0b1
@@ -7,6 +7,8 @@
|
||||
|
||||
package com.facebook.react.fabric;
|
||||
|
||||
import static com.facebook.react.config.ReactFeatureFlags.enableExperimentalStaticViewConfigs;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.JSIModuleProvider;
|
||||
@@ -27,8 +29,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<UIManager> {
|
||||
@@ -36,14 +40,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
|
||||
@@ -79,20 +86,27 @@ 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 = getEventDispatcher();
|
||||
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;
|
||||
}
|
||||
|
||||
private EventDispatcher getEventDispatcher() {
|
||||
EventDispatcher eventDispatcher;
|
||||
if (enableExperimentalStaticViewConfigs) {
|
||||
eventDispatcher = new EventDispatcherImpl(mReactApplicationContext);
|
||||
} else {
|
||||
UIManagerModule nativeModule =
|
||||
Assertions.assertNotNull(mReactApplicationContext.getNativeModule(UIManagerModule.class));
|
||||
eventDispatcher = nativeModule.getEventDispatcher();
|
||||
}
|
||||
return eventDispatcher;
|
||||
}
|
||||
|
||||
// TODO T31905686: eager load Fabric classes, this is temporary and it will be removed
|
||||
// in the near future
|
||||
private static void loadClasses() {
|
||||
|
||||
Reference in New Issue
Block a user