Skip to content

Commit ab7d932

Browse files
author
sunny.luo
committed
fix android reload
1 parent 822602a commit ab7d932

File tree

9 files changed

+4973
-17342
lines changed

9 files changed

+4973
-17342
lines changed

Example/testHotUpdate/bun.lock

Lines changed: 1935 additions & 0 deletions
Large diffs are not rendered by default.

Example/testHotUpdate/bun.lockb

-373 KB
Binary file not shown.

Example/testHotUpdate/yarn.lock

Lines changed: 0 additions & 7142 deletions
This file was deleted.

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ repositories {
8282
dependencies {
8383
implementation 'com.facebook.react:react-native:+'
8484
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
85+
implementation 'com.jakewharton:process-phoenix:3.0.0'
8586
}
8687
if (isNewArchitectureEnabled()) {
8788
react {

android/src/main/java/cn/reactnative/modules/update/UpdateModuleImpl.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ public void onDownloadFailed(Throwable error) {
105105
}
106106
}
107107

108+
private void loadBundleLegacy() {
109+
final Activity currentActivity = getCurrentActivity();
110+
if (currentActivity == null) {
111+
return;
112+
}
113+
114+
currentActivity.runOnUiThread(new Runnable() {
115+
@Override
116+
public void run() {
117+
currentActivity.recreate();
118+
}
119+
});
120+
}
121+
108122
public static void reloadUpdate(UpdateContext updateContext, ReactApplicationContext mContext, ReadableMap options,Promise promise) {
109123
final String hash = options.getString("hash");
110124

@@ -136,20 +150,13 @@ public void run() {
136150
jsBundleField.set(instanceManager, UpdateContext.getBundleUrl(application));
137151
}
138152

139-
try {
140-
instanceManager.recreateReactContextInBackground();
141-
promise.resolve(true);
142-
} catch (Throwable err) {
143-
promise.reject("pushy:"+err.getMessage());
144-
final Activity activity = mContext.getCurrentActivity();
145-
if (activity != null) {
146-
activity.recreate();
147-
}
148-
}
153+
instanceManager.recreateReactContextInBackground();
154+
promise.resolve(true);
149155

150156
} catch (Throwable err) {
151-
promise.reject("pushy:switchVersion failed"+err.getMessage());
152-
Log.e("pushy", "switchVersion failed", err);
157+
promise.reject(err);
158+
Log.e("pushy", "switchVersion failed ", err);
159+
loadBundleLegacy();
153160
}
154161
}
155162
});

android/src/oldarch/cn/reactnative/modules/update/UpdateModule.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import com.facebook.react.ReactApplication;
1111
import com.facebook.react.ReactInstanceManager;
12+
import com.facebook.react.bridge.LifecycleEventListener;
1213
import com.facebook.react.bridge.Promise;
1314
import com.facebook.react.bridge.ReactApplicationContext;
1415
import com.facebook.react.bridge.ReactContext;
@@ -19,6 +20,7 @@
1920
import com.facebook.react.bridge.JSBundleLoader;
2021
import com.facebook.react.bridge.WritableMap;
2122
import com.facebook.react.modules.core.DeviceEventManagerModule;
23+
import com.jakewharton.processphoenix.ProcessPhoenix;
2224

2325
import java.io.File;
2426
import java.lang.reflect.Field;
@@ -30,6 +32,7 @@
3032
public class UpdateModule extends ReactContextBaseJavaModule {
3133
UpdateContext updateContext;
3234
public static ReactApplicationContext mContext;
35+
private LifecycleEventListener mLifecycleEventListener = null;
3336

3437
public UpdateModule(ReactApplicationContext reactContext, UpdateContext updateContext) {
3538
super(reactContext);
@@ -167,6 +170,20 @@ public void onDownloadFailed(Throwable error) {
167170
});
168171
}
169172

173+
private void loadBundleLegacy() {
174+
final Activity currentActivity = getCurrentActivity();
175+
if (currentActivity == null) {
176+
return;
177+
}
178+
179+
currentActivity.runOnUiThread(new Runnable() {
180+
@Override
181+
public void run() {
182+
currentActivity.recreate();
183+
}
184+
});
185+
}
186+
170187
@ReactMethod
171188
public void reloadUpdate(ReadableMap options, final Promise promise) {
172189
final String hash = options.getString("hash");
@@ -194,21 +211,14 @@ public void run() {
194211
jsBundleField.setAccessible(true);
195212
jsBundleField.set(instanceManager, UpdateContext.getBundleUrl(application));
196213
}
197-
198-
try {
199-
instanceManager.recreateReactContextInBackground();
200-
promise.resolve(null);
201-
} catch (Throwable err) {
202-
final Activity activity = getCurrentActivity();
203-
if (activity != null) {
204-
activity.recreate();
205-
}
206-
promise.reject(err);
207-
}
214+
215+
instanceManager.recreateReactContextInBackground();
216+
promise.resolve(true);
208217

209218
} catch (Throwable err) {
210219
promise.reject(err);
211-
Log.e("pushy", "switchVersion failed", err);
220+
Log.e("pushy", "switchVersion failed ", err);
221+
loadBundleLegacy();
212222
}
213223
}
214224
});

0 commit comments

Comments
 (0)