Allow apps to provide JSBundleLoader of their choice
Reviewed By: tadeuzagallo Differential Revision: D3522798 fbshipit-source-id: 90324e44a02ad78885ff3c2a33ba58d4ee6a021a
This commit is contained in:
parent
2f73ca8f76
commit
e632025917
|
@ -23,6 +23,7 @@ import com.facebook.react.bridge.NativeModuleCallExceptionHandler;
|
|||
import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.cxxbridge.JSBundleLoader;
|
||||
import com.facebook.react.common.annotations.VisibleForTesting;
|
||||
import com.facebook.react.devsupport.DevSupportManager;
|
||||
import com.facebook.react.devsupport.RedBoxHandler;
|
||||
|
@ -184,6 +185,7 @@ public abstract class ReactInstanceManager {
|
|||
protected final List<ReactPackage> mPackages = new ArrayList<>();
|
||||
|
||||
protected @Nullable String mJSBundleFile;
|
||||
protected @Nullable JSBundleLoader mJSBundleLoader;
|
||||
protected @Nullable String mJSMainModuleName;
|
||||
protected @Nullable NotThreadSafeBridgeIdleDebugListener mBridgeIdleDebugListener;
|
||||
protected @Nullable Application mApplication;
|
||||
|
@ -225,6 +227,19 @@ public abstract class ReactInstanceManager {
|
|||
*/
|
||||
public Builder setJSBundleFile(String jsBundleFile) {
|
||||
mJSBundleFile = jsBundleFile;
|
||||
mJSBundleLoader = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bundle loader to use when setting up JS environment. This supersedes
|
||||
* prior invcations of {@link setJSBundleFile} and {@link setBundleAssetName}.
|
||||
*
|
||||
* Example: {@code JSBundleLoader.createFileLoader(application, bundleFile)}
|
||||
*/
|
||||
public Builder setJSBundleLoader(JSBundleLoader jsBundleLoader) {
|
||||
mJSBundleLoader = jsBundleLoader;
|
||||
mJSBundleFile = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -326,12 +341,20 @@ public abstract class ReactInstanceManager {
|
|||
* </ul>
|
||||
*/
|
||||
public ReactInstanceManager build() {
|
||||
Assertions.assertNotNull(
|
||||
mApplication,
|
||||
"Application property has not been set with this builder");
|
||||
|
||||
Assertions.assertCondition(
|
||||
mUseDeveloperSupport || mJSBundleFile != null,
|
||||
mJSBundleLoader == null || !mUseOldBridge,
|
||||
"JSBundleLoader can't be used with the old bridge");
|
||||
|
||||
Assertions.assertCondition(
|
||||
mUseDeveloperSupport || mJSBundleFile != null || mJSBundleLoader != null,
|
||||
"JS Bundle File has to be provided when dev support is disabled");
|
||||
|
||||
Assertions.assertCondition(
|
||||
mJSMainModuleName != null || mJSBundleFile != null,
|
||||
mJSMainModuleName != null || mJSBundleFile != null || mJSBundleLoader != null,
|
||||
"Either MainModuleName or JS Bundle File needs to be provided");
|
||||
|
||||
if (mUIImplementationProvider == null) {
|
||||
|
@ -341,9 +364,7 @@ public abstract class ReactInstanceManager {
|
|||
|
||||
if (mUseOldBridge) {
|
||||
return new ReactInstanceManagerImpl(
|
||||
Assertions.assertNotNull(
|
||||
mApplication,
|
||||
"Application property has not been set with this builder"),
|
||||
mApplication,
|
||||
mCurrentActivity,
|
||||
mDefaultHardwareBackBtnHandler,
|
||||
mJSBundleFile,
|
||||
|
@ -358,12 +379,11 @@ public abstract class ReactInstanceManager {
|
|||
mRedBoxHandler);
|
||||
} else {
|
||||
return new XReactInstanceManagerImpl(
|
||||
Assertions.assertNotNull(
|
||||
mApplication,
|
||||
"Application property has not been set with this builder"),
|
||||
mApplication,
|
||||
mCurrentActivity,
|
||||
mDefaultHardwareBackBtnHandler,
|
||||
mJSBundleFile,
|
||||
(mJSBundleLoader == null && mJSBundleFile != null) ?
|
||||
JSBundleLoader.createFileLoader(mApplication, mJSBundleFile) : mJSBundleLoader,
|
||||
mJSMainModuleName,
|
||||
mPackages,
|
||||
mUseDeveloperSupport,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue