forked from mrzachnugent/react-native-reusables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoast.tsx
51 lines (48 loc) · 1.65 KB
/
toast.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
import { Pressable } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import Toast, { ToastConfig } from 'react-native-toast-message';
import { Alert, AlertDescription, AlertTitle } from '~/components/ui/alert';
/**
* @docs https://github.com/calintamas/react-native-toast-message/blob/main/docs/quick-start.md
*/
const TOAST_CONFIG: ToastConfig = {
success: ({ text1, text2, onPress, props: { icon = 'CheckSquare' } }) => (
<Pressable onPress={onPress} className='px-6 w-full max-w-xl'>
<Alert icon={icon} variant='success'>
<AlertTitle>{text1}</AlertTitle>
<AlertDescription>{text2}</AlertDescription>
</Alert>
</Pressable>
),
error: ({ text1, text2, onPress, props: { icon = 'AlertTriangle' } }) => (
<Pressable onPress={onPress} className='px-6 w-full max-w-xl'>
<Alert icon={icon} variant='destructive'>
<AlertTitle>{text1}</AlertTitle>
<AlertDescription>{text2}</AlertDescription>
</Alert>
</Pressable>
),
base: ({ text1, text2, onPress, props: { icon = 'Info' } }) => (
<Pressable onPress={onPress} className='px-6 w-full max-w-xl'>
<Alert icon={icon} variant='default'>
<AlertTitle>{text1}</AlertTitle>
<AlertDescription>{text2}</AlertDescription>
</Alert>
</Pressable>
),
};
/**
*
* If you want to use a Toast in a Modal, you will need to add another `ToastPrivider` as a child of the Modal.
*/
function ToastProvider() {
const insets = useSafeAreaInsets();
return (
<Toast
config={TOAST_CONFIG}
topOffset={insets.top}
bottomOffset={insets.bottom}
/>
);
}
export { ToastProvider };