11import * as React from 'react' ;
2- import { Stack , useGlobalSearchParams } from 'expo-router ' ;
3- import { Text } from 'react-native ' ;
2+ import { Pressable , Text , useColorScheme } from 'react-native ' ;
3+ import { Stack , useGlobalSearchParams , useRouter } from 'expo-router ' ;
44import { GestureHandlerRootView } from 'react-native-gesture-handler' ;
55import { SafeAreaProvider } from 'react-native-safe-area-context' ;
6- import { Toaster , type ToastPosition } from 'sonner-native' ;
6+ import {
7+ Toaster ,
8+ type AutoWiggle ,
9+ type ToastPosition ,
10+ type ToastSwipeDirection ,
11+ type ToastTheme ,
12+ } from 'sonner-native' ;
713
814const RootLayout : React . FC = ( ) => {
15+ const colorScheme = useColorScheme ( ) ;
16+ const router = useRouter ( ) ;
917 const params = useGlobalSearchParams < {
1018 stacking ?: string ;
1119 position ?: string ;
20+ theme ?: string ;
21+ swipeDirection ?: string ;
22+ closeButton ?: string ;
23+ visibleToasts ?: string ;
24+ autoWiggle ?: string ;
25+ richColors ?: string ;
26+ invert ?: string ;
1227 } > ( ) ;
1328
29+ const position = ( params . position as ToastPosition ) || 'top-center' ;
1430 const stackingEnabled = params . stacking !== 'false' ;
15- const defaultPosition = ( params . position as ToastPosition ) || 'top-center' ;
31+ const theme = ( params . theme as ToastTheme ) || 'system' ;
32+ const swipeDirection =
33+ ( params . swipeDirection as ToastSwipeDirection ) || 'up' ;
34+ const closeButton = params . closeButton !== 'false' ;
35+ const visibleToasts = parseInt ( params . visibleToasts || '4' , 10 ) ;
36+ const autoWiggle = ( params . autoWiggle as AutoWiggle ) || 'toast-change' ;
37+ const richColors = params . richColors === 'true' ;
38+ const invert = params . invert === 'true' ;
1639
1740 return (
1841 < SafeAreaProvider >
1942 < GestureHandlerRootView style = { { flex : 1 } } >
2043 < Stack >
21- { /* Tabs group - all tab screens are handled in (tabs)/_layout.tsx */ }
2244 < Stack . Screen
23- name = "(tabs) "
45+ name = "index "
2446 options = { {
25- headerShown : false ,
47+ title : 'Toasts' ,
48+ headerRight : ( ) => (
49+ < Pressable
50+ onPress = { ( ) => router . push ( '/modal' ) }
51+ hitSlop = { 8 }
52+ >
53+ < Text
54+ style = { {
55+ color :
56+ colorScheme === 'dark' ? '#0A84FF' : '#007AFF' ,
57+ fontSize : 17 ,
58+ } }
59+ >
60+ Modal
61+ </ Text >
62+ </ Pressable >
63+ ) ,
2664 } }
2765 />
28- { /* Modal screens outside of tabs */ }
66+ < Stack . Screen
67+ name = "(tabs)"
68+ options = { { headerShown : false } }
69+ />
2970 < Stack . Screen
3071 name = "modal"
3172 options = { {
@@ -36,14 +77,16 @@ const RootLayout: React.FC = () => {
3677 />
3778 </ Stack >
3879 < Toaster
39- position = { defaultPosition }
80+ position = { position }
4081 duration = { 30000 }
41- swipeToDismissDirection = "up"
42- visibleToasts = { 4 }
43- closeButton
44- autoWiggleOnUpdate = "toast-change"
45- theme = "system"
82+ swipeToDismissDirection = { swipeDirection }
83+ visibleToasts = { visibleToasts }
84+ closeButton = { closeButton }
85+ autoWiggleOnUpdate = { autoWiggle }
86+ theme = { theme }
4687 enableStacking = { stackingEnabled }
88+ richColors = { richColors }
89+ invert = { invert }
4790 icons = { {
4891 error : < Text > 💥</ Text > ,
4992 loading : < Text > 🔄</ Text > ,
0 commit comments