airbnb / lottie-android

Render After Effects animations natively on Android and iOS, Web, and React Native
http://airbnb.io/lottie/
Apache License 2.0
34.95k stars 5.4k forks source link

How to replay the animation after a drawable resource is set to LottieAnimationView? #2467

Closed oOJohn6Oo closed 6 months ago

oOJohn6Oo commented 6 months ago

Link to fork with a repro in the issue-repro module issue-repo, test APKs is in the release section.

Describe the bug

I can switch between normal Drawable and LottieDrawable with version 6.2.0, just like Twitter's Like button.

binding.animationView.setOnClickListener {
    if((it as LottieAnimationView).drawable is LottieDrawable){
        it.setImageDrawable(ContextCompat.getDrawable(this, R.mipmap.ic_launcher))
    }else{
        it.setAnimation(R.raw.heart)
        it.playAnimation()
    }
}

ba6e49004292b214acd59d32a8ec8806

https://github.com/airbnb/lottie-android/blob/fe412fa6c2a5612b4379538e9a9bea14bb415569/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java#L608-L612

Changes to #2441 prevent us from setting the same animation for LottieAnimationView, but it also prevents us from replaying the animation.

I tried set frame to 0 then playAnimation(), but it didn't work.

Steps To Reproduce Steps to reproduce the behavior:

  1. Open the app, the heart animation should start playing.
  2. Click the heart, it should changes to app logo with no animation.
  3. Click the logo, there is no change in the UI of version 6.3.0. Version 6.2.0 displays the "heart" animation and starts playing.

What I want to know

  1. Is this an intented behavior?
  2. How to implement this feature in version 6.3.0?