Skip to content

Commit

Permalink
add a way to enable / disable lazy native modules
Browse files Browse the repository at this point in the history
Reviewed By: lexs

Differential Revision: D3849947

fbshipit-source-id: 0a4a1cd5b9f165269a53b69de46c9cc1939d9d08
  • Loading branch information
aaronechiu authored and Facebook Github Bot 6 committed Sep 13, 2016
1 parent 82c8c97 commit a4916b8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public static class Builder {
protected @Nullable Activity mCurrentActivity;
protected @Nullable DefaultHardwareBackBtnHandler mDefaultHardwareBackBtnHandler;
protected @Nullable RedBoxHandler mRedBoxHandler;
protected boolean mLazyNativeModulesEnabled;

protected Builder() {
}
Expand Down Expand Up @@ -366,6 +367,11 @@ public Builder setRedBoxHandler(@Nullable RedBoxHandler redBoxHandler) {
return this;
}

public Builder setLazyNativeModulesEnabled(boolean lazyNativeModulesEnabled) {
mLazyNativeModulesEnabled = lazyNativeModulesEnabled;
return this;
}

/**
* Instantiates a new {@link ReactInstanceManagerImpl}.
* Before calling {@code build}, the following must be called:
Expand All @@ -378,37 +384,38 @@ public Builder setRedBoxHandler(@Nullable RedBoxHandler redBoxHandler) {
*/
public ReactInstanceManager build() {
Assertions.assertNotNull(
mApplication,
"Application property has not been set with this builder");
mApplication,
"Application property has not been set with this builder");

Assertions.assertCondition(
mUseDeveloperSupport || mJSBundleAssetUrl != null || mJSBundleLoader != null,
"JS Bundle File or Asset URL has to be provided when dev support is disabled");
mUseDeveloperSupport || mJSBundleAssetUrl != null || mJSBundleLoader != null,
"JS Bundle File or Asset URL has to be provided when dev support is disabled");

Assertions.assertCondition(
mJSMainModuleName != null || mJSBundleAssetUrl != null || mJSBundleLoader != null,
"Either MainModuleName or JS Bundle File needs to be provided");
mJSMainModuleName != null || mJSBundleAssetUrl != null || mJSBundleLoader != null,
"Either MainModuleName or JS Bundle File needs to be provided");

if (mUIImplementationProvider == null) {
// create default UIImplementationProvider if the provided one is null.
mUIImplementationProvider = new UIImplementationProvider();
}

return new XReactInstanceManagerImpl(
mApplication,
mCurrentActivity,
mDefaultHardwareBackBtnHandler,
(mJSBundleLoader == null && mJSBundleAssetUrl != null) ?
JSBundleLoader.createAssetLoader(mApplication, mJSBundleAssetUrl) : mJSBundleLoader,
mJSMainModuleName,
mPackages,
mUseDeveloperSupport,
mBridgeIdleDebugListener,
Assertions.assertNotNull(mInitialLifecycleState, "Initial lifecycle state was not set"),
mUIImplementationProvider,
mNativeModuleCallExceptionHandler,
mJSCConfig,
mRedBoxHandler);
mApplication,
mCurrentActivity,
mDefaultHardwareBackBtnHandler,
(mJSBundleLoader == null && mJSBundleAssetUrl != null) ?
JSBundleLoader.createAssetLoader(mApplication, mJSBundleAssetUrl) : mJSBundleLoader,
mJSMainModuleName,
mPackages,
mUseDeveloperSupport,
mBridgeIdleDebugListener,
Assertions.assertNotNull(mInitialLifecycleState, "Initial lifecycle state was not set"),
mUIImplementationProvider,
mNativeModuleCallExceptionHandler,
mJSCConfig,
mRedBoxHandler,
mLazyNativeModulesEnabled);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
private final MemoryPressureRouter mMemoryPressureRouter;
private final @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
private final JSCConfig mJSCConfig;
private final boolean mLazyNativeModulesEnabled;

private final ReactInstanceDevCommandsHandler mDevInterface =
new ReactInstanceDevCommandsHandler() {
Expand Down Expand Up @@ -289,7 +290,8 @@ public T get() throws Exception {
UIImplementationProvider uiImplementationProvider,
NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler,
JSCConfig jscConfig,
@Nullable RedBoxHandler redBoxHandler) {
@Nullable RedBoxHandler redBoxHandler,
boolean lazyNativeModulesEnabled) {

initializeSoLoaderIfNecessary(applicationContext);

Expand All @@ -316,6 +318,7 @@ public T get() throws Exception {
mMemoryPressureRouter = new MemoryPressureRouter(applicationContext);
mNativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler;
mJSCConfig = jscConfig;
mLazyNativeModulesEnabled = lazyNativeModulesEnabled;
}

@Override
Expand Down

0 comments on commit a4916b8

Please sign in to comment.