-
Notifications
You must be signed in to change notification settings - Fork 19
/
SimpleExample.tsx
131 lines (124 loc) · 3.12 KB
/
SimpleExample.tsx
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
import {
BottomSheetBackdrop,
BottomSheetBackdropProps,
} from '@gorhom/bottom-sheet';
import { NavigationContainer } from '@react-navigation/native';
import {
BottomSheetScreenProps,
createBottomSheetNavigator,
} from '@th3rdwave/react-navigation-bottom-sheet';
import * as React from 'react';
import { Button, StyleSheet, Text, View } from 'react-native';
type BottomSheetParams = {
Home: undefined;
Sheet: { id: number };
BigSheet: { id: number };
};
const BottomSheet = createBottomSheetNavigator<BottomSheetParams>();
function HomeScreen({
navigation,
}: BottomSheetScreenProps<BottomSheetParams, 'Home'>) {
return (
<View style={styles.container}>
<Text>Home Screen</Text>
<View style={styles.spacer} />
<Button
title="Open sheet"
onPress={() => {
navigation.navigate('Sheet', { id: 1 });
}}
/>
<View style={styles.spacer} />
<Button
title="Open a big sheet"
onPress={() => {
navigation.navigate('BigSheet', { id: 1 });
}}
/>
</View>
);
}
function SheetScreen({
route,
navigation,
}: BottomSheetScreenProps<BottomSheetParams, 'Sheet'>) {
return (
<View style={[styles.container, styles.content]}>
<Text>Sheet Screen {route.params.id}</Text>
<View style={styles.spacer} />
<Button
title="Open new sheet"
onPress={() => {
navigation.navigate('Sheet', { id: route.params.id + 1 });
}}
/>
<View style={styles.spacer} />
<Button
title="Open new big sheet"
onPress={() => {
navigation.navigate('BigSheet', { id: route.params.id + 1 });
}}
/>
<View style={styles.spacer} />
<Button
title="Close this sheet"
onPress={() => {
navigation.goBack();
}}
/>
{route.name === ('BigSheet' as unknown) && (
<>
<View style={styles.spacer} />
<Button
title="Snap to top"
onPress={() => {
navigation.snapTo(1);
}}
/>
</>
)}
</View>
);
}
const renderBackdrop = (props: BottomSheetBackdropProps) => (
<BottomSheetBackdrop {...props} appearsOnIndex={0} disappearsOnIndex={-1} />
);
export function SimpleExample() {
return (
<NavigationContainer>
<BottomSheet.Navigator
screenOptions={{
backdropComponent: renderBackdrop,
}}
>
<BottomSheet.Screen name="Home" component={HomeScreen} />
<BottomSheet.Screen
name="Sheet"
component={SheetScreen}
getId={({ params }) => `sheet-${params.id}`}
/>
<BottomSheet.Screen
name="BigSheet"
component={SheetScreen}
options={{
snapPoints: ['50%', '80%'],
}}
getId={({ params }) => `sheet-${params.id}`}
/>
</BottomSheet.Navigator>
</NavigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
content: {
marginVertical: 20,
},
spacer: {
margin: 5,
},
});