mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 21:33: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 { | dependencies { | ||||||
|     implementation 'com.facebook.react:react-native:+' |     implementation 'com.facebook.react:react-native:+' | ||||||
|     implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0' |     implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0' | ||||||
|  |     implementation 'com.jakewharton:process-phoenix:3.0.0' | ||||||
| } | } | ||||||
| if (isNewArchitectureEnabled()) { | if (isNewArchitectureEnabled()) { | ||||||
|     react { |     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) { |     public static void reloadUpdate(UpdateContext updateContext, ReactApplicationContext mContext, ReadableMap options,Promise promise) { | ||||||
|         final String hash = options.getString("hash"); |         final String hash = options.getString("hash"); | ||||||
|  |  | ||||||
| @@ -136,20 +150,13 @@ public class UpdateModuleImpl { | |||||||
|                         jsBundleField.set(instanceManager, UpdateContext.getBundleUrl(application)); |                         jsBundleField.set(instanceManager, UpdateContext.getBundleUrl(application)); | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
|                     try { |  | ||||||
|                     instanceManager.recreateReactContextInBackground(); |                     instanceManager.recreateReactContextInBackground(); | ||||||
|                     promise.resolve(true); |                     promise.resolve(true); | ||||||
|                     } catch (Throwable err) { |  | ||||||
|                         promise.reject("pushy:"+err.getMessage()); |  | ||||||
|                         final Activity activity = mContext.getCurrentActivity(); |  | ||||||
|                         if (activity != null) { |  | ||||||
|                             activity.recreate(); |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|  |  | ||||||
|                 } catch (Throwable err) { |                 } catch (Throwable err) { | ||||||
|                     promise.reject("pushy:switchVersion failed"+err.getMessage()); |                     promise.reject(err); | ||||||
|                     Log.e("pushy", "switchVersion failed", 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.ReactApplication; | ||||||
| import com.facebook.react.ReactInstanceManager; | import com.facebook.react.ReactInstanceManager; | ||||||
|  | import com.facebook.react.bridge.LifecycleEventListener; | ||||||
| import com.facebook.react.bridge.Promise; | import com.facebook.react.bridge.Promise; | ||||||
| import com.facebook.react.bridge.ReactApplicationContext; | import com.facebook.react.bridge.ReactApplicationContext; | ||||||
| import com.facebook.react.bridge.ReactContext; | 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.JSBundleLoader; | ||||||
| import com.facebook.react.bridge.WritableMap; | import com.facebook.react.bridge.WritableMap; | ||||||
| import com.facebook.react.modules.core.DeviceEventManagerModule; | import com.facebook.react.modules.core.DeviceEventManagerModule; | ||||||
|  | import com.jakewharton.processphoenix.ProcessPhoenix; | ||||||
|  |  | ||||||
| import java.io.File; | import java.io.File; | ||||||
| import java.lang.reflect.Field; | import java.lang.reflect.Field; | ||||||
| @@ -30,6 +32,7 @@ import static androidx.core.content.FileProvider.getUriForFile; | |||||||
| public class UpdateModule extends ReactContextBaseJavaModule { | public class UpdateModule extends ReactContextBaseJavaModule { | ||||||
|     UpdateContext updateContext; |     UpdateContext updateContext; | ||||||
|     public static ReactApplicationContext mContext; |     public static ReactApplicationContext mContext; | ||||||
|  |     private LifecycleEventListener mLifecycleEventListener = null; | ||||||
|  |  | ||||||
|     public UpdateModule(ReactApplicationContext reactContext, UpdateContext updateContext) { |     public UpdateModule(ReactApplicationContext reactContext, UpdateContext updateContext) { | ||||||
|         super(reactContext); |         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 |     @ReactMethod | ||||||
|     public void reloadUpdate(ReadableMap options, final Promise promise) { |     public void reloadUpdate(ReadableMap options, final Promise promise) { | ||||||
|         final String hash = options.getString("hash"); |         final String hash = options.getString("hash"); | ||||||
| @@ -195,20 +212,13 @@ public class UpdateModule extends ReactContextBaseJavaModule { | |||||||
|                         jsBundleField.set(instanceManager, UpdateContext.getBundleUrl(application)); |                         jsBundleField.set(instanceManager, UpdateContext.getBundleUrl(application)); | ||||||
|                     } |                     } | ||||||
|                      |                      | ||||||
|                     try { |  | ||||||
|                     instanceManager.recreateReactContextInBackground(); |                     instanceManager.recreateReactContextInBackground(); | ||||||
|                         promise.resolve(null); |                     promise.resolve(true); | ||||||
|                     } catch (Throwable err) { |  | ||||||
|                         final Activity activity = getCurrentActivity(); |  | ||||||
|                         if (activity != null) { |  | ||||||
|                             activity.recreate(); |  | ||||||
|                         } |  | ||||||
|                         promise.reject(err); |  | ||||||
|                     } |  | ||||||
|  |  | ||||||
|                 } catch (Throwable err) { |                 } catch (Throwable err) { | ||||||
|                     promise.reject(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