Solved: Figure out dismiss-event of Toast


#1

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.


#2

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");
      break;
    case 'backdrop':
      console.log("Duration timeout");
      break;
    case 'custom':
      console.log("toast.dismiss('custom'); called");
      break;
  }
});

Maybe this can be added to the docs.


#3

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