Solved: Figure out dismiss-event of Toast

Hey, I have a toast with shown closeButton and I would need to detect, what triggered the dismiss

There are several options:

  1. Timeout after duration
  2. A toast.dismiss();
  3. Or a click on the closeButton

I want a special handling only when the closeButton was clicked, so it would be great, if you would change the onDidDismiss to something like
toast.onDidDismiss((event: Event) => {...}); with the triggered event.

Ok, after checking the source I figured out, that this already exist. I was really close to it, but the role/event is the second parameter…

toast.onWillDismiss((_null, role) => {
  switch (role) {
    case 'close':
      console.log("Button clicked");
    case 'backdrop':
      console.log("Duration timeout");
    case 'custom':
      console.log("toast.dismiss('custom'); called");

Maybe this can be added to the docs.


Just when I was going to read the code source, you saved me the trouble. Thank you :smiley: