Add dev bundle download listener on Android

Summary:
This exposes a way to listen to JS bundle download events when creating a ReactInstanceManager. This can be used to display a custom native UI while the JS bundle is loading. It is a pretty specific use case but Expo will need this to display loading progress on the app loading splash screen.

**Test plan**
Tested by adding a listener to the ReactInstanceManager in the Expo app and checked that it gets called when the bundle is loading.
Closes https://github.com/facebook/react-native/pull/12984

Reviewed By: devknoll

Differential Revision: D4797638

Pulled By: hramos

fbshipit-source-id: 04d7cd4071535670c1bcb121566748e495197c80
This commit is contained in:
Janic Duplessis
2017-06-28 19:49:14 -07:00
committed by Facebook Github Bot
parent c848c3820b
commit 960e5db0ed
7 changed files with 53 additions and 9 deletions

View File

@@ -15,6 +15,7 @@ import com.facebook.react.bridge.NativeModuleCallExceptionHandler;
import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener;
import com.facebook.react.bridge.JSBundleLoader;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.devsupport.RedBoxHandler;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
@@ -42,6 +43,7 @@ public class ReactInstanceManagerBuilder {
protected @Nullable RedBoxHandler mRedBoxHandler;
protected boolean mLazyNativeModulesEnabled;
protected boolean mLazyViewManagersEnabled;
protected @Nullable DevBundleDownloadListener mDevBundleDownloadListener;
protected boolean mSetupReactContextInBackground;
protected boolean mUseSeparateUIBackgroundThread;
protected int mMinNumShakes = 1;
@@ -189,6 +191,11 @@ public class ReactInstanceManagerBuilder {
return this;
}
public ReactInstanceManagerBuilder setDevBundleDownloadListener(@Nullable DevBundleDownloadListener listener) {
mDevBundleDownloadListener = listener;
return this;
}
public ReactInstanceManagerBuilder setSetupReactContextInBackgroundEnabled(
boolean setupReactContextInBackground) {
mSetupReactContextInBackground = setupReactContextInBackground;
@@ -252,6 +259,7 @@ public class ReactInstanceManagerBuilder {
mRedBoxHandler,
mLazyNativeModulesEnabled,
mLazyViewManagersEnabled,
mDevBundleDownloadListener,
mSetupReactContextInBackground,
mUseSeparateUIBackgroundThread,
mMinNumShakes);