-
-
Notifications
You must be signed in to change notification settings - Fork 949
Expand file tree
/
Copy pathDraggableViewExample.tsx
More file actions
74 lines (68 loc) · 1.95 KB
/
DraggableViewExample.tsx
File metadata and controls
74 lines (68 loc) · 1.95 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
import React, { useCallback, useMemo, useRef } from 'react';
import { View, StyleSheet, Text } from 'react-native';
import BottomSheet, { BottomSheetDraggableView, BottomSheetView } from '@gorhom/bottom-sheet';
import { Button } from '../../components/button';
const DraggableViewExample = () => {
// hooks
const bottomSheetRef = useRef<BottomSheet>(null);
// variables
const snapPoints = useMemo(() => ['25%', '50%'], []);
// callbacks
const handleExpandPress = useCallback(() => {
bottomSheetRef.current?.expand();
}, []);
const handleCollapsePress = useCallback(() => {
bottomSheetRef.current?.collapse();
}, []);
const handleClosePress = useCallback(() => {
bottomSheetRef.current?.close();
}, []);
// renders
return (
<View style={styles.container}>
<Button label="Expand" onPress={handleExpandPress} />
<Button label="Collapse" onPress={handleCollapsePress} />
<Button label="Close" onPress={handleClosePress} />
<BottomSheet
ref={bottomSheetRef}
snapPoints={snapPoints}
keyboardBehavior="interactive"
keyboardBlurBehavior="restore"
enablePanDownToClose={true}
enableContentPanningGesture={false}
>
<BottomSheetView style={styles.row}>
<BottomSheetDraggableView style={styles.leftView}>
<Text>Draggable</Text>
</BottomSheetDraggableView>
<View style={styles.rightView}>
<Text>Not draggable</Text>
</View>
</BottomSheetView>
</BottomSheet>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 24,
},
row: {
flexDirection: 'row',
height: '100%',
},
leftView: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#ccc',
},
rightView: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#ddd',
},
});
export default DraggableViewExample;