ソースを参照

refactor, reloadReactNative on android

Daniel Zlotin 7 年 前
コミット
999ae9337f

+ 16
- 0
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ApplicationLifecycleTest.java ファイルの表示

@@ -4,6 +4,7 @@ import android.content.Intent;
4 4
 import android.net.Uri;
5 5
 import android.provider.Settings;
6 6
 import android.support.test.uiautomator.By;
7
+import android.view.KeyEvent;
7 8
 
8 9
 import org.junit.FixMethodOrder;
9 10
 import org.junit.Test;
@@ -37,6 +38,8 @@ public class ApplicationLifecycleTest extends BaseTest {
37 38
 	@Test
38 39
 	public void _3_relaunchAfterClose() throws Exception {
39 40
 		launchTheApp();
41
+		assertMainShown();
42
+
40 43
 		elementByText("PUSH").click();
41 44
 		assertExists(By.text("Pushed Screen"));
42 45
 
@@ -49,6 +52,7 @@ public class ApplicationLifecycleTest extends BaseTest {
49 52
 	@Test
50 53
 	public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
51 54
 		launchTheApp();
55
+		assertMainShown();
52 56
 		elementByText("PUSH").click();
53 57
 		assertExists(By.text("Pushed Screen"));
54 58
 
@@ -61,6 +65,7 @@ public class ApplicationLifecycleTest extends BaseTest {
61 65
 	@Test
62 66
 	public void _5_relaunchAfterActivityKilledBySystem() throws Exception {
63 67
 		launchTheApp();
68
+		assertMainShown();
64 69
 		elementByText("PUSH").click();
65 70
 		assertExists(By.text("Pushed Screen"));
66 71
 
@@ -71,6 +76,17 @@ public class ApplicationLifecycleTest extends BaseTest {
71 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 90
 	private void killAppSaveInstanceState_ByTogglingPermissions() throws Exception {
75 91
 		device().pressHome();
76 92
 

+ 14
- 0
lib/android/app/src/main/java/com/reactnativenavigation/NavigationActivity.java ファイルの表示

@@ -3,6 +3,8 @@ package com.reactnativenavigation;
3 3
 import android.os.Bundle;
4 4
 import android.support.annotation.Nullable;
5 5
 import android.support.v7.app.AppCompatActivity;
6
+import android.view.KeyEvent;
7
+import android.widget.Toast;
6 8
 
7 9
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
8 10
 import com.reactnativenavigation.viewcontrollers.Navigator;
@@ -47,6 +49,18 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
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 64
 	public Navigator getNavigator() {
51 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 ファイルの表示

@@ -7,7 +7,7 @@ import java.util.Collection;
7 7
 import java.util.HashMap;
8 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 12
 	private final ArrayDeque<String> deque = new ArrayDeque<>();
13 13
 	private final HashMap<String, E> map = new HashMap<>();

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java ファイルの表示

@@ -10,7 +10,7 @@ import com.reactnativenavigation.anim.StackAnimator;
10 10
 import java.util.Collection;
11 11
 
12 12
 public class StackController extends ParentController {
13
-	private final IndexedStack<ViewController> stack = new IndexedStack<>();
13
+	private final IdStack<ViewController> stack = new IdStack<>();
14 14
 	private StackAnimator animator;
15 15
 
16 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 ファイルの表示

@@ -6,14 +6,14 @@ import org.junit.Test;
6 6
 
7 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 13
 	@Override
14 14
 	public void beforeEach() {
15 15
 		super.beforeEach();
16
-		uut = new IndexedStack<>();
16
+		uut = new IdStack<>();
17 17
 	}
18 18
 
19 19
 	@Test