Browse Source

iOS refactoring

Ran Greenberg 8 years ago
parent
commit
4bd0ded475

+ 7
- 0
playground/e2e/app.test.js View File

50
     elementByLabel('Dismiss Modal').tap();
50
     elementByLabel('Dismiss Modal').tap();
51
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
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
 describe('reload app', () => {
62
 describe('reload app', () => {

+ 8
- 1
playground/src/containers/LifecycleScreen.js View File

23
   render() {
23
   render() {
24
     return (
24
     return (
25
       <View style={styles.root}>
25
       <View style={styles.root}>
26
+        <Text style={styles.h1}>Lifecycle Screen</Text>
26
         <Text style={styles.h1}>{this.state.text}</Text>
27
         <Text style={styles.h1}>{this.state.text}</Text>
27
         <Button title="Push to test onStop" onPress={this.onClickPush} />
28
         <Button title="Push to test onStop" onPress={this.onClickPush} />
29
+        <Text style={styles.footer}>ContainerId: {this.props.id}</Text>
28
       </View>
30
       </View>
29
     );
31
     );
30
   }
32
   }
31
 
33
 
32
   onClickPush() {
34
   onClickPush() {
33
     Navigation.on(this.props.id).push({
35
     Navigation.on(this.props.id).push({
34
-      name: 'navigation.playground.SimpleScreen'
36
+      name: 'navigation.playground.TextScreen'
35
     });
37
     });
36
   }
38
   }
37
 }
39
 }
48
     fontSize: 24,
50
     fontSize: 24,
49
     textAlign: 'center',
51
     textAlign: 'center',
50
     margin: 10
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 View File

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 View File

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 View File

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 View File

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 View File

30
       tabs: [
30
       tabs: [
31
         {
31
         {
32
           container: {
32
           container: {
33
-            name: 'navigation.playground.SimpleScreen',
33
+            name: 'navigation.playground.TextScreen',
34
             passProps: {
34
             passProps: {
35
               text: 'This is tab 1',
35
               text: 'This is tab 1',
36
               myFunction: () => 'Hello from a function!'
36
               myFunction: () => 'Hello from a function!'
39
         },
39
         },
40
         {
40
         {
41
           container: {
41
           container: {
42
-            name: 'navigation.playground.SimpleScreen',
42
+            name: 'navigation.playground.TextScreen',
43
             passProps: {
43
             passProps: {
44
               text: 'This is tab 2'
44
               text: 'This is tab 2'
45
             }
45
             }
54
       tabs: [
54
       tabs: [
55
         {
55
         {
56
           container: {
56
           container: {
57
-            name: 'navigation.playground.SimpleScreen',
57
+            name: 'navigation.playground.TextScreen',
58
             passProps: {
58
             passProps: {
59
               text: 'This is a side menu center screen'
59
               text: 'This is a side menu center screen'
60
             }
60
             }
62
         },
62
         },
63
         {
63
         {
64
           container: {
64
           container: {
65
-            name: 'navigation.playground.SimpleScreen'
65
+            name: 'navigation.playground.TextScreen'
66
           }
66
           }
67
         },
67
         },
68
         {
68
         {
69
           container: {
69
           container: {
70
-            name: 'navigation.playground.SimpleScreen'
70
+            name: 'navigation.playground.TextScreen'
71
           }
71
           }
72
         }
72
         }
73
       ],
73
       ],
74
       sideMenu: {
74
       sideMenu: {
75
         left: {
75
         left: {
76
           container: {
76
           container: {
77
-            name: 'navigation.playground.SimpleScreen',
77
+            name: 'navigation.playground.TextScreen',
78
             passProps: {
78
             passProps: {
79
               text: 'This is a side menu screen'
79
               text: 'This is a side menu screen'
80
             }
80
             }
82
         },
82
         },
83
         right: {
83
         right: {
84
           container: {
84
           container: {
85
-            name: 'navigation.playground.SimpleScreen'
85
+            name: 'navigation.playground.TextScreen'
86
           }
86
           }
87
         }
87
         }
88
       }
88
       }
91
 
91
 
92
   onClickPush() {
92
   onClickPush() {
93
     Navigation.on(this.props.id).push({
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
 
105
 
110
   onClickShowModal() {
106
   onClickShowModal() {
111
     Navigation.showModal({
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
   footer: {
131
   footer: {
139
     fontSize: 10,
132
     fontSize: 10,
140
     color: '#888',
133
     color: '#888',
141
-    marginTop: 80
134
+    marginTop: 10
142
   }
135
   }
143
 };
136
 };

+ 7
- 2
playground/src/containers/index.js View File

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