|
5 | 5 | * @format |
6 | 6 | */ |
7 | 7 |
|
8 | | -import React from 'react'; |
9 | | -import type {PropsWithChildren} from 'react'; |
10 | | -import { |
11 | | - ScrollView, |
12 | | - StatusBar, |
13 | | - StyleSheet, |
14 | | - Text, |
15 | | - useColorScheme, |
16 | | - View, |
17 | | -} from 'react-native'; |
18 | | - |
19 | | -import { |
20 | | - Colors, |
21 | | - DebugInstructions, |
22 | | - Header, |
23 | | - LearnMoreLinks, |
24 | | - ReloadInstructions, |
25 | | -} from 'react-native/Libraries/NewAppScreen'; |
26 | | - |
27 | | -type SectionProps = PropsWithChildren<{ |
28 | | - title: string; |
29 | | -}>; |
30 | | - |
31 | | -function Section({children, title}: SectionProps): React.JSX.Element { |
32 | | - const isDarkMode = useColorScheme() === 'dark'; |
33 | | - return ( |
34 | | - <View style={styles.sectionContainer}> |
35 | | - <Text |
36 | | - style={[ |
37 | | - styles.sectionTitle, |
38 | | - { |
39 | | - color: isDarkMode ? Colors.white : Colors.black, |
40 | | - }, |
41 | | - ]}> |
42 | | - {title} |
43 | | - </Text> |
44 | | - <Text |
45 | | - style={[ |
46 | | - styles.sectionDescription, |
47 | | - { |
48 | | - color: isDarkMode ? Colors.light : Colors.dark, |
49 | | - }, |
50 | | - ]}> |
51 | | - {children} |
52 | | - </Text> |
53 | | - </View> |
54 | | - ); |
55 | | -} |
| 8 | +import React, {useRef} from 'react'; |
| 9 | +import {Text, Pressable, StyleSheet, Button} from 'react-native'; |
| 10 | +import {GestureHandlerRootView} from 'react-native-gesture-handler'; |
| 11 | +import BottomSheet, {BottomSheetView} from '@gorhom/bottom-sheet'; |
56 | 12 |
|
57 | 13 | function App(): React.JSX.Element { |
58 | | - const isDarkMode = useColorScheme() === 'dark'; |
| 14 | + const [count, setCount] = React.useState(0); |
| 15 | + const [pressCount, setPressCount] = React.useState(0); |
59 | 16 |
|
60 | | - const backgroundStyle = { |
61 | | - backgroundColor: isDarkMode ? Colors.darker : Colors.lighter, |
62 | | - }; |
| 17 | + // ref |
| 18 | + const bottomSheetRef = useRef<BottomSheet>(null); |
63 | 19 |
|
64 | | - /* |
65 | | - * To keep the template simple and small we're adding padding to prevent view |
66 | | - * from rendering under the System UI. |
67 | | - * For bigger apps the reccomendation is to use `react-native-safe-area-context`: |
68 | | - * https://github.com/AppAndFlow/react-native-safe-area-context |
69 | | - * |
70 | | - * You can read more about it here: |
71 | | - * https://github.com/react-native-community/discussions-and-proposals/discussions/827 |
72 | | - */ |
73 | | - const safePadding = '5%'; |
| 20 | + const handleCloseButton = () => { |
| 21 | + bottomSheetRef.current?.close(); |
| 22 | + }; |
74 | 23 |
|
75 | 24 | return ( |
76 | | - <View style={backgroundStyle}> |
77 | | - <StatusBar |
78 | | - barStyle={isDarkMode ? 'light-content' : 'dark-content'} |
79 | | - backgroundColor={backgroundStyle.backgroundColor} |
| 25 | + <GestureHandlerRootView style={styles.container}> |
| 26 | + <Pressable |
| 27 | + style={{padding: 16}} |
| 28 | + onPointerDown={() => setCount(n => n + 1)} |
| 29 | + onPressIn={() => setPressCount(n => n + 1)}> |
| 30 | + <Text>Press me</Text> |
| 31 | + </Pressable> |
| 32 | + <Text style={{marginBottom: 16}}> |
| 33 | + pointer: {count} -- press: {pressCount} |
| 34 | + </Text> |
| 35 | + |
| 36 | + <Button |
| 37 | + title="Open Sheet" |
| 38 | + onPress={() => bottomSheetRef.current?.expand()} |
80 | 39 | /> |
81 | | - <ScrollView |
82 | | - style={backgroundStyle}> |
83 | | - <View style={{paddingRight: safePadding}}> |
84 | | - <Header/> |
85 | | - </View> |
86 | | - <View |
87 | | - style={{ |
88 | | - backgroundColor: isDarkMode ? Colors.black : Colors.white, |
89 | | - paddingHorizontal: safePadding, |
90 | | - paddingBottom: safePadding, |
91 | | - }}> |
92 | | - <Section title="Step One"> |
93 | | - Edit <Text style={styles.highlight}>App.tsx</Text> to change this |
94 | | - screen and then come back to see your edits. |
95 | | - </Section> |
96 | | - <Section title="See Your Changes"> |
97 | | - <ReloadInstructions /> |
98 | | - </Section> |
99 | | - <Section title="Debug"> |
100 | | - <DebugInstructions /> |
101 | | - </Section> |
102 | | - <Section title="Learn More"> |
103 | | - Read the docs to discover what to do next: |
104 | | - </Section> |
105 | | - <LearnMoreLinks /> |
106 | | - </View> |
107 | | - </ScrollView> |
108 | | - </View> |
| 40 | + |
| 41 | + <BottomSheet ref={bottomSheetRef} enablePanDownToClose> |
| 42 | + <Button title="close" onPress={handleCloseButton} /> |
| 43 | + <BottomSheetView style={styles.contentContainer}> |
| 44 | + <Text>Awesome 🎉</Text> |
| 45 | + </BottomSheetView> |
| 46 | + </BottomSheet> |
| 47 | + </GestureHandlerRootView> |
109 | 48 | ); |
110 | 49 | } |
111 | 50 |
|
112 | 51 | const styles = StyleSheet.create({ |
113 | | - sectionContainer: { |
114 | | - marginTop: 32, |
115 | | - paddingHorizontal: 24, |
116 | | - }, |
117 | | - sectionTitle: { |
118 | | - fontSize: 24, |
119 | | - fontWeight: '600', |
120 | | - }, |
121 | | - sectionDescription: { |
122 | | - marginTop: 8, |
123 | | - fontSize: 18, |
124 | | - fontWeight: '400', |
| 52 | + container: { |
| 53 | + flex: 1, |
125 | 54 | }, |
126 | | - highlight: { |
127 | | - fontWeight: '700', |
| 55 | + contentContainer: { |
| 56 | + flex: 1, |
| 57 | + height: 400, |
| 58 | + padding: 36, |
| 59 | + alignItems: 'center', |
128 | 60 | }, |
129 | 61 | }); |
130 | 62 |
|
|
0 commit comments