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

Changing autoplay from false to true after mount does not start to play

Open pke opened this issue 5 years ago • 2 comments

Description

I know its described in the docs, that the autoplay prop only affects the component on mount. In a full declarative way this is kind of unexpected and I had to read about it in the docs after I thought my code has a bug.

I wonder, is there a technical reason the prop can't be changed after the component has been mounted? Its already issuing a play command when the source is changed and autoplay===true. I know the name of the prop is autoplay and for my proposal the property better named playing.

The more declarative behaviour would probably no more then 3 lines of code, unless I am missing something?

componentDidUpdate(prevProps) {
  if (this.props.source.nm !== prevProps.source.nm && this.props.autoPlay) {
    this.play();
  }
  if (this.props.autoPlay != prevProps.autoPlay) {
    this.props.autoPlay ? this.play() : this.stop();
  }
 }

Steps to Reproduce

const [playing, setPlaying] = useState(false)

const onStartClick = useCallback(() {
  setPlaying(true)
}, [])

<LottieView ... autoplay={playing} />

Changing the playing var does not start to play the animation.

Expected behavior: [What you expected to happen]

Expected to animation to play.

Actual behavior: [What actually happened]

The animation was not played.

pke avatar May 29 '20 23:05 pke

I'm running into this same issue but with a hook component. idk what is causing it either. I console.log the useState and uppon clicking it, it is turning true but the animation won't start playing

HosAkh avatar Jan 26 '21 16:01 HosAkh

Try changing the speed of LottieView using the setTimeout function.

solankiTejasHere avatar Dec 30 '21 05:12 solankiTejasHere

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 14 '22 07:08 stale[bot]

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

stale[bot] avatar Aug 30 '22 21:08 stale[bot]