Is there any way to close a toast programmatically?
I'm displaying one as an "error message" but I want to programmatically close it when the user is about to close the screen.
Wrapping my screen with the Root component (instead of doing that globally) works, however it does cause an error if you close the screen without closing the toast, and the you navigate back to the same screen.
Wouldn't a static close method in ToastContainer be enough for this task?
static close() {
this.toastInstance._root.closeToast();
}
EDIT:
I just found out that the following will also work:
Toast.toastInstance._root.closeToast();
hey @shivrajkumar , did you close the issue 'cause Toast.toastInstance is the "official" way to close a toast?
@shivrajkumar ?!!
@nicgutierrez There is no "official" way to close the toast programmatically. But if that works for you, feel free to use that.
Let me know if that serves your your purpose so that we can close this.
@sankhadeeproy007 thanks for your reply. Toast.toastInstance._root.closeToast(); indeed works for me.
Most helpful comment
Wouldn't a static close method in ToastContainer be enough for this task?
static close() { this.toastInstance._root.closeToast(); }EDIT:
I just found out that the following will also work:
Toast.toastInstance._root.closeToast();