nandorojo / moti

🐼 The React Native (+ Web) animation library, powered by Reanimated 3.
https://moti.fyi
MIT License
3.9k stars 120 forks source link

Animation reset or stop when component is rerendered #327

Closed oliviercperrier closed 6 months ago

oliviercperrier commented 6 months ago

Is there an existing issue for this?

Do you want this issue prioritized?

Current Behavior

I have a button component with a Spinner (using moti animation). This spinner shows up when the loading props is set to true. The button opacity also change when the button is hovered. When the button is loading and hovered (in/out), the spinner animation reset or stop because de MotiView is rerendered.

Expected Behavior

The spinner animation should not stop or be reset when the MotiView is rerendered

Steps To Reproduce

See reproduction

Versions

see reproduction

Screenshots

No response

Reproduction

https://stackblitz.com/edit/nextjs-e2vcnq?file=pages%2Findex.tsx

oliviercperrier commented 6 months ago

@nandorojo This is blocking for us, if its possible to fix or if there is an alternative it would be appreciated. Thanks

nandorojo commented 6 months ago

If it's urgent for you, you can check the "I've sponsored" box in the original post.

Otherwise, I will take a look when I have time.

Consider memoizing the spinner.

nandorojo commented 6 months ago

Maybe this will fix it

https://stackblitz.com/edit/nextjs-cffja2?file=components%2FButton.tsx

oliviercperrier commented 6 months ago

@nandorojo Thanks for the quick response. In fact, memoizing works for use case! Thanks

i would still let this issue open (not urgent)

nandorojo commented 6 months ago

Glad it helped.

This is blocking for us, if it's possible to fix or if there is an alternative it would be appreciated. Thanks

For future reference, please consider sponsoring before tagging me.