Sfoglia il codice sorgente

Add ScrollView inside Overlay example

Complex layouts were added to relevant parts in the playground app.
Guy Carmeli 5 anni fa
parent
commit
24a8c53a2c

+ 0
- 197
playground/src/screens/ComplexLayout.js Vedi File

@@ -1,197 +0,0 @@
1
-const React = require('react');
2
-const { Component } = require('react');
3
-
4
-const { View, Text, Button } = require('react-native');
5
-
6
-const { Navigation } = require('react-native-navigation');
7
-const testIDs = require('../testIDs');
8
-
9
-class ComplexLayout extends Component {
10
-  render() {
11
-    return (
12
-      <View style={styles.root}>
13
-        <Text style={styles.h1} testID={testIDs.CENTERED_TEXT_HEADER}>{this.props.text || 'Complex layout screen'}</Text>
14
-        <Button title={'External component in stack'} testID={testIDs.EXTERNAL_COMPONENT_IN_STACK} onPress={this.onExternalComponentInStackPressed} />
15
-        <Button title={'External component in deep stack'} testID={testIDs.EXTERNAL_COMPONENT_IN_DEEP_STACK} onPress={this.onExternalComponentInDeepStackPressed} />
16
-        <Button title={'SideMenu layout inside a bottomTab'} testID={testIDs.SIDE_MENU_LAYOUT_INSIDE_BOTTOM_TAB} onPress={this.onSideMenuLayoutInsideBottomTabPressed} />
17
-        <Button title='Show touch through overlay with scroll' testID={testIDs.SHOW_TOUCH_THROUGH_OVERLAY_SCROLLER} onPress={() => this.onClickShowOverlayWithScroll(true)} />
18
-      </View>
19
-    );
20
-  }
21
-
22
-  onExternalComponentInStackPressed = () => {
23
-    Navigation.showModal({
24
-      stack: {
25
-        children: [{
26
-          externalComponent: {
27
-            name: 'RNNCustomComponent',
28
-            passProps: {
29
-              text: 'External component in stack'
30
-            }
31
-          }
32
-        }]
33
-      }
34
-    });
35
-  }
36
-
37
-  onExternalComponentInDeepStackPressed = () => {
38
-    Navigation.showModal({
39
-      stack: {
40
-        children: [{
41
-          component: {
42
-            name: 'navigation.playground.TextScreen'
43
-          }
44
-        },
45
-        {
46
-          externalComponent: {
47
-            name: 'RNNCustomComponent',
48
-            passProps: {
49
-              text: 'External component in deep stack'
50
-            }
51
-          }
52
-        }]
53
-      }
54
-    });
55
-  }
56
-
57
-  onSideMenuLayoutInsideBottomTabPressed = () => {
58
-    Navigation.dismissAllModals();
59
-    Navigation.setRoot({
60
-      root: {
61
-        bottomTabs: {
62
-          children: [
63
-            {
64
-              stack: {
65
-                children: [
66
-                  {
67
-                    component: {
68
-                      name: 'navigation.playground.TextScreen',
69
-                      options: {
70
-                        topBar: {
71
-                          animate: false
72
-                        }
73
-                      }
74
-                    }
75
-                  }
76
-                ],
77
-                options: {
78
-                  bottomTab: {
79
-                    text: 'Stack',
80
-                    icon: require('../images/one.png')
81
-                  }
82
-                }
83
-              }
84
-            },
85
-            {
86
-              sideMenu: {
87
-                left: {
88
-                  component: {
89
-                    name: 'navigation.playground.SideMenuScreen',
90
-                    options: {
91
-                      topBar: {
92
-                        animate: false
93
-                      }
94
-                    },
95
-                    passProps: {
96
-                      side: 'left'
97
-                    }
98
-                  }
99
-                },
100
-                center: {
101
-                  stack: {
102
-                    children: [
103
-                      {
104
-                        component: {
105
-                          name: 'complexLayout.bottomTabThatOpensSideMenu'
106
-                        }
107
-                      }
108
-                    ]
109
-                  }
110
-                },
111
-                options: {
112
-                  bottomTab: {
113
-                    text: 'SideMenu',
114
-                    icon: require('../images/two.png'),
115
-                    testID: testIDs.SECOND_TAB_BAR_BUTTON
116
-                  }
117
-                }
118
-              }
119
-            },
120
-            {
121
-              sideMenu: {
122
-                left: {
123
-                  component: {
124
-                    name: 'navigation.playground.SideMenuScreen',
125
-                    passProps: {
126
-                      side: 'left'
127
-                    }
128
-                  }
129
-                },
130
-                center: {
131
-                  stack: {
132
-                    children: [
133
-                      {
134
-                        component: {
135
-                          name: 'navigation.playground.FlatListScreen',
136
-                        }
137
-                      }
138
-                    ]
139
-                  }
140
-                },
141
-                options: {
142
-                  bottomTab: {
143
-                    text: 'FlatList',
144
-                    icon: require('../images/three.png'),
145
-                    testID: testIDs.THIRD_TAB_BAR_BUTTON,
146
-                  }
147
-                }
148
-              }
149
-            }
150
-           ]
151
-        }
152
-      }
153
-    });
154
-  }
155
-
156
-  onClickShowOverlayWithScroll = async (interceptTouchOutside) => {
157
-    await Navigation.showOverlay({
158
-      component: {
159
-        name: 'navigation.playground.CustomDialogWithScroll',
160
-        options: {
161
-          layout: {
162
-            componentBackgroundColor: 'transparent'
163
-          },
164
-          overlay: {
165
-            interceptTouchOutside
166
-          }
167
-        }
168
-      }
169
-    });
170
-  }
171
-}
172
-
173
-module.exports = ComplexLayout;
174
-
175
-const styles = {
176
-  root: {
177
-    flexGrow: 1,
178
-    justifyContent: 'center',
179
-    alignItems: 'center',
180
-    backgroundColor: '#f5fcff'
181
-  },
182
-  h1: {
183
-    fontSize: 24,
184
-    textAlign: 'center',
185
-    margin: 10
186
-  },
187
-  h2: {
188
-    fontSize: 12,
189
-    textAlign: 'center',
190
-    margin: 10
191
-  },
192
-  footer: {
193
-    fontSize: 10,
194
-    color: '#888',
195
-    marginTop: 10
196
-  }
197
-};

+ 4
- 14
playground/src/screens/OverlayScreen.js Vedi File

@@ -28,6 +28,7 @@ class OverlayScreen extends React.Component {
28 28
         <Button label='Alert' testID={ALERT_BUTTON} onPress={() => alert('Alert displayed')} />
29 29
         <Button label='Show overlay' testID={SHOW_OVERLAY_BTN} onPress={() => this.showOverlay(true)} />
30 30
         <Button label='Show touch through overlay' testID={SHOW_TOUCH_THROUGH_OVERLAY_BTN} onPress={() => this.showOverlay(false)} />
31
+        <Button label='Show overlay with ScrollView' onPress={this.showOverlayWithScrollView} />
31 32
         <Button label='Set Root' testID={SET_ROOT_BTN} onPress={this.setRoot} />
32 33
       </Root>
33 34
     );
@@ -40,20 +41,9 @@ class OverlayScreen extends React.Component {
40 41
 
41 42
   setRoot = () => Navigation.setRoot({ root: component(Screens.Pushed) })
42 43
 
43
-  // await Navigation.showOverlay({
44
-  //   component: {
45
-  //     name: 'navigation.playground.CustomDialog',
46
-  //     options: {
47
-  //       layout: {
48
-  //         componentBackgroundColor: 'transparent'
49
-  //       },
50
-  //       overlay: {
51
-  //         interceptTouchOutside: false
52
-  //       }
53
-  //     }
54
-  //   }
55
-  // });
56
-  // });
44
+  showOverlayWithScrollView = () => Navigation.showOverlay(Screens.ScrollViewOverlay, {
45
+    layout: { componentBackgroundColor: 'transparent' }
46
+  });
57 47
 }
58 48
 
59 49
 module.exports = OverlayScreen;

+ 1
- 0
playground/src/screens/Screens.js Vedi File

@@ -7,6 +7,7 @@ module.exports = {
7 7
   Modal: 'Modal',
8 8
   Overlay: 'Overlay',
9 9
   OverlayAlert: 'OverlayAlert',
10
+  ScrollViewOverlay: 'ScrollViewOverlay',
10 11
   Lifecycle: 'Lifecycle',
11 12
   BackHandler: 'BackHandler',
12 13
   BottomTabs: 'BottomTabs',

+ 68
- 0
playground/src/screens/ScrollViewOverlay.js Vedi File

@@ -0,0 +1,68 @@
1
+const React = require('react');
2
+const { PureComponent } = require('react');
3
+const { View, Text, ScrollView, StyleSheet } = require('react-native');
4
+
5
+const colors = [
6
+  '#3182C8',
7
+  '#00AAAF',
8
+  '#00A65F',
9
+  '#E2902B',
10
+  '#D9644A',
11
+  '#CF262F',
12
+  '#8B1079',
13
+  '#48217B'
14
+];
15
+
16
+class ScrollViewOverlay extends PureComponent {
17
+
18
+  render() {
19
+    return (
20
+      <View style={styles.root}>
21
+        <View style={{ height: 200, width: '80%', alignSelf: 'center', flexDirection: 'row' }}>
22
+          <ScrollView style={styles.scrollView} contentContainerStyle={styles.content}>
23
+            {colors.map(this.renderRow)}
24
+          </ScrollView>
25
+        </View>
26
+      </View>
27
+    );
28
+  }
29
+
30
+  renderRow = (color) => <Text key={color} style={[styles.row, { backgroundColor: color }]}>{color}</Text>
31
+}
32
+
33
+const styles = StyleSheet.create({
34
+  scrollView: {
35
+    backgroundColor: 'blue'
36
+  },
37
+  root: {
38
+    flex: 1,
39
+    flexDirection: 'column',
40
+    justifyContent: 'flex-end'
41
+  },
42
+  row: {
43
+    height: 40,
44
+    textAlign: 'center',
45
+    textAlignVertical: 'center',
46
+    color: 'white',
47
+  },
48
+  content: {
49
+    backgroundColor: 'blue'
50
+  },
51
+  h1: {
52
+    fontSize: 24,
53
+    textAlign: 'center',
54
+    margin: 10
55
+  },
56
+  h2: {
57
+    fontSize: 12,
58
+    textAlign: 'center',
59
+    margin: 10
60
+  },
61
+  footer: {
62
+    fontSize: 10,
63
+    color: '#888',
64
+    marginTop: 10
65
+  }
66
+});
67
+
68
+module.exports = ScrollViewOverlay;

+ 1
- 0
playground/src/screens/index.js Vedi File

@@ -25,6 +25,7 @@ function registerScreens() {
25 25
   Navigation.registerComponent(Screens.Lifecycle, () => require('./LifecycleScreen'));
26 26
   Navigation.registerComponent(Screens.Overlay, () => require('./OverlayScreen'));
27 27
   Navigation.registerComponent(Screens.OverlayAlert, () => require('./OverlayAlert'));
28
+  Navigation.registerComponent(Screens.ScrollViewOverlay, () => require('./ScrollViewOverlay'));
28 29
   Navigation.registerComponent(Screens.RoundButton, () => require('./RoundedButton'));
29 30
   Navigation.registerComponent(Screens.ReactTitleView, () => require('./CustomTopBar'));
30 31
   Navigation.registerComponent(Screens.EventsScreen, () => require('./StaticEventsScreen'));