Przeglądaj źródła

iOS refactoring

Ran Greenberg 8 lat temu
rodzic
commit
4bd0ded475

+ 7
- 0
playground/e2e/app.test.js Wyświetl plik

@@ -50,6 +50,13 @@ describe('app', () => {
50 50
     elementByLabel('Dismiss Modal').tap();
51 51
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
52 52
   });
53
+  
54
+  it.only('show multiple modals', () => {
55
+    elementByLabel('Show Modal').tap();
56
+    expect(elementByLabel('ModalStackPosition: 1')).toBeVisible();
57
+    elementByLabel('Show Modal').tap();
58
+    expect(elementByLabel('ModalStackPosition: 2s')).toBeVisible();
59
+  })
53 60
 });
54 61
 
55 62
 describe('reload app', () => {

+ 8
- 1
playground/src/containers/LifecycleScreen.js Wyświetl plik

@@ -23,15 +23,17 @@ class LifecycleScreen extends Component {
23 23
   render() {
24 24
     return (
25 25
       <View style={styles.root}>
26
+        <Text style={styles.h1}>Lifecycle Screen</Text>
26 27
         <Text style={styles.h1}>{this.state.text}</Text>
27 28
         <Button title="Push to test onStop" onPress={this.onClickPush} />
29
+        <Text style={styles.footer}>ContainerId: {this.props.id}</Text>
28 30
       </View>
29 31
     );
30 32
   }
31 33
 
32 34
   onClickPush() {
33 35
     Navigation.on(this.props.id).push({
34
-      name: 'navigation.playground.SimpleScreen'
36
+      name: 'navigation.playground.TextScreen'
35 37
     });
36 38
   }
37 39
 }
@@ -48,5 +50,10 @@ const styles = {
48 50
     fontSize: 24,
49 51
     textAlign: 'center',
50 52
     margin: 10
53
+  },
54
+  footer: {
55
+    fontSize: 10,
56
+    color: '#888',
57
+    marginTop: 10
51 58
   }
52 59
 };

+ 67
- 0
playground/src/containers/ModalScreen.js Wyświetl plik

@@ -0,0 +1,67 @@
1
+import React, {Component} from 'react';
2
+import {
3
+  StyleSheet,
4
+  View,
5
+  Text,
6
+  Button
7
+} from 'react-native';
8
+
9
+import Navigation from 'react-native-navigation';
10
+
11
+class ModalScreen extends Component {
12
+  constructor(props) {
13
+    super(props);
14
+    this.onClickShowModal = this.onClickShowModal.bind(this);
15
+    this.onClickDismissModal = this.onClickDismissModal.bind(this);
16
+  }
17
+  render() {
18
+    return (
19
+      <View style={styles.root}>
20
+        <Text style={styles.h1}>Modal Screen</Text>
21
+        <Text style={styles.footer}>ModalStackPosition: {this.props.modalPosition || 1}</Text>
22
+        <Button title="Show Modal" onPress={this.onClickShowModal} />
23
+        <Button title="Dismiss Modal" onPress={this.onClickDismissModal} />
24
+        <Text style={styles.footer}>ContainerId: {this.props.id}</Text>
25
+      </View>
26
+    );
27
+  }
28
+  
29
+  onClickShowModal() {
30
+    Navigation.showModal({
31
+      name: 'navigation.playground.ModalScreen',
32
+      passProps: {
33
+        modalPosition: (this.props.modalPosition || 1) + 1
34
+      }
35
+    });
36
+  }
37
+  
38
+  onClickDismissModal() {
39
+    Navigation.dismissModal(this.props.id);
40
+  }
41
+}
42
+
43
+const styles = {
44
+  root: {
45
+    flexGrow: 1,
46
+    justifyContent: 'center',
47
+    alignItems: 'center',
48
+    backgroundColor: '#f5fcff'
49
+  },
50
+  h1: {
51
+    fontSize: 24,
52
+    textAlign: 'center',
53
+    margin: 10
54
+  },
55
+  h2: {
56
+    fontSize: 12,
57
+    textAlign: 'center',
58
+    margin: 10
59
+  },
60
+  footer: {
61
+    fontSize: 10,
62
+    color: '#888',
63
+    marginTop: 10
64
+  }
65
+};
66
+
67
+export default ModalScreen;

+ 67
- 0
playground/src/containers/PushedScreen.js Wyświetl plik

@@ -0,0 +1,67 @@
1
+import React, {Component} from 'react';
2
+import {
3
+  StyleSheet,
4
+  View,
5
+  Text,
6
+  Button
7
+} from 'react-native';
8
+
9
+import Navigation from 'react-native-navigation';
10
+
11
+class PushedScreen extends Component {
12
+  constructor(props) {
13
+    super(props);
14
+    this.onClickPush = this.onClickPush.bind(this);
15
+    this.onClickPop = this.onClickPop.bind(this);
16
+  }
17
+  render() {
18
+    return (
19
+      <View style={styles.root}>
20
+        <Text style={styles.h1}>Pushed Screen</Text>
21
+        <Text style={styles.h2}>Stack Position: {this.props.stackPosition || 1}</Text>
22
+        <Button title="Push" onPress={this.onClickPush} />
23
+        <Button title="Pop" onPress={this.onClickPop} />
24
+        <Text style={styles.footer}>ContainerId: {this.props.id}</Text>
25
+      </View>
26
+    );
27
+  }
28
+  
29
+  onClickPush() {
30
+    Navigation.on(this.props.id).push({
31
+      name: 'navigation.playground.PushedScreen',
32
+      passProps: {
33
+        stackPosition: (this.props.stackPosition || 1) + 1
34
+      }
35
+    });
36
+  }
37
+  
38
+  onClickPop() {
39
+    Navigation.on(this.props.id).pop();
40
+  }
41
+}
42
+
43
+const styles = {
44
+  root: {
45
+    flexGrow: 1,
46
+    justifyContent: 'center',
47
+    alignItems: 'center',
48
+    backgroundColor: '#f5fcff'
49
+  },
50
+  h1: {
51
+    fontSize: 24,
52
+    textAlign: 'center',
53
+    margin: 10
54
+  },
55
+  h2: {
56
+    fontSize: 12,
57
+    textAlign: 'center',
58
+    margin: 10
59
+  },
60
+  footer: {
61
+    fontSize: 10,
62
+    color: '#888',
63
+    marginTop: 10
64
+  }
65
+};
66
+
67
+export default PushedScreen;

+ 84
- 83
playground/src/containers/SimpleScreen.js Wyświetl plik

@@ -1,83 +1,84 @@
1
-import React, { Component } from 'react';
2
-import { View, Text, Button } from 'react-native';
3
-
4
-import Navigation from 'react-native-navigation';
5
-
6
-class SimpleScreen extends Component {
7
-  constructor(props) {
8
-    super(props);
9
-    this.onClickPop = this.onClickPop.bind(this);
10
-    this.onClickPush = this.onClickPush.bind(this);
11
-    this.onClickShowModal = this.onClickShowModal.bind(this);
12
-    this.onClickDismissModal = this.onClickDismissModal.bind(this);
13
-  }
14
-
15
-  render() {
16
-    return (
17
-      <View style={styles.root}>
18
-        <Text style={styles.h1}>{this.props.text || 'Simple Screen'}</Text>
19
-        <Text style={styles.h2}>{this.props.stackPosition}</Text>
20
-        {this.renderTextFromFunctionInProps()}
21
-        <Button title="Push" onPress={this.onClickPush} />
22
-        <Button title="Pop" onPress={this.onClickPop} />
23
-        <Button title="Show Mddal" onPress={this.onClickPop} />
24
-        <Button title="Dismiss Modal" onPress={this.onClickDismissModal} />
25
-      </View>
26
-    );
27
-  }
28
-
29
-  renderTextFromFunctionInProps() {
30
-    if (!this.props.myFunction) {
31
-      return undefined;
32
-    }
33
-    return (
34
-      <Text style={styles.h1}>{this.props.myFunction()}</Text>
35
-    );
36
-  }
37
-
38
-  onClickPop() {
39
-    Navigation.on(this.props.id).pop();
40
-  }
41
-
42
-  onClickPush() {
43
-    Navigation.on(this.props.id).push({
44
-      name: 'navigation.playground.SimpleScreen',
45
-      passProps: {
46
-        stackPosition: this.props.stackPosition + 1
47
-      }
48
-    });
49
-  }
50
-  
51
-  onClickShowModal() {
52
-    Navigation.showModal({
53
-      name: 'navigation.playground.SimpleScreen',
54
-      passProps: {
55
-        text: 'Modal screen'
56
-      }
57
-    });
58
-  }
59
-
60
-  onClickDismissModal() {
61
-    Navigation.dismissModal(this.props.id);
62
-  }
63
-}
64
-export default SimpleScreen;
65
-
66
-const styles = {
67
-  root: {
68
-    flexGrow: 1,
69
-    justifyContent: 'center',
70
-    alignItems: 'center',
71
-    backgroundColor: '#f5fcff'
72
-  },
73
-  h1: {
74
-    fontSize: 24,
75
-    textAlign: 'center',
76
-    margin: 10
77
-  },
78
-  h2: {
79
-    fontSize: 12,
80
-    textAlign: 'center',
81
-    margin: 10
82
-  }
83
-};
1
+//import React, { Component } from 'react';
2
+//import { View, Text, Button } from 'react-native';
3
+//
4
+//import Navigation from 'react-native-navigation';
5
+//
6
+//class SimpleScreen extends Component {
7
+//  constructor(props) {
8
+//    super(props);
9
+//    this.onClickPop = this.onClickPop.bind(this);
10
+//    this.onClickPush = this.onClickPush.bind(this);
11
+//    this.onClickShowModal = this.onClickShowModal.bind(this);
12
+//    this.onClickDismissModal = this.onClickDismissModal.bind(this);
13
+//  }
14
+//
15
+//  render() {
16
+//    return (
17
+//      <View style={styles.root}>
18
+//        <Text style={styles.h1}>{'Simple Screen'}</Text>
19
+//        <Text style={styles.h1}>Origin: {this.props.origin}</Text>
20
+//        <Text style={styles.h2}>Stack Position: {this.props.stackPosition}</Text>
21
+//        {this.renderTextFromFunctionInProps()}
22
+//        <Button title="Push" onPress={this.onClickPush} />
23
+//        <Button title="Pop" onPress={this.onClickPop} />
24
+//        <Button title="Show Modal" onPress={this.onClickPop} />
25
+//        <Button title="Dismiss Modal" onPress={this.onClickDismissModal} />
26
+//      </View>
27
+//    );
28
+//  }
29
+//
30
+//  renderTextFromFunctionInProps() {
31
+//    if (!this.props.myFunction) {
32
+//      return undefined;
33
+//    }
34
+//    return (
35
+//      <Text style={styles.h1}>{this.props.myFunction()}</Text>
36
+//    );
37
+//  }
38
+//
39
+//  onClickPop() {
40
+//    Navigation.on(this.props.id).pop();
41
+//  }
42
+//
43
+//  onClickPush() {
44
+//    Navigation.on(this.props.id).push({
45
+//      name: 'navigation.playground.SimpleScreen',
46
+//      passProps: {
47
+//        stackPosition: this.props.stackPosition + 1
48
+//      }
49
+//    });
50
+//  }
51
+//
52
+//  onClickShowModal() {
53
+//    Navigation.showModal({
54
+//      name: 'navigation.playground.SimpleScreen',
55
+//      passProps: {
56
+//        text: 'Modal screen'
57
+//      }
58
+//    });
59
+//  }
60
+//
61
+//  onClickDismissModal() {
62
+//    Navigation.dismissModal(this.props.id);
63
+//  }
64
+//}
65
+//export default SimpleScreen;
66
+//
67
+//const styles = {
68
+//  root: {
69
+//    flexGrow: 1,
70
+//    justifyContent: 'center',
71
+//    alignItems: 'center',
72
+//    backgroundColor: '#f5fcff'
73
+//  },
74
+//  h1: {
75
+//    fontSize: 24,
76
+//    textAlign: 'center',
77
+//    margin: 10
78
+//  },
79
+//  h2: {
80
+//    fontSize: 12,
81
+//    textAlign: 'center',
82
+//    margin: 10
83
+//  }
84
+//};

+ 46
- 0
playground/src/containers/TextScreen.js Wyświetl plik

@@ -0,0 +1,46 @@
1
+import React, {Component} from 'react';
2
+import {
3
+  StyleSheet,
4
+  View,
5
+  Text
6
+} from 'react-native';
7
+
8
+
9
+class TextScreen extends Component {
10
+  
11
+  render() {
12
+    return (
13
+      <View style={styles.root}>
14
+        <Text style={styles.h1}>{this.props.text || 'Text Screen'}</Text>
15
+        <Text style={styles.footer}>ContainerId: {this.props.id}</Text>
16
+      </View>
17
+    );
18
+  }
19
+}
20
+
21
+const styles = {
22
+  root: {
23
+    flexGrow: 1,
24
+    justifyContent: 'center',
25
+    alignItems: 'center',
26
+    backgroundColor: '#f5fcff'
27
+  },
28
+  h1: {
29
+    fontSize: 24,
30
+    textAlign: 'center',
31
+    margin: 10
32
+  },
33
+  h2: {
34
+    fontSize: 12,
35
+    textAlign: 'center',
36
+    margin: 10
37
+  },
38
+  footer: {
39
+    fontSize: 10,
40
+    color: '#888',
41
+    marginTop: 10
42
+  }
43
+};
44
+
45
+
46
+export default TextScreen;

+ 10
- 17
playground/src/containers/WelcomeScreen.js Wyświetl plik

@@ -30,7 +30,7 @@ class WelcomeScreen extends Component {
30 30
       tabs: [
31 31
         {
32 32
           container: {
33
-            name: 'navigation.playground.SimpleScreen',
33
+            name: 'navigation.playground.TextScreen',
34 34
             passProps: {
35 35
               text: 'This is tab 1',
36 36
               myFunction: () => 'Hello from a function!'
@@ -39,7 +39,7 @@ class WelcomeScreen extends Component {
39 39
         },
40 40
         {
41 41
           container: {
42
-            name: 'navigation.playground.SimpleScreen',
42
+            name: 'navigation.playground.TextScreen',
43 43
             passProps: {
44 44
               text: 'This is tab 2'
45 45
             }
@@ -54,7 +54,7 @@ class WelcomeScreen extends Component {
54 54
       tabs: [
55 55
         {
56 56
           container: {
57
-            name: 'navigation.playground.SimpleScreen',
57
+            name: 'navigation.playground.TextScreen',
58 58
             passProps: {
59 59
               text: 'This is a side menu center screen'
60 60
             }
@@ -62,19 +62,19 @@ class WelcomeScreen extends Component {
62 62
         },
63 63
         {
64 64
           container: {
65
-            name: 'navigation.playground.SimpleScreen'
65
+            name: 'navigation.playground.TextScreen'
66 66
           }
67 67
         },
68 68
         {
69 69
           container: {
70
-            name: 'navigation.playground.SimpleScreen'
70
+            name: 'navigation.playground.TextScreen'
71 71
           }
72 72
         }
73 73
       ],
74 74
       sideMenu: {
75 75
         left: {
76 76
           container: {
77
-            name: 'navigation.playground.SimpleScreen',
77
+            name: 'navigation.playground.TextScreen',
78 78
             passProps: {
79 79
               text: 'This is a side menu screen'
80 80
             }
@@ -82,7 +82,7 @@ class WelcomeScreen extends Component {
82 82
         },
83 83
         right: {
84 84
           container: {
85
-            name: 'navigation.playground.SimpleScreen'
85
+            name: 'navigation.playground.TextScreen'
86 86
           }
87 87
         }
88 88
       }
@@ -91,11 +91,7 @@ class WelcomeScreen extends Component {
91 91
 
92 92
   onClickPush() {
93 93
     Navigation.on(this.props.id).push({
94
-      name: 'navigation.playground.SimpleScreen',
95
-      passProps: {
96
-        text: 'Pushed screen',
97
-        stackPosition: 1
98
-      }
94
+      name: 'navigation.playground.PushedScreen'
99 95
     });
100 96
   }
101 97
 
@@ -109,10 +105,7 @@ class WelcomeScreen extends Component {
109 105
 
110 106
   onClickShowModal() {
111 107
     Navigation.showModal({
112
-      name: 'navigation.playground.SimpleScreen',
113
-      passProps: {
114
-        text: 'Modal screen'
115
-      }
108
+      name: 'navigation.playground.ModalScreen',
116 109
     });
117 110
   }
118 111
 
@@ -138,6 +131,6 @@ const styles = {
138 131
   footer: {
139 132
     fontSize: 10,
140 133
     color: '#888',
141
-    marginTop: 80
134
+    marginTop: 10
142 135
   }
143 136
 };

+ 7
- 2
playground/src/containers/index.js Wyświetl plik

@@ -1,11 +1,16 @@
1 1
 import Navigation from 'react-native-navigation';
2 2
 
3 3
 import WelcomeScreen from './WelcomeScreen';
4
-import SimpleScreen from './SimpleScreen';
4
+import TextScreen from './TextScreen';
5
+import PushedScreen from './PushedScreen';
5 6
 import LifecycleScreen from './LifecycleScreen';
7
+import ModalScreen from './ModalScreen';
8
+
6 9
 
7 10
 export function registerContainers() {
8 11
   Navigation.registerContainer(`navigation.playground.WelcomeScreen`, () => WelcomeScreen);
9
-  Navigation.registerContainer(`navigation.playground.SimpleScreen`, () => SimpleScreen);
12
+  Navigation.registerContainer(`navigation.playground.ModalScreen`, () => ModalScreen);
10 13
   Navigation.registerContainer(`navigation.playground.LifecycleScreen`, () => LifecycleScreen);
14
+  Navigation.registerContainer(`navigation.playground.TextScreen`, () => TextScreen);
15
+  Navigation.registerContainer(`navigation.playground.PushedScreen`, () => PushedScreen);
11 16
 }