arnnis / react-native-toast-notifications

Toast component for React Native, supports Android, iOS and Web
563 stars 89 forks source link

Toast content is not updating #141

Open anilchrishan opened 2 years ago

anilchrishan commented 2 years ago

let id = toast.show("Loading..."); toast.update(id, "Loading completed", {type: "success"});

toast.update function is not working.

nikki-cat commented 2 years ago

You're not experiencing issues related to this, are you?

Sin-Yone commented 7 months ago

I faced the same issue that toasts sometimes dont update. I think the problem is inside the show function. https://github.com/arnnis/react-native-toast-notifications/blob/e0ed48e1098359d933c84c9c6dbaafe13810ea68/src/toast-container.tsx#L43-L68 The new toast will be set in the state inside the requestAnimationFrame method. But it is not used in the update method. Since requestAnimationFrame will only be called before the next repaint, the new toast is probably not in the state yet and those cannot be found and updated. https://github.com/arnnis/react-native-toast-notifications/blob/e0ed48e1098359d933c84c9c6dbaafe13810ea68/src/toast-container.tsx#L73-L83 I fixed it by wrapping the toast.update() inside the requestAnimationFrame method. For your example it should be:

requestAnimationFrame(() => {
    toast.update(id, "Loading completed", {type: "success"});
});

The toast is now updated about 20ms later than without the method, but this is not noticeable.

groom7 commented 3 months ago

I fixed it by wrapping the toast.update() inside the requestAnimationFrame method.

This worked for me too. But what's the problem?