mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-16 11:50:32 +08:00
Prevent removing ReactNativeDevBundle in LiveReload (#1332)
This commit is contained in:
committed by
GitHub
parent
19b1a5ede7
commit
09883dd6f1
@@ -11,6 +11,8 @@ import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.bridge.JavaScriptModule;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.devsupport.DevInternalSettings;
|
||||
import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
|
||||
import org.json.JSONException;
|
||||
@@ -76,7 +78,7 @@ public class CodePush implements ReactPackage {
|
||||
|
||||
mCurrentInstance = this;
|
||||
|
||||
clearDebugCacheIfNeeded();
|
||||
clearDebugCacheIfNeeded(null);
|
||||
initializeUpdateAfterRestart();
|
||||
}
|
||||
|
||||
@@ -119,8 +121,20 @@ public class CodePush implements ReactPackage {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
public void clearDebugCacheIfNeeded() {
|
||||
if (mIsDebugMode && mSettingsManager.isPendingUpdate(null)) {
|
||||
public void clearDebugCacheIfNeeded(ReactInstanceManager instanceManager) {
|
||||
boolean isLiveReloadEnabled = false;
|
||||
|
||||
// Use instanceManager for checking if we use LiveRelaod mode. In this case we should not remove ReactNativeDevBundle.js file
|
||||
// because we get error with trying to get this after reloading. Issue: https://github.com/Microsoft/react-native-code-push/issues/1272
|
||||
if (instanceManager != null) {
|
||||
DevSupportManager devSupportManager = instanceManager.getDevSupportManager();
|
||||
if (devSupportManager != null) {
|
||||
DevInternalSettings devInternalSettings = (DevInternalSettings)devSupportManager.getDevSettings();
|
||||
isLiveReloadEnabled = devInternalSettings.isReloadOnJSChangeEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
if (mIsDebugMode && mSettingsManager.isPendingUpdate(null) && !isLiveReloadEnabled) {
|
||||
// This needs to be kept in sync with https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java#L78
|
||||
File cachedDevBundle = new File(mContext.getFilesDir(), "ReactNativeDevBundle.js");
|
||||
if (cachedDevBundle.exists()) {
|
||||
|
||||
@@ -118,7 +118,13 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule {
|
||||
|
||||
private void loadBundle() {
|
||||
clearLifecycleEventListener();
|
||||
mCodePush.clearDebugCacheIfNeeded();
|
||||
try {
|
||||
mCodePush.clearDebugCacheIfNeeded(resolveInstanceManager());
|
||||
} catch(Exception e) {
|
||||
// If we got error in out reflection we should clear debug cache anyway.
|
||||
mCodePush.clearDebugCacheIfNeeded(null);
|
||||
}
|
||||
|
||||
try {
|
||||
// #1) Get the ReactInstanceManager instance, which is what includes the
|
||||
// logic to reload the current React context.
|
||||
|
||||
Reference in New Issue
Block a user