Giter VIP home page Giter VIP logo

Comments (3)

Sin-Yone avatar Sin-Yone commented on September 14, 2024 1

I faced the same issue that toasts sometimes dont update.
I think the problem is inside the show function.

show = (message: string | JSX.Element, toastOptions?: ToastOptions) => {
let id = toastOptions?.id || Math.random().toString();
const onDestroy = () => {
toastOptions?.onClose && toastOptions?.onClose();
this.setState({ toasts: this.state.toasts.filter((t) => t.id !== id) });
};
requestAnimationFrame(() => {
this.setState({
toasts: [
{
id,
onDestroy,
message,
open: true,
onHide: () => this.hide(id),
...this.props,
...toastOptions,
},
...this.state.toasts.filter((t) => t.open),
],
});
});
return id;
};

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.
update = (
id: string,
message: string | JSX.Element,
toastOptions?: ToastOptions
) => {
this.setState({
toasts: this.state.toasts.map((toast) =>
toast.id === id ? { ...toast, message, ...toastOptions } : toast
),
});
};

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.

from react-native-toast-notifications.

nikki-cat avatar nikki-cat commented on September 14, 2024

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

from react-native-toast-notifications.

groom7 avatar groom7 commented on September 14, 2024

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

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

from react-native-toast-notifications.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.