Search code examples
animationreact-nativerendersetstatereact-animated

Animation render with React Native + Animated.timing and setState


The animation library it's working fine, but I have a problem when I execute this.setState while I’m using Animated.timing because it’s re-render my screen and my animations are restarted.

By example, when I try to run an animation with Animation.timer and at the same time I put an interval that make a setState each 1000 milliseconds, It make to my view re-render and to lose all the animation.

Can you help me?

Thank you very much!


Solution

  • For this issue you can use the shouldComponentUpdate method. If you don't want to rerender you just return false. Here is the doc for React but it works on React-Native the same way: https://facebook.github.io/react/docs/react-component.html#shouldcomponentupdate