Allow apps to provide JSBundleLoader of their choice

Reviewed By: tadeuzagallo

Differential Revision: D3522798

fbshipit-source-id: 90324e44a02ad78885ff3c2a33ba58d4ee6a021a
This commit is contained in:
Michał Gregorczyk
2016-07-12 08:03:04 -07:00
committed by Facebook Github Bot 2
parent 2f73ca8f76
commit e632025917
2 changed files with 37 additions and 20 deletions

View File

@@ -109,7 +109,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
private @Nullable ReactContextInitAsyncTask mReactContextInitAsyncTask;
/* accessed from any thread */
private @Nullable String mJSBundleFile; /* path to JS bundle on file system */
private final @Nullable JSBundleLoader mBundleLoader; /* path to JS bundle on file system */
private final @Nullable String mJSMainModuleName; /* path to JS bundle root on packager server */
private final List<ReactPackage> mPackages;
private final DevSupportManager mDevSupportManager;
@@ -275,7 +275,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
Context applicationContext,
@Nullable Activity currentActivity,
@Nullable DefaultHardwareBackBtnHandler defaultHardwareBackBtnHandler,
@Nullable String jsBundleFile,
@Nullable JSBundleLoader bundleLoader,
@Nullable String jsMainModuleName,
List<ReactPackage> packages,
boolean useDeveloperSupport,
@@ -295,7 +295,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
mApplicationContext = applicationContext;
mCurrentActivity = currentActivity;
mDefaultBackButtonImpl = defaultHardwareBackBtnHandler;
mJSBundleFile = jsBundleFile;
mBundleLoader = bundleLoader;
mJSMainModuleName = jsMainModuleName;
mPackages = packages;
mUseDeveloperSupport = useDeveloperSupport;
@@ -382,7 +382,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
// If there is a up-to-date bundle downloaded from server,
// with remote JS debugging disabled, always use that.
onJSBundleLoadedFromServer();
} else if (mJSBundleFile == null) {
} else if (mBundleLoader == null) {
mDevSupportManager.handleReloadJS();
} else {
mDevSupportManager.isPackagerRunning(
@@ -398,7 +398,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
} else {
// If dev server is down, disable the remote JS debugging.
devSettings.setRemoteJSDebugEnabled(false);
recreateReactContextInBackgroundFromBundleFile();
recreateReactContextInBackgroundFromBundleLoader();
}
}
});
@@ -408,16 +408,13 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
return;
}
recreateReactContextInBackgroundFromBundleFile();
recreateReactContextInBackgroundFromBundleLoader();
}
private void recreateReactContextInBackgroundFromBundleFile() {
boolean useLazyBundle = mJSCConfig.getConfigMap().hasKey("useLazyBundle") ?
mJSCConfig.getConfigMap().getBoolean("useLazyBundle") : false;
private void recreateReactContextInBackgroundFromBundleLoader() {
recreateReactContextInBackground(
new JSCJavaScriptExecutor.Factory(mJSCConfig.getConfigMap()),
JSBundleLoader.createFileLoader(mApplicationContext, mJSBundleFile, useLazyBundle));
mBundleLoader);
}
/**