-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBottomSheetComponent.js
83 lines (74 loc) · 2.24 KB
/
BottomSheetComponent.js
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
/**
* BottomSheetComponent.js
*
* A 3-step Bottom Sheet.
* 1. The sheet is presented with a CTA prompting the user to interact
* 2. The sheet is partially expanded with a text input focused
* 3. The sheet is fully expanded with a text input focused</Text>
*
*/
import React, { useMemo, useRef } from "react";
import { StyleSheet } from "react-native";
import BottomSheet, {
BottomSheetView,
BottomSheetTextInput,
useBottomSheetDynamicSnapPoints,
} from "@gorhom/bottom-sheet";
const BottomSheetComponent = ({}) => {
// ref
const bottomSheetRef = useRef(null);
/**
* Snap Point Demo instructions:
*
* 1. When a snap point is set higher than the CONTENT_HEIGHT, the sheet will expand to the maximum snap point *every time* the Text Input is focused
*
* 2. When the snap points do not include anything higher than the CONTENT_HEIGHT, the sheet will expand to the size of the content, but not allow the user to *manually* expand the sheet further
*/
// 1.
const initialSnapPoints = useMemo(() => [100, "CONTENT_HEIGHT", "90%"], []);
// 2.
// const initialSnapPoints = useMemo(() => [100, "CONTENT_HEIGHT"], []);
// dynamic height
const {
animatedHandleHeight,
animatedSnapPoints,
animatedContentHeight,
handleContentLayout,
} = useBottomSheetDynamicSnapPoints(initialSnapPoints);
// renders
return (
<BottomSheet
ref={bottomSheetRef}
index={0}
snapPoints={animatedSnapPoints}
handleHeight={animatedHandleHeight}
contentHeight={animatedContentHeight}
android_keyboardInputMode="adjustResize"
keyboardBehavior="extend"
keyboardBlurBehavior="restore"
>
<BottomSheetView style={styles.container} onLayout={handleContentLayout}>
<BottomSheetTextInput
style={styles.textInput}
placeholder="Focus this input to partially expand the sheet."
/>
</BottomSheetView>
</BottomSheet>
);
};
const styles = StyleSheet.create({
container: {
height: 200,
padding: 24,
backgroundColor: "grey",
justifyContent: "space-between",
},
textInput: {
width: "100%",
height: 40,
paddingHorizontal: 16,
backgroundColor: "white",
borderRadius: 8,
},
});
export default BottomSheetComponent;