Daniel Zlotin 7 years ago
parent
commit
ed3338c4b8

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

6
 import android.support.test.uiautomator.By;
6
 import android.support.test.uiautomator.By;
7
 import android.view.KeyEvent;
7
 import android.view.KeyEvent;
8
 
8
 
9
-import org.junit.Ignore;
10
 import org.junit.Test;
9
 import org.junit.Test;
11
 
10
 
12
 import static android.support.test.InstrumentationRegistry.getInstrumentation;
11
 import static android.support.test.InstrumentationRegistry.getInstrumentation;
88
 	}
87
 	}
89
 
88
 
90
 	@Test
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
 	private void killAppSaveInstanceState_ByTogglingPermissions() throws Exception {
99
 	private void killAppSaveInstanceState_ByTogglingPermissions() throws Exception {

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

1
 package com.reactnativenavigation.react;
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
 import android.view.KeyEvent;
8
 import android.view.KeyEvent;
4
 
9
 
5
 import com.facebook.react.ReactInstanceManager;
10
 import com.facebook.react.ReactInstanceManager;
6
 
11
 
7
 public class JsDevReloadHandler {
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
 	private final ReactInstanceManager reactInstanceManager;
19
 	private final ReactInstanceManager reactInstanceManager;
9
 	private long firstRTimestamp = 0;
20
 	private long firstRTimestamp = 0;
10
 
21
 
12
 		this.reactInstanceManager = reactInstanceManager;
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
 	public boolean onKeyUp(int keyCode) {
34
 	public boolean onKeyUp(int keyCode) {
16
 		if (!reactInstanceManager.getDevSupportManager().getDevSupportEnabled()) {
35
 		if (!reactInstanceManager.getDevSupportManager().getDevSupportEnabled()) {
17
 			return false;
36
 			return false;
24
 
43
 
25
 		if (keyCode == KeyEvent.KEYCODE_R) {
44
 		if (keyCode == KeyEvent.KEYCODE_R) {
26
 			if (lessThan500MillisSinceLastR()) {
45
 			if (lessThan500MillisSinceLastR()) {
27
-				reactInstanceManager.getDevSupportManager().handleReloadJS();
46
+				reloadReactNative();
28
 				return true;
47
 				return true;
29
 			}
48
 			}
30
 			firstRTimestamp = System.currentTimeMillis();
49
 			firstRTimestamp = System.currentTimeMillis();
35
 	private boolean lessThan500MillisSinceLastR() {
54
 	private boolean lessThan500MillisSinceLastR() {
36
 		return firstRTimestamp != 0 && System.currentTimeMillis() - firstRTimestamp < 1000;
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
 
25
 
26
 	public void onActivityResumed(NavigationActivity activity) {
26
 	public void onActivityResumed(NavigationActivity activity) {
27
 		initializer.onActivityResumed(activity);
27
 		initializer.onActivityResumed(activity);
28
+		jsDevReloadHandler.onActivityResumed(activity);
28
 	}
29
 	}
29
 
30
 
30
 	public void onActivityPaused(NavigationActivity activity) {
31
 	public void onActivityPaused(NavigationActivity activity) {
31
 		initializer.onActivityPaused(activity);
32
 		initializer.onActivityPaused(activity);
33
+		jsDevReloadHandler.onActivityPaused(activity);
32
 	}
34
 	}
33
 
35
 
34
 	public void onActivityDestroyed(NavigationActivity activity) {
36
 	public void onActivityDestroyed(NavigationActivity activity) {