It appears that this issue isn’t actually resolved.
I have a function.
presentToast(msg: string, time = 2000) {
const toast = this.toastCtrl.create({
message: msg,
duration: time,
position: "top"
});
toast.present();
}
I also have a list of items that can be “liked” by clicking on an icon in the list. Whenever an item is “liked” the presentToast method is called.
likeItem( item ){
// do service work to like item
this.presentToast("Item liked!");
}
If I “like” a single item I see the toast appear then disappear after the duration has passed. If I like several items in a row I see each toast appear, but only one will disappear (I can tell by the change in the stack of toasts opacity).
Additionally, manually calling .dismiss() on the toast also does nothing.
presentToast(msg: string, time = 2000) {
const toast = this.toastCtrl.create({
message: msg,
duration: time,
position: "top"
});
toast.present();
setTimeout(() => {
toast.dismiss();
console.log("called dismiss");
}, time + 500);
}
… here I see “called dismiss” multiple times, but the toasts never actually dismiss. Removing the duration option has no effect on calling dismiss either.
For now I am keeping track of whether a toast is displayed or not and only allowing “present” to be called whenever a toast is displayed. In other cases I simply update the toast’s message to the new message. This isn’t great because the single toast still dismisses after the duration from the first present passes (ie. if duration is 3 seconds and I call the toast again after 2 seconds, the message will update, but only be displayed for 1 more second).
presentToast(msg: string, time = 2000) {
if (this.canShowToast) {
this.canShowToast = false;
this.displayedToast = this.toastCtrl.create({
message: msg,
duration: time,
position: "top"
});
this.displayedToast.present();
this.displayedToast.onDidDismiss(() => {
this.canShowToast = true;
});
} else {
this.displayedToast.setMessage(msg);
}
}