diff --git a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/JSBundleLoader.java b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/JSBundleLoader.java index 311b4fa41..1f064212a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/JSBundleLoader.java +++ b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/JSBundleLoader.java @@ -104,6 +104,7 @@ public abstract class JSBundleLoader { .setDestinationPath(new File(context.getFilesDir(), "optimized-bundle")) .checkAndUnpackFile(bundleName + ".meta", "bundle.meta") .unpackFile(bundleName, "bundle.js") + .setLoadFlags(UnpackingJSBundleLoader.UNPACKED_JS_SOURCE) .build(); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/UnpackingJSBundleLoader.java b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/UnpackingJSBundleLoader.java index 722b3c596..e4cf13628 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/UnpackingJSBundleLoader.java +++ b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/UnpackingJSBundleLoader.java @@ -42,7 +42,7 @@ public class UnpackingJSBundleLoader extends JSBundleLoader { * Flag passed to loadScriptFromOptimizedBundle to let the bridge know that * the unpacked unpacked js source file. */ - static final int UNPACKED_JS_SOURCE = (1 << 0); + public static final int UNPACKED_JS_SOURCE = (1 << 0); /** * Name of the lock files. Multiple processes can be spawned off the same app @@ -71,6 +71,7 @@ public class UnpackingJSBundleLoader extends JSBundleLoader { private final String mSourceURL; private final Context mContext; + private final int mLoadFlags; /** * Description of what needs to be unpacked. @@ -82,6 +83,7 @@ public class UnpackingJSBundleLoader extends JSBundleLoader { mDirectoryPath = Assertions.assertNotNull(builder.destinationPath); mSourceURL = Assertions.assertNotNull(builder.sourceURL); mUnpackers = builder.unpackers.toArray(new Unpacker[builder.unpackers.size()]); + mLoadFlags = builder.loadFlags; } /** @@ -150,7 +152,7 @@ public class UnpackingJSBundleLoader extends JSBundleLoader { instance.loadScriptFromOptimizedBundle( mDirectoryPath.getPath(), mSourceURL, - UNPACKED_JS_SOURCE); + mLoadFlags); } @Override @@ -204,12 +206,14 @@ public class UnpackingJSBundleLoader extends JSBundleLoader { private @Nullable File destinationPath; private @Nullable String sourceURL; private final ArrayList unpackers; + private int loadFlags; public Builder() { this.unpackers = new ArrayList(); context = null; destinationPath = null; sourceURL = null; + loadFlags = 0; } public Builder setContext(Context context) { @@ -227,6 +231,11 @@ public class UnpackingJSBundleLoader extends JSBundleLoader { return this; } + public Builder setLoadFlags(int loadFlags) { + this.loadFlags = loadFlags; + return this; + } + /** * Adds a file for unpacking. Content of extracted file is not checked on each * start against content of the file bundled in apk. diff --git a/ReactAndroid/src/test/java/com/facebook/react/cxxbridge/UnpackingJSBundleLoaderTest.java b/ReactAndroid/src/test/java/com/facebook/react/cxxbridge/UnpackingJSBundleLoaderTest.java index 016ecb201..371f5fd31 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/cxxbridge/UnpackingJSBundleLoaderTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/cxxbridge/UnpackingJSBundleLoaderTest.java @@ -105,10 +105,21 @@ public class UnpackingJSBundleLoaderTest { verify(mCatalystInstanceImpl).loadScriptFromOptimizedBundle( eq(mDestinationPath.getPath()), eq(URL), - eq(UnpackingJSBundleLoader.UNPACKED_JS_SOURCE)); + eq(0)); verifyNoMoreInteractions(mCatalystInstanceImpl); } + @Test + public void testSetLoadFlags() throws IOException { + mBuilder.setLoadFlags(UnpackingJSBundleLoader.UNPACKED_JS_SOURCE) + .build() + .loadScript(mCatalystInstanceImpl); + verify(mCatalystInstanceImpl).loadScriptFromOptimizedBundle( + eq(mDestinationPath.getPath()), + eq(URL), + eq(UnpackingJSBundleLoader.UNPACKED_JS_SOURCE)); + } + @Test public void testLoadScriptUnpacks() { mBuilder.build().loadScript(mCatalystInstanceImpl);