Skip to content

Commit

Permalink
Expose lazyViewManagers option on ReactNativeHost
Browse files Browse the repository at this point in the history
Summary: Changelog: [Android][Added] Option to enable lazyViewManager support with `ViewManagerOnDemandReactPackage`

Reviewed By: RSNara

Differential Revision: D36130066

fbshipit-source-id: b8b04b46f59248baacdf1717f7e32b45e56dd2b8
  • Loading branch information
javache authored and facebook-github-bot committed May 12, 2022
1 parent d493f45 commit d4b59cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ public final List<NativeModule> createNativeModules(ReactApplicationContext reac
List<NativeModule> modules = new ArrayList<>();
for (ModuleSpec holder : getNativeModules(reactContext)) {
NativeModule nativeModule;
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createNativeModule")
.arg("module", holder.getType())
.flush();
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createNativeModule").flush();
ReactMarker.logMarker(ReactMarkerConstants.CREATE_MODULE_START, holder.getName());
try {
nativeModule = holder.getProvider().get();
Expand Down
11 changes: 11 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/react/ReactNativeHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected ReactInstanceManager createReactInstanceManager() {
.setDevSupportManagerFactory(getDevSupportManagerFactory())
.setRequireActivity(getShouldRequireActivity())
.setSurfaceDelegateFactory(getSurfaceDelegateFactory())
.setLazyViewManagersEnabled(getLazyViewManagersEnabled())
.setRedBoxHandler(getRedBoxHandler())
.setJavaScriptExecutorFactory(getJavaScriptExecutorFactory())
.setUIImplementationProvider(getUIImplementationProvider())
Expand Down Expand Up @@ -135,6 +136,16 @@ public boolean getShouldRequireActivity() {
return true;
}

/**
* Returns whether view managers should be created lazily. See {@link
* ViewManagerOnDemandReactPackage} for details.
*
* @experimental
*/
public boolean getLazyViewManagersEnabled() {
return false;
}

/**
* Return the {@link SurfaceDelegateFactory} used by NativeModules to get access to a {@link
* SurfaceDelegate} to interact with a surface. By default in the mobile platform the {@link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
public class ModuleSpec {

private static final String TAG = "ModuleSpec";
private final @Nullable Class<? extends NativeModule> mType;
private final Provider<? extends NativeModule> mProvider;
private final String mName;
private final @Nullable String mName;

public static ModuleSpec viewManagerSpec(Provider<? extends NativeModule> provider) {
return new ModuleSpec(provider);
Expand Down Expand Up @@ -54,22 +53,16 @@ public static ModuleSpec nativeModuleSpec(
* @param provider
*/
private ModuleSpec(Provider<? extends NativeModule> provider) {
mType = null;
mProvider = provider;
mName = null;
}

private ModuleSpec(Provider<? extends NativeModule> provider, String name) {
mType = null;
mProvider = provider;
mName = name;
}

public @Nullable Class<? extends NativeModule> getType() {
return mType;
}

public String getName() {
public @Nullable String getName() {
return mName;
}

Expand Down

0 comments on commit d4b59cd

Please sign in to comment.