Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LottieOnCompositionLoadedListener is not called when the animation is loaded again #2505

Closed
linkaipeng opened this issue May 28, 2024 · 1 comment

Comments

@linkaipeng
Copy link

Lottie is supported and developed on nights and weekends. Issues from Lottie sponsors will be prioritized.

If you don't use this template, your issue will be closed. Delete this text once completed.

Checklist

  1. Fork this repository into your account. ✅
  2. Reproduce your issue in the issue-repro module. Issues without a repro in the issue-repro
    module may be auto-closed. ✅

Link to fork with a repro in the issue-repro module

https://github.com/linkaipeng/lottie-android/tree/master/issue-repro

Describe the bug

Steps To Reproduce
Steps to reproduce the behavior:

  1. Call binding.animationView.playAnimation() within the addLottieOnCompositionLoadedListener onCompositionLoaded.
  2. Click loadButton, call setAnimation(R.raw.heart), it's work.
  3. Click cancelButton, call cancelAnimation()
  4. Click loadButton again, it's not work. Reproduce. However, the issue did not exist in the version 6.0.0.

I've reviewed the source code and analyzed the differences with version 6.0.0. I would like to know why these changes were made?

  • The setCompositionTask method in LottieAnimationView checks three conditions, and if they are the true, it will return and will not execute the addListener below.
    WX20240528-153916

  • In the cache method of LottieCompositionFactory, a new LottieTask is recreated, but the successListeners within it are empty. Therefore, the onResult inside notifySuccessListeners will not be called.
    1716884472741

@linkaipeng linkaipeng changed the title LottieOnCompositionLoadedListener has issues with not being called back LottieOnCompositionLoadedListener is not called when the animation is loaded again May 28, 2024
@gpeal
Copy link
Collaborator

gpeal commented Sep 29, 2024

This is actually the expected behavior here. cancelAnimation() cancels the animator so that if you call playAnimation() again, it'll restart from the beginning but you aren't actually "loading" it again after that.
If you call binding.animationView.setImageDrawable(null) and then all setAnimation(…) again then the callback will get called because it's actually updating the drawable on LottieAnimationView.

@gpeal gpeal closed this as completed Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants