Skip to content

Commit d3a3ce8

Browse files
mdvaccafacebook-github-bot
authored andcommitted
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 (facebook@4984c1e) 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 (facebook@2e63147). changelog: [internal] internal Reviewed By: JoshuaGross Differential Revision: D25746024 fbshipit-source-id: 3d12d29973a12b1edfea75f4dd954790f835e9bd
1 parent 2e63147 commit d3a3ce8

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

ReactAndroid/src/main/java/com/facebook/react/fabric/FabricJSIModuleProvider.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
package com.facebook.react.fabric;
99

1010
import androidx.annotation.NonNull;
11-
import com.facebook.infer.annotation.Assertions;
1211
import com.facebook.react.bridge.JSIModuleProvider;
1312
import com.facebook.react.bridge.ReactApplicationContext;
1413
import com.facebook.react.bridge.UIManager;
@@ -26,24 +25,28 @@
2625
import com.facebook.react.fabric.mounting.mountitems.PreAllocateViewMountItem;
2726
import com.facebook.react.fabric.mounting.mountitems.SendAccessibilityEvent;
2827
import com.facebook.react.uimanager.StateWrapper;
29-
import com.facebook.react.uimanager.UIManagerModule;
28+
import com.facebook.react.uimanager.ViewManagerRegistry;
3029
import com.facebook.react.uimanager.events.BatchEventDispatchedListener;
3130
import com.facebook.react.uimanager.events.EventDispatcher;
31+
import com.facebook.react.uimanager.events.EventDispatcherImpl;
3232
import com.facebook.systrace.Systrace;
3333

3434
public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
3535

3636
@NonNull private final ReactApplicationContext mReactApplicationContext;
3737
@NonNull private final ComponentFactory mComponentFactory;
3838
@NonNull private final ReactNativeConfig mConfig;
39+
@NonNull private final ViewManagerRegistry mViewManagerRegistry;
3940

4041
public FabricJSIModuleProvider(
4142
@NonNull ReactApplicationContext reactApplicationContext,
4243
@NonNull ComponentFactory componentFactory,
43-
@NonNull ReactNativeConfig config) {
44+
@NonNull ReactNativeConfig config,
45+
@NonNull ViewManagerRegistry viewManagerRegistry) {
4446
mReactApplicationContext = reactApplicationContext;
4547
mComponentFactory = componentFactory;
4648
mConfig = config;
49+
mViewManagerRegistry = viewManagerRegistry;
4750
}
4851

4952
@Override
@@ -79,15 +82,10 @@ public UIManager get() {
7982
private FabricUIManager createUIManager(@NonNull EventBeatManager eventBeatManager) {
8083
Systrace.beginSection(
8184
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricJSIModuleProvider.createUIManager");
82-
UIManagerModule nativeModule =
83-
Assertions.assertNotNull(mReactApplicationContext.getNativeModule(UIManagerModule.class));
84-
EventDispatcher eventDispatcher = nativeModule.getEventDispatcher();
85+
EventDispatcher eventDispatcher = new EventDispatcherImpl(mReactApplicationContext);
8586
FabricUIManager fabricUIManager =
8687
new FabricUIManager(
87-
mReactApplicationContext,
88-
nativeModule.getViewManagerRegistry_DO_NOT_USE(),
89-
eventDispatcher,
90-
eventBeatManager);
88+
mReactApplicationContext, mViewManagerRegistry, eventDispatcher, eventBeatManager);
9189

9290
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
9391
return fabricUIManager;

packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.facebook.react.module.model.ReactModuleInfoProvider;
3535
import com.facebook.react.shell.MainReactPackage;
3636
import com.facebook.react.turbomodule.core.TurboModuleManager;
37+
import com.facebook.react.uimanager.ViewManagerRegistry;
3738
import com.facebook.react.views.text.ReactFontManager;
3839
import com.facebook.soloader.SoLoader;
3940
import java.lang.reflect.InvocationTargetException;
@@ -168,6 +169,13 @@ public JSIModuleType getJSIModuleType() {
168169
public JSIModuleProvider<UIManager> getJSIModuleProvider() {
169170
final ComponentFactory ComponentFactory = new ComponentFactory();
170171
CoreComponentsRegistry.register(ComponentFactory);
172+
final ReactInstanceManager reactInstanceManager = getReactInstanceManager();
173+
174+
ViewManagerRegistry viewManagerRegistry =
175+
new ViewManagerRegistry(
176+
reactInstanceManager.getOrCreateViewManagers(
177+
reactApplicationContext));
178+
171179
return new FabricJSIModuleProvider(
172180
reactApplicationContext,
173181
ComponentFactory,
@@ -192,7 +200,8 @@ public String getString(final String s) {
192200
public double getDouble(final String s) {
193201
return 0;
194202
}
195-
});
203+
},
204+
viewManagerRegistry);
196205
}
197206
});
198207
}

0 commit comments

Comments
 (0)