Parcourir la source

android: device orientation

Daniel Zlotin il y a 8 ans
Parent
révision
3572f8543d

+ 47
- 11
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ApplicationLifecycleTest.java Voir le fichier

1
 package com.reactnativenavigation.e2e.androide2e;
1
 package com.reactnativenavigation.e2e.androide2e;
2
 
2
 
3
 import android.support.test.runner.AndroidJUnit4;
3
 import android.support.test.runner.AndroidJUnit4;
4
+import android.support.test.uiautomator.By;
5
+import android.support.test.uiautomator.BySelector;
4
 import android.support.test.uiautomator.UiDevice;
6
 import android.support.test.uiautomator.UiDevice;
7
+import android.support.test.uiautomator.UiObject;
5
 import android.support.test.uiautomator.UiScrollable;
8
 import android.support.test.uiautomator.UiScrollable;
6
 import android.support.test.uiautomator.UiSelector;
9
 import android.support.test.uiautomator.UiSelector;
10
+import android.support.test.uiautomator.Until;
7
 
11
 
8
 import org.junit.After;
12
 import org.junit.After;
9
 import org.junit.Before;
13
 import org.junit.Before;
18
 import static org.assertj.core.api.Java6Assertions.assertThat;
22
 import static org.assertj.core.api.Java6Assertions.assertThat;
19
 
23
 
20
 @RunWith(AndroidJUnit4.class)
24
 @RunWith(AndroidJUnit4.class)
21
-@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
25
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
22
 public class ApplicationLifecycleTest {
26
 public class ApplicationLifecycleTest {
23
 
27
 
24
     private static final String PACKAGE_NAME = "com.reactnativenavigation.playground";
28
     private static final String PACKAGE_NAME = "com.reactnativenavigation.playground";
25
-    private static final int TIMEOUT = 2000;
29
+    private static final long TIMEOUT = 3000;
26
 
30
 
27
     @Before
31
     @Before
28
     public void beforeEach() {
32
     public void beforeEach() {
38
     public void _1_showSplash_AcceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
42
     public void _1_showSplash_AcceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
39
         launchTheApp();
43
         launchTheApp();
40
 //        assertThat(uiDevice().wait(Until.hasObject(By.desc("NavigationSplashView")), TIMEOUT)).isTrue();
44
 //        assertThat(uiDevice().wait(Until.hasObject(By.desc("NavigationSplashView")), TIMEOUT)).isTrue();
41
-        acceptOverlayPermissionIfNeeded();
42
         assertMainShown();
45
         assertMainShown();
43
     }
46
     }
44
 
47
 
49
 
52
 
50
         uiDevice().pressHome();
53
         uiDevice().pressHome();
51
         uiDevice().pressRecentApps();
54
         uiDevice().pressRecentApps();
52
-        uiDevice().findObject(new UiSelector().text("Playground")).click();
55
+        elementByText("Playground").click();
53
         assertMainShown();
56
         assertMainShown();
54
     }
57
     }
55
 
58
 
64
         assertMainShown();
67
         assertMainShown();
65
     }
68
     }
66
 
69
 
70
+    @Test
71
+    public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
72
+        launchTheApp();
73
+        assertMainShown();
74
+
75
+        elementByText("PUSH").click();
76
+        assertExists(By.text("Pushed screen"));
77
+
78
+        uiDevice().setOrientationLeft();
79
+        Thread.sleep(100);
80
+
81
+        assertExists(By.text("Pushed screen"));
82
+    }
83
+
67
     private void assertMainShown() {
84
     private void assertMainShown() {
68
-        assertThat(uiDevice().findObject(new UiSelector().text("React Native Navigation!")).exists()).isTrue();
85
+        assertExists(By.text("React Native Navigation!"));
69
     }
86
     }
70
 
87
 
71
     private void acceptOverlayPermissionIfNeeded() throws Exception {
88
     private void acceptOverlayPermissionIfNeeded() throws Exception {
72
-        if (uiDevice().findObject(new UiSelector().text("Draw over other apps")).exists()) {
73
-            uiDevice().findObject(new UiSelector().text("Playground")).click();
74
-            uiDevice().findObject(new UiSelector().text("Permit drawing over other apps")).click();
89
+        if (elementByText("Draw over other apps").exists()) {
90
+            if (!elementByText("Playground").exists()) {
91
+                scrollToText("Playground");
92
+            }
93
+            elementByText("Playground").click();
94
+            elementByText("Permit drawing over other apps").click();
75
             uiDevice().pressBack();
95
             uiDevice().pressBack();
76
             uiDevice().pressBack();
96
             uiDevice().pressBack();
77
         }
97
         }
80
     private void launchTheApp() throws Exception {
100
     private void launchTheApp() throws Exception {
81
         uiDevice().wakeUp();
101
         uiDevice().wakeUp();
82
         uiDevice().pressHome();
102
         uiDevice().pressHome();
83
-        uiDevice().findObject(new UiSelector().description("Apps")).clickAndWaitForNewWindow();
84
-        new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView("Playground");
85
-        uiDevice().findObject(new UiSelector().text("Playground")).clickAndWaitForNewWindow();
103
+        elementByDesc("Apps").clickAndWaitForNewWindow();
104
+        scrollToText("Playground");
105
+        elementByText("Playground").clickAndWaitForNewWindow();
106
+        acceptOverlayPermissionIfNeeded();
86
     }
107
     }
87
 
108
 
88
     private UiDevice uiDevice() {
109
     private UiDevice uiDevice() {
89
         return UiDevice.getInstance(getInstrumentation());
110
         return UiDevice.getInstance(getInstrumentation());
90
     }
111
     }
91
 
112
 
113
+    private UiObject elementByText(String text) {
114
+        return uiDevice().findObject(new UiSelector().text(text));
115
+    }
116
+
117
+    private UiObject elementByDesc(String text) {
118
+        return uiDevice().findObject(new UiSelector().description(text));
119
+    }
120
+
121
+    private void scrollToText(String txt) throws Exception {
122
+        new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView(txt);
123
+    }
124
+
125
+    private void assertExists(BySelector selector) {
126
+        assertThat(uiDevice().wait(Until.hasObject(selector), TIMEOUT)).isTrue();
127
+    }
92
 }
128
 }

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/NavigationActivity.java Voir le fichier

1
 package com.reactnativenavigation;
1
 package com.reactnativenavigation;
2
 
2
 
3
+import android.content.res.Configuration;
3
 import android.os.Bundle;
4
 import android.os.Bundle;
4
 import android.support.annotation.Nullable;
5
 import android.support.annotation.Nullable;
5
 import android.support.v7.app.AppCompatActivity;
6
 import android.support.v7.app.AppCompatActivity;

+ 0
- 9
playground/android/app/src/androidTest/AndroidManifest.xml Voir le fichier

1
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
-    xmlns:tools="http://schemas.android.com/tools"
3
-    package="com.reactnativenavigation.playground">
4
-
5
-    <uses-sdk
6
-        android:minSdkVersion="23"
7
-        tools:overrideLibrary="android.support.test.uiautomator.v18" />
8
-
9
-</manifest>

+ 2
- 0
playground/android/app/src/main/AndroidManifest.xml Voir le fichier

11
         android:theme="@style/AppTheme">
11
         android:theme="@style/AppTheme">
12
         <activity
12
         <activity
13
             android:name=".MainActivity"
13
             android:name=".MainActivity"
14
+            android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
14
             android:label="@string/app_name"
15
             android:label="@string/app_name"
15
             android:launchMode="singleTask">
16
             android:launchMode="singleTask">
16
             <intent-filter>
17
             <intent-filter>
18
                 <category android:name="android.intent.category.LAUNCHER" />
19
                 <category android:name="android.intent.category.LAUNCHER" />
19
             </intent-filter>
20
             </intent-filter>
20
         </activity>
21
         </activity>
22
+        <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
21
     </application>
23
     </application>
22
 </manifest>
24
 </manifest>