Browse Source

refactor, reloadReactNative on android

Daniel Zlotin 7 years ago
parent
commit
999ae9337f

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

4
 import android.net.Uri;
4
 import android.net.Uri;
5
 import android.provider.Settings;
5
 import android.provider.Settings;
6
 import android.support.test.uiautomator.By;
6
 import android.support.test.uiautomator.By;
7
+import android.view.KeyEvent;
7
 
8
 
8
 import org.junit.FixMethodOrder;
9
 import org.junit.FixMethodOrder;
9
 import org.junit.Test;
10
 import org.junit.Test;
37
 	@Test
38
 	@Test
38
 	public void _3_relaunchAfterClose() throws Exception {
39
 	public void _3_relaunchAfterClose() throws Exception {
39
 		launchTheApp();
40
 		launchTheApp();
41
+		assertMainShown();
42
+
40
 		elementByText("PUSH").click();
43
 		elementByText("PUSH").click();
41
 		assertExists(By.text("Pushed Screen"));
44
 		assertExists(By.text("Pushed Screen"));
42
 
45
 
49
 	@Test
52
 	@Test
50
 	public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
53
 	public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
51
 		launchTheApp();
54
 		launchTheApp();
55
+		assertMainShown();
52
 		elementByText("PUSH").click();
56
 		elementByText("PUSH").click();
53
 		assertExists(By.text("Pushed Screen"));
57
 		assertExists(By.text("Pushed Screen"));
54
 
58
 
61
 	@Test
65
 	@Test
62
 	public void _5_relaunchAfterActivityKilledBySystem() throws Exception {
66
 	public void _5_relaunchAfterActivityKilledBySystem() throws Exception {
63
 		launchTheApp();
67
 		launchTheApp();
68
+		assertMainShown();
64
 		elementByText("PUSH").click();
69
 		elementByText("PUSH").click();
65
 		assertExists(By.text("Pushed Screen"));
70
 		assertExists(By.text("Pushed Screen"));
66
 
71
 
71
 		assertMainShown();
76
 		assertMainShown();
72
 	}
77
 	}
73
 
78
 
79
+	@Test
80
+	public void _6_reloadReactNativeApp() throws Exception {
81
+		launchTheApp();
82
+		assertMainShown();
83
+		elementByText("PUSH").click();
84
+		assertExists(By.text("Pushed Screen"));
85
+		device().pressKeyCode(KeyEvent.KEYCODE_R);
86
+		device().pressKeyCode(KeyEvent.KEYCODE_R);
87
+		assertMainShown();
88
+	}
89
+
74
 	private void killAppSaveInstanceState_ByTogglingPermissions() throws Exception {
90
 	private void killAppSaveInstanceState_ByTogglingPermissions() throws Exception {
75
 		device().pressHome();
91
 		device().pressHome();
76
 
92
 

+ 14
- 0
lib/android/app/src/main/java/com/reactnativenavigation/NavigationActivity.java View File

3
 import android.os.Bundle;
3
 import android.os.Bundle;
4
 import android.support.annotation.Nullable;
4
 import android.support.annotation.Nullable;
5
 import android.support.v7.app.AppCompatActivity;
5
 import android.support.v7.app.AppCompatActivity;
6
+import android.view.KeyEvent;
7
+import android.widget.Toast;
6
 
8
 
7
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
9
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
8
 import com.reactnativenavigation.viewcontrollers.Navigator;
10
 import com.reactnativenavigation.viewcontrollers.Navigator;
47
 		}
49
 		}
48
 	}
50
 	}
49
 
51
 
52
+	
53
+	@Override
54
+	public boolean onKeyMultiple(final int keyCode, final int repeatCount, final KeyEvent event) {
55
+		Toast.makeText(this, "onKeyMultiple", Toast.LENGTH_SHORT).show();
56
+		if (keyCode == KeyEvent.KEYCODE_R && repeatCount == 2) {
57
+			Toast.makeText(this, "RR!!!!", Toast.LENGTH_SHORT).show();
58
+			return true;
59
+		} else {
60
+			return super.onKeyMultiple(keyCode, repeatCount, event);
61
+		}
62
+	}
63
+
50
 	public Navigator getNavigator() {
64
 	public Navigator getNavigator() {
51
 		return navigator;
65
 		return navigator;
52
 	}
66
 	}

lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/IndexedStack.java → lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/IdStack.java View File

7
 import java.util.HashMap;
7
 import java.util.HashMap;
8
 import java.util.Iterator;
8
 import java.util.Iterator;
9
 
9
 
10
-public class IndexedStack<E> implements Iterable<String> {
10
+public class IdStack<E> implements Iterable<String> {
11
 
11
 
12
 	private final ArrayDeque<String> deque = new ArrayDeque<>();
12
 	private final ArrayDeque<String> deque = new ArrayDeque<>();
13
 	private final HashMap<String, E> map = new HashMap<>();
13
 	private final HashMap<String, E> map = new HashMap<>();

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java View File

10
 import java.util.Collection;
10
 import java.util.Collection;
11
 
11
 
12
 public class StackController extends ParentController {
12
 public class StackController extends ParentController {
13
-	private final IndexedStack<ViewController> stack = new IndexedStack<>();
13
+	private final IdStack<ViewController> stack = new IdStack<>();
14
 	private StackAnimator animator;
14
 	private StackAnimator animator;
15
 
15
 
16
 	public StackController(final Activity activity, String id) {
16
 	public StackController(final Activity activity, String id) {

lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/IndexedStackTest.java → lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/IdStackTest.java View File

6
 
6
 
7
 import static org.assertj.core.api.Java6Assertions.assertThat;
7
 import static org.assertj.core.api.Java6Assertions.assertThat;
8
 
8
 
9
-public class IndexedStackTest extends BaseTest {
9
+public class IdStackTest extends BaseTest {
10
 
10
 
11
-	private IndexedStack<Integer> uut;
11
+	private IdStack<Integer> uut;
12
 
12
 
13
 	@Override
13
 	@Override
14
 	public void beforeEach() {
14
 	public void beforeEach() {
15
 		super.beforeEach();
15
 		super.beforeEach();
16
-		uut = new IndexedStack<>();
16
+		uut = new IdStack<>();
17
 	}
17
 	}
18
 
18
 
19
 	@Test
19
 	@Test