react-lottie icon indicating copy to clipboard operation
react-lottie copied to clipboard

Animation plays itself when a state changes

Open gisellezeitoune opened this issue 6 years ago • 7 comments

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

First I'm rendering an animation with autoplay set to false. this.options = { loop: false, autoplay: false, animationData: require("./leo_anim.json"), rendererSettings: { preserveAspectRatio: "xMidYMid slice" } };

The animation does not start which is perfect, but then I call setState() function and the animation starts playing

See the behavior here: https://codesandbox.io/s/2wk6nv3pvr

What is the expected behavior?

If the animation has autoplay set to false, then it should only start when the play function is called.

Which versions of Lottie

Both "react-lottie": "1.0.0" & "react-lottie": "1.1.0"

Thank you for your help!

gisellezeitoune avatar Apr 03 '18 17:04 gisellezeitoune

Please set isStopped to true, which will work as you expected.

<Lottie options={this.props.options} isStopped={true}/>

chenqingspring avatar Apr 04 '18 04:04 chenqingspring

Thank you for your prompt response. That works! But then, what is autoplay for? Is it ok to set isStopped to true? It sounds like a hack just to make it work

gisellezeitoune avatar Apr 04 '18 11:04 gisellezeitoune

Yes, I think that is a bug to be fixed. I'll handle the logic in the wrapper.

Thanks for issuing this :)

chenqingspring avatar Apr 04 '18 12:04 chenqingspring

There's another problem when setting isStopped to true. Now, when a state changes, the animation stops playing.

See: https://codesandbox.io/s/xjr104920p

The play button should start the animation on the bottom but, because it also changes a state and the animation has isStopped set to true, the animation stops immediately after playing. Contrary to what happens with the top animation that has isStopped set to false. Even though I never play this animation, it starts because the state changed

gisellezeitoune avatar Apr 04 '18 18:04 gisellezeitoune

It is still not fixed

fuchenxu2008 avatar Jul 10 '19 06:07 fuchenxu2008

@gisellezeitoune I've encountered the same problem - it's still not fixed

However, a workaround is as followed;

Instead of using isStopped as the above post suggests use isPaused as things SEEM to work fine

<Lottie
  options={defaultOptions}
  isPaused={!isStopped}
  style={{
    width: 50,
    height: 50
  }}
/>

maccapakka avatar Nov 19 '19 21:11 maccapakka

@chenqingspring

Yes, I think that is a bug to be fixed. I'll handle the logic in the wrapper.

Sorry to bother you about this open issue from 2018 but it's causing our team a lot of pain. Any state change in the component knocks out autoplay: false.

Is there any chance you can look into this or do you need help with it, it's a fairly critical bug. Thanks!

mosesoak avatar Apr 23 '21 17:04 mosesoak