forked from mrzachnugent/react-native-reusables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbottom-sheet.tsx
89 lines (86 loc) · 2.69 KB
/
bottom-sheet.tsx
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
84
85
86
87
88
89
import React from 'react';
import { Platform, Text, View } from 'react-native';
import {
BottomSheet,
BottomSheetCloseTrigger,
BottomSheetContent,
BottomSheetHeader,
BottomSheetOpenTrigger,
BottomSheetTextInput,
BottomSheetView,
} from '~/components/ui/bottom-sheet';
import {
Button,
buttonTextVariants,
buttonVariants,
} from '~/components/ui/button';
import { Label } from '~/components/ui/label';
import { cn } from '~/lib/utils';
export default function BottomSheetScreen() {
const nameInputRef =
React.useRef<React.ComponentRef<typeof BottomSheetTextInput>>(null);
const usernameInputRef =
React.useRef<React.ComponentRef<typeof BottomSheetTextInput>>(null);
function handleOnLabelPress(ref: typeof nameInputRef) {
return () => {
if (!ref.current) return;
const input = ref.current;
if (input && 'focus' in input && typeof input.focus === 'function') {
input.focus();
}
};
}
return (
<View className='flex-1 justify-center items-center'>
<BottomSheet>
<BottomSheetOpenTrigger asChild>
<Button>
{Platform.OS === 'web' ? 'Not implemented for web yet' : 'Open'}
</Button>
</BottomSheetOpenTrigger>
<BottomSheetContent>
<BottomSheetHeader>
<Text className='text-foreground text-xl font-bold text-center pb-1'>
Edit your profile
</Text>
</BottomSheetHeader>
<BottomSheetView className='gap-5 pt-6'>
<View className='pb-2 gap-6'>
<View>
<Label
className={'pb-2.5'}
onPress={handleOnLabelPress(nameInputRef)}
>
Name
</Label>
<BottomSheetTextInput
defaultValue='Pedro Duarte'
ref={nameInputRef}
/>
</View>
<View>
<Label
className={'pb-2.5'}
onPress={handleOnLabelPress(usernameInputRef)}
>
Username
</Label>
<BottomSheetTextInput
defaultValue='@peduarte'
ref={usernameInputRef}
/>
</View>
</View>
<View className={cn(Platform.OS === 'android' && 'pb-2')}>
<BottomSheetCloseTrigger
className={buttonVariants({ size: 'sm' })}
>
<Text className={buttonTextVariants()}>Save Changes</Text>
</BottomSheetCloseTrigger>
</View>
</BottomSheetView>
</BottomSheetContent>
</BottomSheet>
</View>
);
}