Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add starting animation delay to lottie-react-native

This is my component and I want the animation to start 0.5s after the page has been landed on. How can I achieve this?

No props for delay here:
https://github.com/lottie-react-native/lottie-react-native/

<Lottie
  style={[
    {
      position: 'relative',
      height: 160,
      width: 160,
    },
    spacing.gbMt1,
  ]}
  autoPlay={true}
  loop={false}
  source={require('../assets/lottie/Coach001.json')}
/>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There is no prop for adding time delay but you can use these API methods to play, pause, resume and reset animation. You will need to set autoplay to false and call "play" method in timeout of 5 seconds to achieve the required delay.

useEffect(() => {
  setTimeout(() => {
    ref?.current?.play();
  }, 500)
}, [])
<Lottie
  ref={ref}
  style={[
    {
      position: 'relative',
      height: 160,
      width: 160,
    },
    spacing.gbMt1,
  ]}
  autoPlay={false}
  loop={false}
  source={require('../assets/lottie/Coach001.json')}
/>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading