mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 13:23:12 +08:00 
			
		
		
		
	fix android reload
This commit is contained in:
		
							
								
								
									
										1935
									
								
								Example/testHotUpdate/bun.lock
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										1935
									
								
								Example/testHotUpdate/bun.lock
									
									
									
									
									
										Executable file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -82,6 +82,7 @@ repositories { | ||||
| dependencies { | ||||
|     implementation 'com.facebook.react:react-native:+' | ||||
|     implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0' | ||||
|     implementation 'com.jakewharton:process-phoenix:3.0.0' | ||||
| } | ||||
| if (isNewArchitectureEnabled()) { | ||||
|     react { | ||||
|   | ||||
| @@ -105,6 +105,20 @@ public class UpdateModuleImpl { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void loadBundleLegacy() { | ||||
|         final Activity currentActivity = getCurrentActivity(); | ||||
|         if (currentActivity == null) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         currentActivity.runOnUiThread(new Runnable() { | ||||
|             @Override | ||||
|             public void run() { | ||||
|                 currentActivity.recreate(); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     public static void reloadUpdate(UpdateContext updateContext, ReactApplicationContext mContext, ReadableMap options,Promise promise) { | ||||
|         final String hash = options.getString("hash"); | ||||
|  | ||||
| @@ -136,20 +150,13 @@ public class UpdateModuleImpl { | ||||
|                         jsBundleField.set(instanceManager, UpdateContext.getBundleUrl(application)); | ||||
|                     } | ||||
|  | ||||
|                     try { | ||||
|                         instanceManager.recreateReactContextInBackground(); | ||||
|                         promise.resolve(true); | ||||
|                     } catch (Throwable err) { | ||||
|                         promise.reject("pushy:"+err.getMessage()); | ||||
|                         final Activity activity = mContext.getCurrentActivity(); | ||||
|                         if (activity != null) { | ||||
|                             activity.recreate(); | ||||
|                         } | ||||
|                     } | ||||
|                     instanceManager.recreateReactContextInBackground(); | ||||
|                     promise.resolve(true); | ||||
|  | ||||
|                 } catch (Throwable err) { | ||||
|                     promise.reject("pushy:switchVersion failed"+err.getMessage()); | ||||
|                     Log.e("pushy", "switchVersion failed", err); | ||||
|                     promise.reject(err); | ||||
|                     Log.e("pushy", "switchVersion failed ", err); | ||||
|                     loadBundleLegacy(); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|   | ||||
| @@ -9,6 +9,7 @@ import android.util.Log; | ||||
|  | ||||
| import com.facebook.react.ReactApplication; | ||||
| import com.facebook.react.ReactInstanceManager; | ||||
| import com.facebook.react.bridge.LifecycleEventListener; | ||||
| import com.facebook.react.bridge.Promise; | ||||
| import com.facebook.react.bridge.ReactApplicationContext; | ||||
| import com.facebook.react.bridge.ReactContext; | ||||
| @@ -19,6 +20,7 @@ import com.facebook.react.bridge.UiThreadUtil; | ||||
| import com.facebook.react.bridge.JSBundleLoader; | ||||
| import com.facebook.react.bridge.WritableMap; | ||||
| import com.facebook.react.modules.core.DeviceEventManagerModule; | ||||
| import com.jakewharton.processphoenix.ProcessPhoenix; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.lang.reflect.Field; | ||||
| @@ -30,6 +32,7 @@ import static androidx.core.content.FileProvider.getUriForFile; | ||||
| public class UpdateModule extends ReactContextBaseJavaModule { | ||||
|     UpdateContext updateContext; | ||||
|     public static ReactApplicationContext mContext; | ||||
|     private LifecycleEventListener mLifecycleEventListener = null; | ||||
|  | ||||
|     public UpdateModule(ReactApplicationContext reactContext, UpdateContext updateContext) { | ||||
|         super(reactContext); | ||||
| @@ -167,6 +170,20 @@ public class UpdateModule extends ReactContextBaseJavaModule { | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     private void loadBundleLegacy() { | ||||
|         final Activity currentActivity = getCurrentActivity(); | ||||
|         if (currentActivity == null) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         currentActivity.runOnUiThread(new Runnable() { | ||||
|             @Override | ||||
|             public void run() { | ||||
|                 currentActivity.recreate(); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @ReactMethod | ||||
|     public void reloadUpdate(ReadableMap options, final Promise promise) { | ||||
|         final String hash = options.getString("hash"); | ||||
| @@ -194,21 +211,14 @@ public class UpdateModule extends ReactContextBaseJavaModule { | ||||
|                         jsBundleField.setAccessible(true); | ||||
|                         jsBundleField.set(instanceManager, UpdateContext.getBundleUrl(application)); | ||||
|                     } | ||||
|  | ||||
|                     try { | ||||
|                         instanceManager.recreateReactContextInBackground(); | ||||
|                         promise.resolve(null); | ||||
|                     } catch (Throwable err) { | ||||
|                         final Activity activity = getCurrentActivity(); | ||||
|                         if (activity != null) { | ||||
|                             activity.recreate(); | ||||
|                         } | ||||
|                         promise.reject(err); | ||||
|                     } | ||||
|                      | ||||
|                     instanceManager.recreateReactContextInBackground(); | ||||
|                     promise.resolve(true); | ||||
|  | ||||
|                 } catch (Throwable err) { | ||||
|                     promise.reject(err); | ||||
|                     Log.e("pushy", "switchVersion failed", err); | ||||
|                     Log.e("pushy", "switchVersion failed ", err); | ||||
|                     loadBundleLegacy(); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 sunny.luo
					sunny.luo