11import React , { useCallback , useMemo , useRef , useState } from 'react' ;
22import { View , StyleSheet } from 'react-native' ;
3- import { useHeaderHeight } from '@react-navigation/stack' ;
4- import Animated , {
5- interpolate ,
6- concat ,
7- Extrapolate ,
8- } from 'react-native-reanimated' ;
3+ import { concat } from 'react-native-reanimated' ;
94import { ReText , useValue } from 'react-native-redash' ;
10- import BottomSheet , { BottomSheetFlatList } from '@gorhom/bottom-sheet' ;
11- import Handle from '../../components/handle' ;
5+ import BottomSheet from '@gorhom/bottom-sheet' ;
126import Button from '../../components/button' ;
7+ import ContactList from '../../components/contactList' ;
8+ import { useSafeArea } from 'react-native-safe-area-context' ;
139
1410const BasicExample = ( ) => {
1511 // state
1612 const [ enabled , setEnabled ] = useState ( true ) ;
13+ const [ dynamicSnapPoint , setDynamicSnapPoint ] = useState ( 450 ) ;
1714
1815 // hooks
1916 const bottomSheetRef = useRef < BottomSheet > ( null ) ;
20- const headerHeight = useHeaderHeight ( ) ;
17+ const { top : topSafeArea } = useSafeArea ( ) ;
2118
2219 // variables
23- const snapPoints = useMemo ( ( ) => [ 150 , 300 , 450 ] , [ ] ) ;
20+ const snapPoints = useMemo ( ( ) => [ 150 , dynamicSnapPoint ] , [ dynamicSnapPoint ] ) ;
2421 const position = useValue < number > ( 0 ) ;
2522
2623 // styles
27- const shadowOverlayStyle = useMemo (
24+ const containerStyle = useMemo (
2825 ( ) => ( {
29- ...styles . shadowOverlay ,
30- opacity : interpolate ( position , {
31- inputRange : [ 300 , 450 ] ,
32- outputRange : [ 0 , 1 ] ,
33- extrapolate : Extrapolate . CLAMP ,
34- } ) ,
26+ ...styles . container ,
27+ paddingTop : topSafeArea ,
3528 } ) ,
36- // eslint-disable-next-line react-hooks/exhaustive-deps
37- [ ]
29+ [ topSafeArea ]
3830 ) ;
3931
4032 // callbacks
@@ -44,31 +36,20 @@ const BasicExample = () => {
4436 const handleSnapPress = useCallback ( index => {
4537 bottomSheetRef . current ?. snapTo ( index ) ;
4638 } , [ ] ) ;
47-
4839 const handleClosePress = useCallback ( ( ) => {
4940 bottomSheetRef . current ?. close ( ) ;
5041 } , [ ] ) ;
42+ const handleIncreaseDynamicSnapPoint = useCallback ( ( ) => {
43+ setDynamicSnapPoint ( state => state + 50 ) ;
44+ } , [ ] ) ;
5145
5246 // renders
53- // const renderHeader = useCallback(() => {
54- // return (
55- // <View style={styles.headerContainer}>
56- // <Text style={styles.title}>Basic Screen</Text>
57- // </View>
58- // );
59- // }, []);
60-
6147 return (
62- < View style = { styles . container } >
63- < Button
64- label = "Snap To 450"
65- style = { styles . buttonContainer }
66- onPress = { ( ) => handleSnapPress ( 2 ) }
67- />
48+ < View style = { containerStyle } >
6849 < Button
69- label = "Snap To 300 "
50+ label = "Increase Dynamic Snap Point "
7051 style = { styles . buttonContainer }
71- onPress = { ( ) => handleSnapPress ( 1 ) }
52+ onPress = { handleIncreaseDynamicSnapPoint }
7253 />
7354 < Button
7455 label = "Snap To 150"
@@ -87,92 +68,16 @@ const BasicExample = () => {
8768 onPress = { ( ) => setEnabled ( state => ! state ) }
8869 />
8970 < ReText text = { concat ( 'Position from bottom: ' , position ) } />
90- < Animated . View pointerEvents = "none" style = { shadowOverlayStyle } />
9171 < BottomSheet
9272 ref = { bottomSheetRef }
9373 enabled = { enabled }
9474 snapPoints = { snapPoints }
9575 initialSnapIndex = { 1 }
96- handleComponent = { Handle }
97- topInset = { headerHeight }
76+ topInset = { topSafeArea }
9877 animatedPosition = { position }
9978 onChange = { handleSheetChanges }
10079 >
101- { /* <View
102- style={{
103- position: 'absolute',
104- left: 0,
105- right: 0,
106- height: (25 * sheetHeight) / 100,
107- backgroundColor: 'rgba(0,0,0,0.25)',
108- }}
109- />
110- <View
111- style={{
112- position: 'absolute',
113- left: 0,
114- right: 0,
115- height: (50 * sheetHeight) / 100,
116- backgroundColor: 'rgba(0,0,0,0.50)',
117- }}
118- />
119- <View
120- style={{
121- position: 'absolute',
122- left: windowWidth / 2 - 25,
123- width: 50,
124- height: 10,
125- backgroundColor: 'red',
126- }}
127- />
128- <View
129- style={{
130- position: 'absolute',
131- left: windowWidth / 2 - 25,
132- bottom: 0,
133- width: 50,
134- height: 10,
135- backgroundColor: 'red',
136- }}
137- />
138- <View
139- style={{
140- position: 'absolute',
141- bottom: sheetHeight / 2 - 25,
142- width: 10,
143- height: 50,
144- backgroundColor: 'red',
145- }}
146- />
147-
148- <View
149- style={{
150- position: 'absolute',
151- bottom: sheetHeight / 2 - 25,
152- right: 0,
153- width: 10,
154- height: 50,
155- backgroundColor: 'red',
156- }}
157- /> */ }
158-
159- { /* <Button
160- label="Open"
161- style={styles.buttonContainer}
162- onPress={() => handleSnapPress(1)}
163- /> */ }
164- { /* <ContactList type="ScrollView" header={renderHeader} /> */ }
165- < View style = { { height : 100 , backgroundColor : 'blue' } } />
166- < BottomSheetFlatList
167- contentContainerStyle = { { flexGrow : 1 , backgroundColor : '#fff' } }
168- data = { [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] }
169- renderItem = { ( ) => (
170- < View
171- style = { { backgroundColor : 'red' , height : 100 , marginBottom : 20 } }
172- />
173- ) }
174- />
175- < View style = { { height : 100 , backgroundColor : 'green' } } />
80+ < ContactList type = "View" />
17681 </ BottomSheet >
17782 </ View >
17883 ) ;
0 commit comments