-
-
Notifications
You must be signed in to change notification settings - Fork 644
Expand file tree
/
Copy pathStackPresentation.tsx
More file actions
249 lines (228 loc) · 6.47 KB
/
StackPresentation.tsx
File metadata and controls
249 lines (228 loc) · 6.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import React from 'react';
import { ScrollView, StyleSheet, View, ImageBackground } from 'react-native';
import { ParamListBase, RouteProp } from '@react-navigation/native';
import {
createNativeStackNavigator,
NativeStackNavigationProp,
} from '@react-navigation/native-stack';
import { Button, Form, Choose, Alert, Dialog } from '../shared';
type StackParamList = {
Main: undefined;
Push: undefined;
Modal: undefined;
TransparentModal: undefined;
ContainedModal: undefined;
ContainedTransparentModal: undefined;
FullScreenModal: undefined;
FormSheet: { usesFormSheetPresentation?: boolean };
PageSheet: undefined;
};
interface MainScreenProps {
navigation: NativeStackNavigationProp<ParamListBase>;
}
const MainScreen = ({ navigation }: MainScreenProps): React.JSX.Element => {
return (
<ScrollView
style={{ ...styles.container, backgroundColor: 'thistle' }}
testID="stack-presentation-root-scroll-view">
<Button
title="push"
onPress={() => navigation.navigate('Push')}
testID="stack-presentation-push-button"
/>
<Button
title="modal"
onPress={() => navigation.navigate('Modal')}
testID="stack-presentation-modal-button"
/>
<Button
title="transparentModal"
onPress={() => navigation.navigate('TransparentModal')}
testID="stack-presentation-transparent-modal-button"
/>
<Button
title="containedModal"
onPress={() => navigation.navigate('ContainedModal')}
testID="stack-presentation-contained-modal-button"
/>
<Button
title="containedTransparentModal"
onPress={() => navigation.navigate('ContainedTransparentModal')}
testID="stack-presentation-contained-transparent-modal-button"
/>
<Button
title="fullScreenModal"
onPress={() => navigation.navigate('FullScreenModal')}
testID="stack-presentation-full-screen-modal-button"
/>
<Button
title="formSheet"
onPress={() => navigation.navigate('FormSheet')}
testID="stack-presentation-form-sheet-button"
/>
<Button
title="pageSheet"
onPress={() => navigation.navigate('PageSheet')}
testID="stack-presentation-page-sheet-button"
/>
<Button
testID="stack-presentation-go-back-button"
onPress={() => navigation.pop()}
title="🔙 Back to Examples"
/>
</ScrollView>
);
};
interface PushScreenProps {
navigation: NativeStackNavigationProp<StackParamList, 'Push'>;
}
const PushScreen = ({ navigation }: PushScreenProps) => (
<View style={styles.container}>
<FormScreenContent navigation={navigation} />
</View>
)
interface FormScreenProps {
navigation: NativeStackNavigationProp<StackParamList, 'FormSheet'>;
route: RouteProp<StackParamList, 'FormSheet'>;
}
const FormScreenContent = ({ navigation }: { navigation: NativeStackNavigationProp<StackParamList, 'Push' | 'FormSheet'> }) => (
<>
<Form />
<Button
testID="stack-presentation-form-screen-go-back-button"
title="Go back"
onPress={() => navigation.goBack()}
/>
</>
);
const FormScreen = ({ navigation, route }: FormScreenProps): React.JSX.Element => {
const isFormSheet = route.params?.usesFormSheetPresentation ?? false;
return (
<View style={!isFormSheet ? styles.container : null}>
<FormScreenContent navigation={navigation} />
</View>
);
}
interface ModalScreenProps {
navigation: NativeStackNavigationProp<ParamListBase>;
}
const ModalScreen = ({ navigation }: ModalScreenProps): React.JSX.Element => (
<View style={styles.container}>
<Choose />
<Button
testID="stack-presentation-modal-screen-go-back-button"
title="Go back"
onPress={() => navigation.goBack()}
/>
</View>
);
interface PageSheetScreenProps {
navigation: NativeStackNavigationProp<ParamListBase>;
}
const PageSheetScreen = ({ navigation }: PageSheetScreenProps): React.JSX.Element => (
<View style={styles.container}>
<Choose />
<Button
testID="stack-presentation-page-sheet-screen-go-back-button"
title="Go back"
onPress={() => navigation.goBack()}
/>
</View>
);
interface FullScreenModalProps {
navigation: NativeStackNavigationProp<ParamListBase>;
}
const FullScreenModalScreen = ({
navigation,
}: FullScreenModalProps): React.JSX.Element => (
<View style={{ flex: 1 }}>
<ImageBackground
style={styles.image}
source={require('../assets/trees.jpg')}>
<Button
testID="stack-presentation-fullscreen-modal-go-back-button"
title="Go back"
onPress={() => navigation.goBack()}
/>
</ImageBackground>
</View>
);
const Stack = createNativeStackNavigator<StackParamList>();
const App = (): React.JSX.Element => (
<Stack.Navigator
screenOptions={{
headerBackVisible: true,
}}>
<Stack.Screen
name="Main"
component={MainScreen}
options={{ title: 'Stack Presentation' }}
/>
<Stack.Screen
name="Push"
component={PushScreen}
options={{ presentation: 'card' }}
/>
<Stack.Screen
name="Modal"
component={ModalScreen}
options={{ presentation: 'modal' }}
/>
<Stack.Screen
name="TransparentModal"
component={Alert}
options={{
presentation: 'transparentModal',
headerShown: false,
animation: 'slide_from_bottom',
}}
/>
<Stack.Screen
name="ContainedModal"
component={ModalScreen}
options={{ presentation: 'containedModal' }}
/>
<Stack.Screen
name="ContainedTransparentModal"
component={Dialog}
options={{
presentation: 'containedTransparentModal',
headerShown: false,
animation: 'fade',
}}
/>
<Stack.Screen
name="FullScreenModal"
component={FullScreenModalScreen}
options={{
presentation: 'fullScreenModal',
headerShown: false,
}}
/>
<Stack.Screen
name="FormSheet"
component={FormScreen}
options={{ presentation: 'formSheet', sheetAllowedDetents: [0.5, 0.85] }}
initialParams={{
usesFormSheetPresentation: true
}}
/>
<Stack.Screen
name="PageSheet"
component={PageSheetScreen}
options={{ presentation: 'pageSheet' }}
/>
</Stack.Navigator>
);
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 10,
},
image: {
flex: 1,
resizeMode: 'cover',
justifyContent: 'center',
},
});
export default App;