Daniel Zlotin 7 vuotta sitten
vanhempi
commit
655dc6bbd1

+ 26
- 13
e2e/Orientations.test.js Näytä tiedosto

@@ -8,39 +8,52 @@ describe('orientation', () => {
8 8
     await device.relaunchApp();
9 9
   });
10 10
 
11
-  it('orientation should not change from landscape', async () => {
12
-    await elementByLabel('Orientation').tap();
11
+  afterEach(async () => {
13 12
     await device.setOrientation('landscape');
14
-    await elementByLabel('Push landscape only screen').tap();
15 13
     await device.setOrientation('portrait');
16
-    await expect(element(by.id('currentOrientation'))).toHaveText('Landscape');
17 14
   });
18 15
 
19
-  it('orientation should not change from portrait', async () => {
16
+  it('default allows all', async () => {
20 17
     await elementByLabel('Orientation').tap();
21
-    await device.setOrientation('portrait');
22
-    await elementByLabel('Push portrait only screen').tap();
18
+    await elementByLabel('default').tap();
19
+    await expect(element(by.id('currentOrientation'))).toHaveText('Portrait');
23 20
     await device.setOrientation('landscape');
21
+    await expect(element(by.id('currentOrientation'))).toHaveText('Landscape');
22
+    await device.setOrientation('portrait');
24 23
     await expect(element(by.id('currentOrientation'))).toHaveText('Portrait');
24
+    await elementByLabel('Dismiss').tap();
25 25
   });
26 26
 
27
-  it('orientation should change to portrait and landscape', async () => {
27
+  it('landscape and portrait array', async () => {
28 28
     await elementByLabel('Orientation').tap();
29
-    await device.setOrientation('portrait');
30
-    await elementByLabel('Push landscape and portrait').tap();
29
+    await elementByLabel('landscape and portrait').tap();
30
+    await expect(element(by.id('currentOrientation'))).toHaveText('Portrait');
31 31
     await device.setOrientation('landscape');
32 32
     await expect(element(by.id('currentOrientation'))).toHaveText('Landscape');
33 33
     await device.setOrientation('portrait');
34 34
     await expect(element(by.id('currentOrientation'))).toHaveText('Portrait');
35
+    await elementByLabel('Dismiss').tap();
35 36
   });
36 37
 
37
-  it('orientation default should change to portrait and landscape', async () => {
38
+  it('portrait only', async () => {
38 39
     await elementByLabel('Orientation').tap();
40
+    await elementByLabel('portrait only').tap();
41
+    await expect(element(by.id('currentOrientation'))).toHaveText('Portrait');
42
+    await device.setOrientation('landscape');
43
+    await expect(element(by.id('currentOrientation'))).toHaveText('Portrait');
39 44
     await device.setOrientation('portrait');
40
-    await elementByLabel('Push default').tap();
45
+    await expect(element(by.id('currentOrientation'))).toHaveText('Portrait');
46
+    await elementByLabel('Dismiss').tap();
47
+  });
48
+
49
+  it('landscape only', async () => {
50
+    await elementByLabel('Orientation').tap();
51
+    await elementByLabel('landscape only').tap();
52
+    await expect(element(by.id('currentOrientation'))).toHaveText('Portrait');
41 53
     await device.setOrientation('landscape');
42 54
     await expect(element(by.id('currentOrientation'))).toHaveText('Landscape');
43 55
     await device.setOrientation('portrait');
44
-    await expect(element(by.id('currentOrientation'))).toHaveText('Portrait');
56
+    await expect(element(by.id('currentOrientation'))).toHaveText('Landscape');
57
+    await elementByLabel('Dismiss').tap();
45 58
   });
46 59
 });

playground/src/containers/OrientationScreen.js → playground/src/containers/OrientationDetectScreen.js Näytä tiedosto

@@ -1,11 +1,11 @@
1 1
 const React = require('react');
2 2
 const { Component } = require('react');
3 3
 
4
-const { View, Text } = require('react-native');
4
+const { View, Text, Button } = require('react-native');
5 5
 
6 6
 const Navigation = require('react-native-navigation');
7 7
 
8
-class OrientationScreen extends Component {
8
+class OrientationDetectScreen extends Component {
9 9
   constructor(props) {
10 10
     super(props);
11 11
 
@@ -20,6 +20,7 @@ class OrientationScreen extends Component {
20 20
     return (
21 21
       <View style={styles.root} onLayout={this.detectHorizontal}>
22 22
         <Text style={styles.h1}>{`Orientation Screen`}</Text>
23
+        <Button title="Dismiss" onPress={() => Navigation.dismissModal(this.props.containerId)} />
23 24
         <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
24 25
         <Text style={styles.footer} testID="currentOrientation">{this.state.horizontal ? 'Landscape' : 'Portrait'}</Text>
25 26
       </View>
@@ -56,4 +57,4 @@ const styles = {
56 57
   }
57 58
 };
58 59
 
59
-module.exports = OrientationScreen;
60
+module.exports = OrientationDetectScreen;

+ 0
- 53
playground/src/containers/OrientationMenuScreen.js Näytä tiedosto

@@ -1,53 +0,0 @@
1
-const React = require('react');
2
-const { Component } = require('react');
3
-const { View, Text, Button } = require('react-native');
4
-
5
-const Navigation = require('react-native-navigation');
6
-
7
-class OrientationMenuScreen extends Component {
8
-  constructor(props) {
9
-    super(props);
10
-    this.onClickPushOrientationScreen = this.onClickPushOrientationScreen.bind(this);
11
-  }
12
-
13
-  render() {
14
-    return (
15
-      <View style={styles.root}>
16
-        <Text style={styles.h1}>{`Orientation Menu`}</Text>
17
-        <Button title="Push landscape only screen" onPress={() => this.onClickPushOrientationScreen(['landscape'])} />
18
-        <Button title="Push portrait only screen" onPress={() => this.onClickPushOrientationScreen('portrait')} />
19
-        <Button title="Push landscape and portrait" onPress={() => this.onClickPushOrientationScreen(['landscape', 'portrait'])} />
20
-        <Button title="Push default" onPress={() => this.onClickPushOrientationScreen('default')} />
21
-      </View>
22
-    );
23
-  }
24
-
25
-  onClickPushOrientationScreen(orientation) {
26
-    Navigation.push(this.props.containerId, {
27
-      name: 'navigation.playground.OrientationScreen',
28
-      passProps: {
29
-        orientation
30
-      }
31
-    });
32
-  }
33
-}
34
-
35
-module.exports = OrientationMenuScreen;
36
-
37
-const styles = {
38
-  root: {
39
-    flexGrow: 1,
40
-    justifyContent: 'center',
41
-    alignItems: 'center'
42
-  },
43
-  h1: {
44
-    fontSize: 24,
45
-    textAlign: 'center',
46
-    margin: 30
47
-  },
48
-  footer: {
49
-    fontSize: 10,
50
-    color: '#888',
51
-    marginTop: 10
52
-  }
53
-};

+ 51
- 0
playground/src/containers/OrientationSelectScreen.js Näytä tiedosto

@@ -0,0 +1,51 @@
1
+const React = require('react');
2
+const { Component } = require('react');
3
+const { View, Text, Button } = require('react-native');
4
+
5
+const Navigation = require('react-native-navigation');
6
+
7
+class OrientationSelectScreen extends Component {
8
+
9
+  render() {
10
+    return (
11
+      <View style={styles.root}>
12
+        <Text style={styles.h1}>{`Orientation Menu`}</Text>
13
+        <Button title="default" onPress={() => this.onClickOrientationScreen('default')} />
14
+        <Button title="landscape and portrait" onPress={() => this.onClickOrientationScreen(['landscape', 'portrait'])} />
15
+        <Button title="portrait only" onPress={() => this.onClickOrientationScreen('portrait')} />
16
+        <Button title="landscape only" onPress={() => this.onClickOrientationScreen(['landscape'])} />
17
+      </View>
18
+    );
19
+  }
20
+
21
+  onClickOrientationScreen(orientation) {
22
+    Navigation.showModal({
23
+      container: {
24
+        name: 'navigation.playground.OrientationDetectScreen',
25
+        passProps: {
26
+          orientation
27
+        }
28
+      }
29
+    });
30
+  }
31
+}
32
+
33
+module.exports = OrientationSelectScreen;
34
+
35
+const styles = {
36
+  root: {
37
+    flexGrow: 1,
38
+    justifyContent: 'center',
39
+    alignItems: 'center'
40
+  },
41
+  h1: {
42
+    fontSize: 24,
43
+    textAlign: 'center',
44
+    margin: 30
45
+  },
46
+  footer: {
47
+    fontSize: 10,
48
+    color: '#888',
49
+    marginTop: 10
50
+  }
51
+};

+ 1
- 1
playground/src/containers/WelcomeScreen.js Näytä tiedosto

@@ -136,7 +136,7 @@ class WelcomeScreen extends Component {
136 136
 
137 137
   onClickPushOrientationMenuScreen() {
138 138
     Navigation.push(this.props.containerId, {
139
-      name: 'navigation.playground.OrientationMenuScreen'
139
+      name: 'navigation.playground.OrientationSelectScreen'
140 140
     });
141 141
   }
142 142
 }

+ 4
- 4
playground/src/containers/index.js Näytä tiedosto

@@ -5,8 +5,8 @@ const PushedScreen = require('./PushedScreen');
5 5
 const LifecycleScreen = require('./LifecycleScreen');
6 6
 const ModalScreen = require('./ModalScreen');
7 7
 const OptionsScreen = require('./OptionsScreen');
8
-const OrientationScreen = require('./OrientationScreen');
9
-const OrientationMenuScreen = require('./OrientationMenuScreen');
8
+const OrientationSelectScreen = require('./OrientationSelectScreen');
9
+const OrientationDetectScreen = require('./OrientationDetectScreen');
10 10
 const ScrollViewScreen = require('./ScrollViewScreen');
11 11
 
12 12
 function registerContainers() {
@@ -17,8 +17,8 @@ function registerContainers() {
17 17
   Navigation.registerContainer(`navigation.playground.TextScreen`, () => TextScreen);
18 18
   Navigation.registerContainer(`navigation.playground.PushedScreen`, () => PushedScreen);
19 19
   Navigation.registerContainer(`navigation.playground.OptionsScreen`, () => OptionsScreen);
20
-  Navigation.registerContainer(`navigation.playground.OrientationScreen`, () => OrientationScreen);
21
-  Navigation.registerContainer(`navigation.playground.OrientationMenuScreen`, () => OrientationMenuScreen);
20
+  Navigation.registerContainer(`navigation.playground.OrientationSelectScreen`, () => OrientationSelectScreen);
21
+  Navigation.registerContainer(`navigation.playground.OrientationDetectScreen`, () => OrientationDetectScreen);
22 22
 }
23 23
 
24 24
 module.exports = {