Skip to content

Commit

Permalink
Refactor initialization of Fabric to avoid loading UIManagerModule
Browse files Browse the repository at this point in the history
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 (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 (2e63147).

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D25746024

fbshipit-source-id: 3d12d29973a12b1edfea75f4dd954790f835e9bd
  • Loading branch information
mdvacca authored and facebook-github-bot committed Jan 6, 2021
1 parent 2e63147 commit d3a3ce8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,24 +25,28 @@
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> {

@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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -168,6 +169,13 @@ public JSIModuleType getJSIModuleType() {
public JSIModuleProvider<UIManager> 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,
Expand All @@ -192,7 +200,8 @@ public String getString(final String s) {
public double getDouble(final String s) {
return 0;
}
});
},
viewManagerRegistry);
}
});
}
Expand Down

0 comments on commit d3a3ce8

Please sign in to comment.