1
1
import React , { useRef } from 'react'
2
- import {
3
- Text ,
4
- TouchableOpacity ,
5
- View ,
6
- type TouchableOpacityProps ,
7
- type ViewStyle ,
8
- type TextStyle ,
9
- type ViewProps ,
10
- ScrollView ,
11
- FlatList ,
12
- type ColorValue ,
13
- TextInput ,
14
- } from 'react-native'
2
+ import { View , type ViewStyle } from 'react-native'
15
3
import { TrueSheet } from '@lodev09/react-native-true-sheet'
16
4
17
- import { random , times } from './utils'
18
-
19
- const SPACING = 16
20
- const INPUT_HEIGHT = SPACING * 3
21
- const FOOTER_HEIGHT = SPACING * 6
22
- const BORDER_RADIUS = 4
23
- const GRABBER_COLOR = 'rgba(121, 135, 160, 0.5)'
24
-
25
- const DARK = '#282e37'
26
- const GRAY = '#b2bac8'
27
- const DARK_GRAY = '#333b48'
28
- const LIGHT_GRAY = '#ebedf1'
29
- const BLUE = '#3784d7'
30
- const DARK_BLUE = '#1f64ae'
31
-
32
- const randomTexts : string [ ] = [
33
- `Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
34
- tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.` ,
35
- `Duis aute irure dolor in reprehenderit in voluptate velit esse
36
- cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat.` ,
37
- ]
38
-
39
- interface ButtonProps extends TouchableOpacityProps {
40
- text : string
41
- }
42
-
43
- interface DemoContentProps extends ViewProps {
44
- radius ?: number
45
- color ?: ColorValue
46
- text ?: string
47
- }
5
+ import { BasicSheet , FlatListSheet , PromptSheet , ScrollViewSheet } from './sheets'
6
+ import { Button } from './components'
7
+ import { BLUE } from './utils'
48
8
49
9
export default function App ( ) {
50
- const sheet1 = useRef < TrueSheet > ( null )
51
- const sheetPrompt = useRef < TrueSheet > ( null )
52
- const sheetScrollView = useRef < TrueSheet > ( null )
53
- const sheetFlatList = useRef < TrueSheet > ( null )
10
+ const basicSheet = useRef < TrueSheet > ( null )
11
+ const promptSheet = useRef < TrueSheet > ( null )
12
+ const scrollViewSheet = useRef < TrueSheet > ( null )
13
+ const flatListSheet = useRef < TrueSheet > ( null )
54
14
55
- const scrollViewRef = useRef < ScrollView > ( null )
56
- const flatListRef = useRef < FlatList > ( null )
57
-
58
- const presentSheet1 = async ( index = 0 ) => {
59
- await sheet1 . current ?. present ( index )
15
+ const presentBasicSheet = async ( index = 0 ) => {
16
+ await basicSheet . current ?. present ( index )
60
17
console . log ( 'Sheet 1 present async' )
61
18
}
62
19
63
- const resizeSheet1 = async ( index : number ) => {
64
- await sheet1 . current ?. resize ( index )
65
- console . log ( `Sheet 1 resize to ${ index } async` )
66
- }
67
-
68
- const dismissSheet1 = async ( ) => {
69
- await sheet1 . current ?. dismiss ( )
70
- console . log ( 'Sheet 1 dismiss asynced' )
71
- }
72
-
73
20
return (
74
21
< View style = { $container } >
75
- < Button text = "TrueSheet View" onPress = { ( ) => presentSheet1 ( 0 ) } />
76
- < Button text = "TrueSheet Prompt" onPress = { ( ) => sheetPrompt . current ?. present ( ) } />
77
- < Button text = "TrueSheet ScrollView" onPress = { ( ) => sheetScrollView . current ?. present ( ) } />
78
- < Button text = "TrueSheet FlatList" onPress = { ( ) => sheetFlatList . current ?. present ( ) } />
79
-
80
- < TrueSheet
81
- sizes = { [ 'auto' , '80%' , 'large' ] }
82
- ref = { sheet1 }
83
- contentContainerStyle = { $content }
84
- blurTint = "dark"
85
- backgroundColor = { DARK }
86
- cornerRadius = { 12 }
87
- grabberProps = { { color : GRABBER_COLOR } }
88
- onDismiss = { ( ) => console . log ( 'Sheet 1 dismissed!' ) }
89
- onPresent = { ( { index, value } ) =>
90
- console . log ( `Sheet 1 presented with size of ${ value } at index: ${ index } ` )
91
- }
92
- onSizeChange = { ( { index, value } ) => console . log ( `Resized to:` , value , 'at index:' , index ) }
93
- FooterComponent = { < Footer /> }
94
- >
95
- < DemoContent color = { DARK_BLUE } text = { random ( randomTexts ) } />
96
- < Button text = "Present Large" onPress = { ( ) => resizeSheet1 ( 2 ) } />
97
- < Button text = "Present 80%" onPress = { ( ) => resizeSheet1 ( 1 ) } />
98
- < Button text = "Present Auto" onPress = { ( ) => resizeSheet1 ( 0 ) } />
99
- < Button text = "Dismis" onPress = { dismissSheet1 } />
100
- </ TrueSheet >
101
-
102
- < TrueSheet
103
- ref = { sheetPrompt }
104
- sizes = { [ 'auto' , '80%' ] }
105
- contentContainerStyle = { $content }
106
- blurTint = "dark"
107
- backgroundColor = { DARK }
108
- cornerRadius = { 12 }
109
- grabberProps = { { color : GRABBER_COLOR } }
110
- onDismiss = { ( ) => console . log ( 'Sheet Prompt dismissed!' ) }
111
- onPresent = { ( { index, value } ) =>
112
- console . log ( `Sheet Prompt presented with size of ${ value } at index: ${ index } ` )
113
- }
114
- onSizeChange = { ( { index, value } ) => console . log ( `Resized to:` , value , 'at index:' , index ) }
115
- FooterComponent = { < Footer /> }
116
- >
117
- < DemoContent color = { DARK_BLUE } text = { random ( randomTexts ) } />
118
- < Input />
119
- < Button text = "Dismis" onPress = { ( ) => sheetPrompt . current ?. dismiss ( ) } />
120
- </ TrueSheet >
121
-
122
- < TrueSheet
123
- ref = { sheetScrollView }
124
- scrollRef = { scrollViewRef }
125
- onDismiss = { ( ) => console . log ( 'Sheet ScrollView dismissed!' ) }
126
- onPresent = { ( ) => console . log ( `Sheet ScrollView presented!` ) }
127
- FooterComponent = { < Footer /> }
128
- >
129
- < ScrollView
130
- ref = { scrollViewRef }
131
- contentContainerStyle = { [ $content , $scrollable ] }
132
- indicatorStyle = "black"
133
- >
134
- { times ( 25 , ( i ) => (
135
- < DemoContent key = { i } />
136
- ) ) }
137
- </ ScrollView >
138
- </ TrueSheet >
139
-
140
- < TrueSheet
141
- ref = { sheetFlatList }
142
- scrollRef = { flatListRef }
143
- sizes = { [ 'large' ] }
144
- cornerRadius = { 24 }
145
- grabber = { false }
146
- maxHeight = { 600 }
147
- onDismiss = { ( ) => console . log ( 'Sheet FlatList dismissed!' ) }
148
- onPresent = { ( ) => console . log ( `Sheet FlatList presented!` ) }
149
- >
150
- < FlatList < number >
151
- ref = { flatListRef }
152
- data = { times ( 50 , ( i ) => i ) }
153
- contentContainerStyle = { $content }
154
- indicatorStyle = "black"
155
- renderItem = { ( ) => < DemoContent radius = { 24 } /> }
156
- />
157
- </ TrueSheet >
158
- </ View >
159
- )
160
- }
161
-
162
- const Input = ( ) => {
163
- return (
164
- < View style = { $inputContainer } >
165
- < TextInput style = { $input } placeholder = "Enter some text..." placeholderTextColor = { GRAY } />
166
- </ View >
167
- )
168
- }
169
-
170
- const Footer = ( ) => {
171
- return (
172
- < View style = { $footer } >
173
- < Text style = { $whiteText } > FOOTER</ Text >
174
- </ View >
175
- )
176
- }
177
-
178
- const Button = ( props : ButtonProps ) => {
179
- const { text, ...rest } = props
180
- return (
181
- < TouchableOpacity activeOpacity = { 0.6 } style = { $button } { ...rest } >
182
- < Text style = { $whiteText } > { text } </ Text >
183
- </ TouchableOpacity >
184
- )
185
- }
186
-
187
- const DemoContent = ( props : DemoContentProps ) => {
188
- const { text, radius = BORDER_RADIUS , style : $style , color = LIGHT_GRAY , ...rest } = props
189
- return (
190
- < View
191
- style = { [ $demoContent , { backgroundColor : color , borderRadius : radius } , $style ] }
192
- { ...rest }
193
- >
194
- { text && < Text style = { $demoText } > { text } </ Text > }
22
+ < Button text = "TrueSheet View" onPress = { ( ) => presentBasicSheet ( 0 ) } />
23
+ < Button text = "TrueSheet Prompt" onPress = { ( ) => promptSheet . current ?. present ( ) } />
24
+ < Button text = "TrueSheet ScrollView" onPress = { ( ) => scrollViewSheet . current ?. present ( ) } />
25
+ < Button text = "TrueSheet FlatList" onPress = { ( ) => flatListSheet . current ?. present ( ) } />
26
+
27
+ < BasicSheet ref = { basicSheet } />
28
+ < PromptSheet ref = { promptSheet } />
29
+ < ScrollViewSheet ref = { scrollViewSheet } />
30
+ < FlatListSheet ref = { flatListSheet } />
195
31
</ View >
196
32
)
197
33
}
@@ -202,58 +38,3 @@ const $container: ViewStyle = {
202
38
padding : 24 ,
203
39
flex : 1 ,
204
40
}
205
-
206
- const $inputContainer : ViewStyle = {
207
- backgroundColor : 'white' ,
208
- paddingHorizontal : SPACING ,
209
- height : INPUT_HEIGHT ,
210
- borderRadius : BORDER_RADIUS ,
211
- justifyContent : 'center' ,
212
- marginBottom : SPACING * 2 ,
213
- }
214
-
215
- const $input : TextStyle = {
216
- fontSize : 16 ,
217
- height : SPACING * 3 ,
218
- }
219
-
220
- const $content : ViewStyle = {
221
- padding : SPACING ,
222
- }
223
-
224
- const $scrollable : ViewStyle = {
225
- paddingBottom : FOOTER_HEIGHT + SPACING ,
226
- }
227
-
228
- const $footer : ViewStyle = {
229
- height : FOOTER_HEIGHT ,
230
- backgroundColor : DARK_GRAY ,
231
- alignItems : 'center' ,
232
- justifyContent : 'center' ,
233
- }
234
-
235
- const $demoContent : ViewStyle = {
236
- height : 100 ,
237
- marginBottom : 16 ,
238
- padding : SPACING / 2 ,
239
- alignItems : 'center' ,
240
- }
241
-
242
- const $button : ViewStyle = {
243
- height : 40 ,
244
- padding : 12 ,
245
- borderRadius : BORDER_RADIUS ,
246
- backgroundColor : DARK_BLUE ,
247
- marginBottom : 12 ,
248
- alignItems : 'center' ,
249
- }
250
-
251
- const $whiteText : TextStyle = {
252
- color : 'white' ,
253
- }
254
-
255
- const $demoText : TextStyle = {
256
- fontSize : 16 ,
257
- lineHeight : 20 ,
258
- color : 'white' ,
259
- }
0 commit comments