Daniel Zlotin 7 years ago
parent
commit
ed3338c4b8

+ 7
- 4
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ApplicationLifecycleTest.java View File

@@ -6,7 +6,6 @@ import android.provider.Settings;
6 6
 import android.support.test.uiautomator.By;
7 7
 import android.view.KeyEvent;
8 8
 
9
-import org.junit.Ignore;
10 9
 import org.junit.Test;
11 10
 
12 11
 import static android.support.test.InstrumentationRegistry.getInstrumentation;
@@ -88,9 +87,13 @@ public class ApplicationLifecycleTest extends BaseTest {
88 87
 	}
89 88
 
90 89
 	@Test
91
-	@Ignore
92
-	public void reloadReactNativeDoesNotCausesLeaks() throws Exception {
93
-		// TODO
90
+	public void sendingReloadBroadcastReloadsReactNative() throws Exception {
91
+		elementByText("PUSH").click();
92
+		assertExists(By.text("Pushed Screen"));
93
+
94
+		device().executeShellCommand("am broadcast -a com.reactnativenavigation.broadcast.RELOAD");
95
+		device().waitForIdle();
96
+		assertMainShown();
94 97
 	}
95 98
 
96 99
 	private void killAppSaveInstanceState_ByTogglingPermissions() throws Exception {

+ 24
- 1
lib/android/app/src/main/java/com/reactnativenavigation/react/JsDevReloadHandler.java View File

@@ -1,10 +1,21 @@
1 1
 package com.reactnativenavigation.react;
2 2
 
3
+import android.app.Activity;
4
+import android.content.BroadcastReceiver;
5
+import android.content.Context;
6
+import android.content.Intent;
7
+import android.content.IntentFilter;
3 8
 import android.view.KeyEvent;
4 9
 
5 10
 import com.facebook.react.ReactInstanceManager;
6 11
 
7 12
 public class JsDevReloadHandler {
13
+	private final BroadcastReceiver reloadReceiver = new BroadcastReceiver() {
14
+		@Override
15
+		public void onReceive(final Context context, final Intent intent) {
16
+			reloadReactNative();
17
+		}
18
+	};
8 19
 	private final ReactInstanceManager reactInstanceManager;
9 20
 	private long firstRTimestamp = 0;
10 21
 
@@ -12,6 +23,14 @@ public class JsDevReloadHandler {
12 23
 		this.reactInstanceManager = reactInstanceManager;
13 24
 	}
14 25
 
26
+	public void onActivityResumed(Activity activity) {
27
+		activity.registerReceiver(reloadReceiver, new IntentFilter("com.reactnativenavigation.broadcast.RELOAD"));
28
+	}
29
+
30
+	public void onActivityPaused(Activity activity) {
31
+		activity.unregisterReceiver(reloadReceiver);
32
+	}
33
+
15 34
 	public boolean onKeyUp(int keyCode) {
16 35
 		if (!reactInstanceManager.getDevSupportManager().getDevSupportEnabled()) {
17 36
 			return false;
@@ -24,7 +43,7 @@ public class JsDevReloadHandler {
24 43
 
25 44
 		if (keyCode == KeyEvent.KEYCODE_R) {
26 45
 			if (lessThan500MillisSinceLastR()) {
27
-				reactInstanceManager.getDevSupportManager().handleReloadJS();
46
+				reloadReactNative();
28 47
 				return true;
29 48
 			}
30 49
 			firstRTimestamp = System.currentTimeMillis();
@@ -35,4 +54,8 @@ public class JsDevReloadHandler {
35 54
 	private boolean lessThan500MillisSinceLastR() {
36 55
 		return firstRTimestamp != 0 && System.currentTimeMillis() - firstRTimestamp < 1000;
37 56
 	}
57
+
58
+	private void reloadReactNative() {
59
+		reactInstanceManager.getDevSupportManager().handleReloadJS();
60
+	}
38 61
 }

+ 2
- 0
lib/android/app/src/main/java/com/reactnativenavigation/react/ReactGateway.java View File

@@ -25,10 +25,12 @@ public class ReactGateway {
25 25
 
26 26
 	public void onActivityResumed(NavigationActivity activity) {
27 27
 		initializer.onActivityResumed(activity);
28
+		jsDevReloadHandler.onActivityResumed(activity);
28 29
 	}
29 30
 
30 31
 	public void onActivityPaused(NavigationActivity activity) {
31 32
 		initializer.onActivityPaused(activity);
33
+		jsDevReloadHandler.onActivityPaused(activity);
32 34
 	}
33 35
 
34 36
 	public void onActivityDestroyed(NavigationActivity activity) {