On state change and component re-rendering animation becomes junky.
See original GitHub issueFirst of all thanks for providing this wonderful library.
ISSUE
I am using MotiView
for creating Waves animation and every time the component mounts it is working fine and on state update, the animation becomes junky and stops working at the end.
I have also wrapped my animation component into the AnimatePresence
but still no success.
Code Sample
<AnimatePresence style={[styles.dot, styles.center]}>
{[...Array(5).keys()].map(index => {
return (
<MotiView
from={{opacity: 1, scale: 0}}
animate={{opacity: 0, scale: 9}}
transition={{
type: 'timing',
duration: durationCal,
easing: Easing.inOut(Easing.ease),
delay: index * 400,
repeatReverse: false,
loop: true,
}}
key={index}
style={[StyleSheet.absoluteFillObject, styles.dot]}
/>
);
})}
</AnimatePresence>
Demo Video
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:19 (9 by maintainers)
Top Results From Across the Web
Changing state re-renders the component in a way that breaks ...
this is a switch component that animates between two states. For some reason in the styleguide the component jumps between its two states...
Read more >Why You Need to Understand Re-rendering in React and ...
State can be confusing to understand at first since it only re-renders when the reference to your state changes. This video explains a...
Read more >My animation is not working when re rendering my react ...
After React rerender component it compares new render with the old one. And update only part that is changed. So you may try...
Read more >When does React re-render components? - Felix Gerschau
When the state changes in the parent component (in this case, App ), the two Tile components will re-render, even though the second...
Read more >React Hooks - Understanding Component Re-renders - Medium
What would happen — when parent and child components have their own local state (via useState) and parent's state gets changed ?
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just saw an issue with your code here. You’re using random numbers for
key
here. That is guaranteed to break code in react. It should always be a stable ID, or an index if indices are stable. This is guaranteeing a full re-render and random behavior. I’m almost certain this is never what you should do.In this case, your code should just be this:
Also, rather than a state change, use a shared value. Moti lets you pass the result of
useDerivedValue
totransition
, meaning you don’t have to trigger re-renders and get better performance. You’ll have to split each item into its own component, and then you can do something like this:Do not use
exit
orAnimatePresence
, they don’t make sense here.I believe these do work on Snack for iOS