|
| 1 | +import { |
| 2 | + BottomSheetBackdrop, |
| 3 | + BottomSheetBackdropProps, |
| 4 | +} from '@gorhom/bottom-sheet'; |
| 5 | +import { NavigationContainer } from '@react-navigation/native'; |
| 6 | +import { |
| 7 | + BottomSheetScreenProps, |
| 8 | + createBottomSheetNavigator, |
| 9 | +} from '@th3rdwave/react-navigation-bottom-sheet'; |
| 10 | +import * as React from 'react'; |
| 11 | +import { Button, StyleSheet, Text, View } from 'react-native'; |
| 12 | + |
| 13 | +type BottomSheetParams = { |
| 14 | + Home: undefined; |
| 15 | + Sheet: { id: number }; |
| 16 | +}; |
| 17 | + |
| 18 | +const BottomSheet = createBottomSheetNavigator<BottomSheetParams>(); |
| 19 | + |
| 20 | +function HomeScreen({ |
| 21 | + navigation, |
| 22 | +}: BottomSheetScreenProps<BottomSheetParams, 'Home'>) { |
| 23 | + return ( |
| 24 | + <View style={styles.container}> |
| 25 | + <Text>Home Screen</Text> |
| 26 | + <Button |
| 27 | + title="Open sheet" |
| 28 | + onPress={() => { |
| 29 | + navigation.navigate('Sheet', { id: 1 }); |
| 30 | + }} |
| 31 | + /> |
| 32 | + </View> |
| 33 | + ); |
| 34 | +} |
| 35 | + |
| 36 | +function SheetScreen({ |
| 37 | + route, |
| 38 | + navigation, |
| 39 | +}: BottomSheetScreenProps<BottomSheetParams, 'Sheet'>) { |
| 40 | + return ( |
| 41 | + <View style={styles.container}> |
| 42 | + <Text>Sheet Screen {route.params.id}</Text> |
| 43 | + <Button |
| 44 | + title="Open new sheet" |
| 45 | + onPress={() => { |
| 46 | + navigation.navigate('Sheet', { id: route.params.id + 1 }); |
| 47 | + }} |
| 48 | + /> |
| 49 | + <Button |
| 50 | + title="Close sheet" |
| 51 | + onPress={() => { |
| 52 | + navigation.goBack(); |
| 53 | + }} |
| 54 | + /> |
| 55 | + <Button |
| 56 | + title="Snap to top" |
| 57 | + onPress={() => { |
| 58 | + navigation.snapTo(1); |
| 59 | + }} |
| 60 | + /> |
| 61 | + </View> |
| 62 | + ); |
| 63 | +} |
| 64 | + |
| 65 | +export function SimpleExample() { |
| 66 | + const renderBackdrop = React.useCallback( |
| 67 | + (props: BottomSheetBackdropProps) => ( |
| 68 | + <BottomSheetBackdrop |
| 69 | + {...props} |
| 70 | + appearsOnIndex={0} |
| 71 | + disappearsOnIndex={-1} |
| 72 | + /> |
| 73 | + ), |
| 74 | + [], |
| 75 | + ); |
| 76 | + return ( |
| 77 | + <NavigationContainer> |
| 78 | + <BottomSheet.Navigator |
| 79 | + screenOptions={{ |
| 80 | + snapPoints: ['70%', '90%'], |
| 81 | + backdropComponent: renderBackdrop, |
| 82 | + }} |
| 83 | + > |
| 84 | + <BottomSheet.Screen name="Home" component={HomeScreen} /> |
| 85 | + <BottomSheet.Screen |
| 86 | + name="Sheet" |
| 87 | + component={SheetScreen} |
| 88 | + getId={({ params }) => `sheet-${params.id}`} |
| 89 | + /> |
| 90 | + </BottomSheet.Navigator> |
| 91 | + </NavigationContainer> |
| 92 | + ); |
| 93 | +} |
| 94 | + |
| 95 | +const styles = StyleSheet.create({ |
| 96 | + container: { flex: 1, alignItems: 'center', justifyContent: 'center' }, |
| 97 | +}); |
0 commit comments