Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.facebook.react.bridge.JSBundleLoaderDelegate;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.NativeArray;
import com.facebook.react.bridge.NativeMap;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactNoCrashSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
Expand Down Expand Up @@ -187,23 +186,6 @@ public void onHostDestroy() {
isProfiling,
useModernRuntimeScheduler);

RuntimeExecutor unbufferedRuntimeExecutor = getUnbufferedRuntimeExecutor();

// Initialize function for JS's UIManager.hasViewManagerConfig()
mComponentNameResolverManager =
new ComponentNameResolverManager(
// Use unbuffered RuntimeExecutor to install binding
unbufferedRuntimeExecutor,
(ComponentNameResolver)
() -> {
Collection<String> viewManagerNames = getViewManagerNames();
if (viewManagerNames.size() < 1) {
FLog.e(TAG, "No ViewManager names found");
return new String[0];
}
return viewManagerNames.toArray(new String[0]);
});

// Set up TurboModules
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ReactInstance.initialize#initTurboModules");
Expand All @@ -222,6 +204,7 @@ public void onHostDestroy() {
.setReactApplicationContext(mBridgelessReactContext)
.build();

RuntimeExecutor unbufferedRuntimeExecutor = getUnbufferedRuntimeExecutor();
mTurboModuleManager =
new TurboModuleManager(
// Use unbuffered RuntimeExecutor to install binding
Expand All @@ -237,6 +220,25 @@ public void onHostDestroy() {

Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);

// Set up Fabric
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ReactInstance.initialize#initFabric");

// Initialize function for JS's UIManager.hasViewManagerConfig()
mComponentNameResolverManager =
new ComponentNameResolverManager(
// Use unbuffered RuntimeExecutor to install binding
unbufferedRuntimeExecutor,
(ComponentNameResolver)
() -> {
Collection<String> viewManagerNames = getViewManagerNames();
if (viewManagerNames.size() < 1) {
FLog.e(TAG, "No ViewManager names found");
return new String[0];
}
return viewManagerNames.toArray(new String[0]);
});

// Initialize function for JS's UIManager.getViewManagerConfig()
// It should come after getTurboModuleManagerDelegate as it relies on react packages being
// initialized.
Expand All @@ -254,14 +256,38 @@ public void onHostDestroy() {
// We want to match this beahavior.
(UIConstantsProvider)
() -> {
return getUIManagerConstants();
List<ViewManager> viewManagers = new ArrayList<ViewManager>();
boolean canLoadViewManagersLazily = true;

List<ReactPackage> packages = mReactPackages;
for (ReactPackage reactPackage : packages) {
if (!(reactPackage instanceof ViewManagerOnDemandReactPackage)) {
canLoadViewManagersLazily = false;
break;
}
}
// 1, Retrive view managers via on demand loading
if (canLoadViewManagersLazily) {
for (String viewManagerName : getViewManagerNames()) {
viewManagers.add(createViewManager(viewManagerName));
}
} else {
// 2, There are packages that don't implement ViewManagerOnDemandReactPackage
// so we retrieve
// view managers via eager loading
for (ReactPackage reactPackage : packages) {
List<ViewManager> viewManagersInPackage =
reactPackage.createViewManagers(mBridgelessReactContext);
viewManagers.addAll(viewManagersInPackage);
}
}
Map<String, Object> constants =
UIManagerModule.createConstants(
viewManagers, new HashMap<>(), new HashMap<>());
return Arguments.makeNativeMap(constants);
});
}

// Set up Fabric
Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ReactInstance.initialize#initFabric");

ViewManagerRegistry viewManagerRegistry =
new ViewManagerRegistry(
new ViewManagerResolver() {
Expand Down Expand Up @@ -555,34 +581,4 @@ public void registerSegment(int segmentId, String path) {
}
return uniqueNames;
}

private @NonNull NativeMap getUIManagerConstants() {
List<ViewManager> viewManagers = new ArrayList<ViewManager>();
boolean canLoadViewManagersLazily = true;

List<ReactPackage> packages = mReactPackages;
for (ReactPackage reactPackage : packages) {
if (!(reactPackage instanceof ViewManagerOnDemandReactPackage)) {
canLoadViewManagersLazily = false;
break;
}
}
// 1, Retrive view managers via on demand loading
if (canLoadViewManagersLazily) {
for (String viewManagerName : getViewManagerNames()) {
viewManagers.add(createViewManager(viewManagerName));
}
} else {
// 2, There are packages that don't implement ViewManagerOnDemandReactPackage so we retrieve
// view managers via eager loading
for (ReactPackage reactPackage : packages) {
List<ViewManager> viewManagersInPackage =
reactPackage.createViewManagers(mBridgelessReactContext);
viewManagers.addAll(viewManagersInPackage);
}
}
Map<String, Object> constants =
UIManagerModule.createConstants(viewManagers, new HashMap<>(), new HashMap<>());
return Arguments.makeNativeMap(constants);
}
}