Add separate JSBunldeLoader for assets

Reviewed By: mhorowitz

Differential Revision: D3735897

fbshipit-source-id: 990d45e9cb40a9afce1df8f8fd0b73c62e13158a
This commit is contained in:
Michał Gregorczyk
2016-09-06 19:39:27 -07:00
committed by Facebook Github Bot 8
parent 96de161304
commit 0c2fdf4b6a
3 changed files with 40 additions and 21 deletions

View File

@@ -220,7 +220,7 @@ public abstract class ReactInstanceManager {
protected final List<ReactPackage> mPackages = new ArrayList<>();
protected @Nullable String mJSBundleFile;
protected @Nullable String mJSBundleAssetUrl;
protected @Nullable JSBundleLoader mJSBundleLoader;
protected @Nullable String mJSMainModuleName;
protected @Nullable NotThreadSafeBridgeIdleDebugListener mBridgeIdleDebugListener;
@@ -252,7 +252,9 @@ public abstract class ReactInstanceManager {
* Example: {@code "index.android.js"}
*/
public Builder setBundleAssetName(String bundleAssetName) {
return this.setJSBundleFile(bundleAssetName == null ? null : "assets://" + bundleAssetName);
mJSBundleAssetUrl = (bundleAssetName == null ? null : "assets://" + bundleAssetName);
mJSBundleLoader = null;
return this;
}
/**
@@ -261,9 +263,12 @@ public abstract class ReactInstanceManager {
* Example: {@code "assets://index.android.js" or "/sdcard/main.jsbundle"}
*/
public Builder setJSBundleFile(String jsBundleFile) {
mJSBundleFile = jsBundleFile;
mJSBundleLoader = null;
return this;
if (jsBundleFile.startsWith("assets://")) {
mJSBundleAssetUrl = jsBundleFile;
mJSBundleLoader = null;
return this;
}
return setJSBundleLoader(JSBundleLoader.createFileLoader(jsBundleFile));
}
/**
@@ -274,7 +279,7 @@ public abstract class ReactInstanceManager {
*/
public Builder setJSBundleLoader(JSBundleLoader jsBundleLoader) {
mJSBundleLoader = jsBundleLoader;
mJSBundleFile = null;
mJSBundleAssetUrl = null;
return this;
}
@@ -376,11 +381,11 @@ public abstract class ReactInstanceManager {
"Application property has not been set with this builder");
Assertions.assertCondition(
mUseDeveloperSupport || mJSBundleFile != null || mJSBundleLoader != null,
"JS Bundle File 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 || mJSBundleFile != null || mJSBundleLoader != null,
mJSMainModuleName != null || mJSBundleAssetUrl != null || mJSBundleLoader != null,
"Either MainModuleName or JS Bundle File needs to be provided");
if (mUIImplementationProvider == null) {
@@ -392,8 +397,8 @@ public abstract class ReactInstanceManager {
mApplication,
mCurrentActivity,
mDefaultHardwareBackBtnHandler,
(mJSBundleLoader == null && mJSBundleFile != null) ?
JSBundleLoader.createFileLoader(mApplication, mJSBundleFile) : mJSBundleLoader,
(mJSBundleLoader == null && mJSBundleAssetUrl != null) ?
JSBundleLoader.createAssetLoader(mApplication, mJSBundleAssetUrl) : mJSBundleLoader,
mJSMainModuleName,
mPackages,
mUseDeveloperSupport,