1- import { Button , Toast , useToaster } from 'heroui-native' ;
2- import { useEffect , useState } from 'react' ;
1+ import { Button , Toast , useToast } from 'heroui-native' ;
32import { View } from 'react-native' ;
43import type { UsageVariant } from '../../../components/component-presentation/types' ;
54import { UsageVariantFlatList } from '../../../components/component-presentation/usage-variant-flatlist' ;
@@ -70,35 +69,42 @@ const AllVariantsContent = () => {
7069// ------------------------------------------------------------------------------
7170
7271const InteractiveDemoContent = ( ) => {
73- const toast = useToaster ( ) ;
74-
75- const myToast = toast . prepare ( {
76- component : ( id ) => (
77- < Toast variant = "accent" className = "flex-row items-center gap-3" >
78- < View className = "flex-1" >
79- < Toast . Label > Interactive Toast</ Toast . Label >
80- < Toast . Description >
81- Use buttons below to control this toast
82- </ Toast . Description >
83- </ View >
84- < Toast . Action onPress = { ( ) => toast . hide ( id ) } > Close</ Toast . Action >
85- </ Toast >
86- ) ,
87- } ) ;
72+ const { show, hide } = useToast ( ) ;
8873
8974 return (
9075 < View className = "flex-1 px-5" >
9176 < View className = "flex-1 justify-center gap-3" >
92- < Button onPress = { ( ) => toast . show ( myToast ) } variant = "primary" >
77+ < Button
78+ onPress = { ( ) => {
79+ const id = show ( {
80+ id : 'my-toast' ,
81+ component : (
82+ < Toast variant = "accent" className = "flex-row items-center gap-3" >
83+ < View className = "flex-1" >
84+ < Toast . Label > Interactive Toast</ Toast . Label >
85+ < Toast . Description >
86+ Use buttons below to control this toast
87+ </ Toast . Description >
88+ </ View >
89+ < Toast . Action onPress = { ( ) => hide ( 'my-toast' ) } >
90+ Close
91+ </ Toast . Action >
92+ </ Toast >
93+ ) ,
94+ } ) ;
95+ console . log ( 'Toast shown with ID:' , id ) ;
96+ } }
97+ variant = "primary"
98+ >
9399 Show Toast
94100 </ Button >
95101
96- < Button onPress = { ( ) => toast . hide ( myToast ) } variant = "secondary" >
102+ < Button onPress = { ( ) => hide ( 'my-toast1' ) } variant = "secondary" >
97103 Hide Toast
98104 </ Button >
99105
100- < Button onPress = { ( ) => toast . remove ( myToast ) } variant = "destructive" >
101- Remove Toast
106+ < Button onPress = { ( ) => hide ( ) } variant = "destructive" >
107+ Hide All Toasts
102108 </ Button >
103109 </ View >
104110 </ View >
@@ -108,80 +114,85 @@ const InteractiveDemoContent = () => {
108114// ------------------------------------------------------------------------------
109115
110116const MultipleToastsContent = ( ) => {
111- const toast = useToaster ( ) ;
112-
113- const toast1 = toast . prepare ( {
114- component : ( id : string ) => (
115- < Toast
116- variant = "default"
117- placement = "top"
118- className = "flex-row items-center gap-3"
119- >
120- < View className = "flex-1" >
121- < Toast . Label > Toast 1</ Toast . Label >
122- < Toast . Description > First toast at top</ Toast . Description >
123- </ View >
124- < Toast . Action onPress = { ( ) => toast . hide ( id ) } > Close</ Toast . Action >
125- </ Toast >
126- ) ,
127- } ) ;
128-
129- const toast2 = toast . prepare ( {
130- component : ( id : string ) => (
131- < Toast
132- variant = "accent"
133- placement = "top"
134- className = "flex-row items-center gap-3"
135- >
136- < View className = "flex-1" >
137- < Toast . Label > Toast 2</ Toast . Label >
138- < Toast . Description > Second toast at top</ Toast . Description >
139- </ View >
140- < Toast . Action onPress = { ( ) => toast . hide ( id ) } > Close</ Toast . Action >
141- </ Toast >
142- ) ,
143- } ) ;
144-
145- const toast3 = toast . prepare ( {
146- component : ( id : string ) => (
147- < Toast
148- variant = "success"
149- placement = "bottom"
150- className = "flex-row items-center gap-3"
151- >
152- < View className = "flex-1" >
153- < Toast . Label > Toast 3</ Toast . Label >
154- < Toast . Description > Third toast at bottom</ Toast . Description >
155- </ View >
156- < Toast . Action onPress = { ( ) => toast . hide ( id ) } > Close</ Toast . Action >
157- </ Toast >
158- ) ,
159- } ) ;
160-
161- const allToasts = [ toast1 , toast2 , toast3 ] ;
117+ const { show, hide } = useToast ( ) ;
162118
163119 return (
164120 < View className = "flex-1 px-5" >
165121 < View className = "flex-1 justify-center gap-3" >
166122 < Button
167- onPress = { ( ) => allToasts . forEach ( ( id ) => toast . show ( id ) ) }
123+ onPress = { ( ) => {
124+ // Show multiple toasts with custom IDs
125+ show ( {
126+ id : 'toast-1' ,
127+ component : (
128+ < Toast
129+ variant = "default"
130+ placement = "top"
131+ className = "flex-row items-center gap-3"
132+ >
133+ < View className = "flex-1" >
134+ < Toast . Label > Toast 1</ Toast . Label >
135+ < Toast . Description > First toast at top</ Toast . Description >
136+ </ View >
137+ < Toast . Action onPress = { ( ) => hide ( 'toast-1' ) } >
138+ Close
139+ </ Toast . Action >
140+ </ Toast >
141+ ) ,
142+ } ) ;
143+
144+ show ( {
145+ id : 'toast-2' ,
146+ component : (
147+ < Toast
148+ variant = "accent"
149+ placement = "top"
150+ className = "flex-row items-center gap-3"
151+ >
152+ < View className = "flex-1" >
153+ < Toast . Label > Toast 2</ Toast . Label >
154+ < Toast . Description > Second toast at top</ Toast . Description >
155+ </ View >
156+ < Toast . Action onPress = { ( ) => hide ( 'toast-2' ) } >
157+ Close
158+ </ Toast . Action >
159+ </ Toast >
160+ ) ,
161+ } ) ;
162+
163+ show ( {
164+ id : 'toast-3' ,
165+ component : (
166+ < Toast
167+ variant = "success"
168+ placement = "bottom"
169+ className = "flex-row items-center gap-3"
170+ >
171+ < View className = "flex-1" >
172+ < Toast . Label > Toast 3</ Toast . Label >
173+ < Toast . Description > Third toast at bottom</ Toast . Description >
174+ </ View >
175+ < Toast . Action onPress = { ( ) => hide ( 'toast-3' ) } >
176+ Close
177+ </ Toast . Action >
178+ </ Toast >
179+ ) ,
180+ } ) ;
181+ } }
168182 variant = "primary"
169183 >
170184 Show All Toasts
171185 </ Button >
172186
173187 < Button
174- onPress = { ( ) => allToasts . forEach ( ( id ) => toast . hide ( id ) ) }
188+ onPress = { ( ) => hide ( [ 'toast-1' , 'toast-2' , ' toast-3' ] ) }
175189 variant = "secondary"
176190 >
177- Hide All Toasts
191+ Hide Specific Toasts
178192 </ Button >
179193
180- < Button
181- onPress = { ( ) => allToasts . forEach ( ( id ) => toast . remove ( id ) ) }
182- variant = "destructive"
183- >
184- Remove All Toasts
194+ < Button onPress = { ( ) => hide ( ) } variant = "destructive" >
195+ Hide All Toasts
185196 </ Button >
186197 </ View >
187198 </ View >
@@ -201,11 +212,11 @@ const TOAST_VARIANTS: UsageVariant[] = [
201212 label : 'Interactive Demo' ,
202213 content : < InteractiveDemoContent /> ,
203214 } ,
204- // {
205- // value: 'multiple-toasts',
206- // label: 'Multiple Toasts',
207- // content: <MultipleToastsContent />,
208- // },
215+ {
216+ value : 'multiple-toasts' ,
217+ label : 'Multiple Toasts' ,
218+ content : < MultipleToastsContent /> ,
219+ } ,
209220] ;
210221
211222export default function ToastScreen ( ) {
0 commit comments