If you haven’t already, check out the ToastController specification. There it says that when a toast is dismissed via timeout or user input, the onDidDismiss function is called wherein you could notify a custom ToastProvider you have written that pops this specific toast from its queue.
You’ll need to adapt this, but it’s just finds the next item on the queue and shows the toast. A simpler version would be to pop the items from the queue and just check for an empty queue.
How would you implement this in an angular architecture?
Create a component (QueuedToast), or service? Or something else?
I guess a QueuedToast with embedded ToastQueueService is the cleanest, although I wouldnt mind letting a service do some UI - even though that goes against
To avoid the unhandled promise rejection and other errors by Android studio, do the following:
/*the reason for the error is when using toastCtrl.dismiss() it doesn't find any overlay
toast especially if your code has a toast function to run when intializing the app.
So, to avoid that, we create a toastcontroller with empty parameters then we can
dismiss it so the app doesn't give error for not finding anything to dismiss.
By the way, this toastcontroller is not presented, no worries. it's just created.
Define it first inside your class constructor, then you can use separate function
to show and dismiss toasts as in the example below*/
constructor () {
const toasty = this.toastCtrl.create();
}
async presentToast(msg: string) {
/* it dismisses the top overlay. so for me it does close any current toast on
the overlay before showing another one. i tested it with button etc. */
this.toastCtrl.dismiss();
const toast = await this.toastCtrl.create({
message: msg,
duration: 3000,
position: 'middle',
buttons: [{
icon: 'close-circle',
role: 'cancel'
}]
});
toast.present();
}