@@ -21,6 +21,9 @@ Toast.defineProperty(Toast, "duration", {default = 3, type = "number"})
2121--- @property toastType string "default" Type of toast: default, success, error, warning, info
2222Toast .defineProperty (Toast , " toastType" , {default = " default" , type = " string" , canTriggerRender = true })
2323
24+ --- @property callback function nil Callback function to call when the toast hides
25+ Toast .defineProperty (Toast , " callback" , {default = nil , type = " function" })
26+
2427--- @property autoHide boolean true Whether the toast should automatically hide after duration
2528Toast .defineProperty (Toast , " autoHide" , {default = true , type = " boolean" })
2629
7073--- @param titleOrMessage string The title (if message provided ) or the message (if no message )
7174--- @param messageOrDuration ? string | number The message (if string ) or duration (if number )
7275--- @param duration ? number Duration in seconds
76+ --- @param callback ? function Callback function to call when the toast hides
7377--- @return Toast self The Toast instance
74- function Toast :show (titleOrMessage , messageOrDuration , duration )
78+ function Toast :show (titleOrMessage , messageOrDuration , duration , callback )
7579 local title , message , dur
7680 if type (messageOrDuration ) == " string" then
7781 title = titleOrMessage
@@ -90,6 +94,7 @@ function Toast:show(titleOrMessage, messageOrDuration, duration)
9094 self .set (" title" , title )
9195 self .set (" message" , message )
9296 self .set (" active" , true )
97+ self .set (" callback" , callback )
9398
9499 if self ._hideTimerId then
95100 os .cancelTimer (self ._hideTimerId )
@@ -123,43 +128,47 @@ end
123128--- @param titleOrMessage string The title or message
124129--- @param messageOrDuration ? string | number The message or duration
125130--- @param duration ? number Duration in seconds
131+ --- @param callback ? function Callback function to call when the toast hides
126132--- @return Toast self The Toast instance
127- function Toast :success (titleOrMessage , messageOrDuration , duration )
133+ function Toast :success (titleOrMessage , messageOrDuration , duration , callback )
128134 self .set (" toastType" , " success" )
129- return self :show (titleOrMessage , messageOrDuration , duration )
135+ return self :show (titleOrMessage , messageOrDuration , duration , callback )
130136end
131137
132138--- Shows an error toast
133139--- @shortDescription Shows an error toast
134140--- @param titleOrMessage string The title or message
135141--- @param messageOrDuration ? string | number The message or duration
136142--- @param duration ? number Duration in seconds
143+ --- @param callback ? function Callback function to call when the toast hides
137144--- @return Toast self The Toast instance
138- function Toast :error (titleOrMessage , messageOrDuration , duration )
145+ function Toast :error (titleOrMessage , messageOrDuration , duration , callback )
139146 self .set (" toastType" , " error" )
140- return self :show (titleOrMessage , messageOrDuration , duration )
147+ return self :show (titleOrMessage , messageOrDuration , duration , callback )
141148end
142149
143150--- Shows a warning toast
144151--- @shortDescription Shows a warning toast
145152--- @param titleOrMessage string The title or message
146153--- @param messageOrDuration ? string | number The message or duration
147154--- @param duration ? number Duration in seconds
155+ --- @param callback ? function Callback function to call when the toast hides
148156--- @return Toast self The Toast instance
149- function Toast :warning (titleOrMessage , messageOrDuration , duration )
157+ function Toast :warning (titleOrMessage , messageOrDuration , duration , callback )
150158 self .set (" toastType" , " warning" )
151- return self :show (titleOrMessage , messageOrDuration , duration )
159+ return self :show (titleOrMessage , messageOrDuration , duration , callback )
152160end
153161
154162--- Shows an info toast
155163--- @shortDescription Shows an info toast
156164--- @param titleOrMessage string The title or message
157165--- @param messageOrDuration ? string | number The message or duration
158166--- @param duration ? number Duration in seconds
167+ --- @param callback ? function Callback function to call when the toast hides
159168--- @return Toast self The Toast instance
160- function Toast :info (titleOrMessage , messageOrDuration , duration )
169+ function Toast :info (titleOrMessage , messageOrDuration , duration , callback )
161170 self .set (" toastType" , " info" )
162- return self :show (titleOrMessage , messageOrDuration , duration )
171+ return self :show (titleOrMessage , messageOrDuration , duration , callback )
163172end
164173
165174--- @shortDescription Dispatches events to the Toast instance
@@ -169,6 +178,11 @@ function Toast:dispatchEvent(event, ...)
169178 if event == " timer" then
170179 local timerId = select (1 , ... )
171180 if timerId == self ._hideTimerId then
181+ self ._hideTimerId = nil
182+ local callback = self .getResolved (" callback" )
183+ if callback then
184+ callback (self )
185+ end
172186 self :hide ()
173187 end
174188 end
0 commit comments