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

LottieAnimationView silently pauses it's drawable without any notifications

Open inktomi opened this issue 2 years ago • 1 comments

Describe the bug Add a LottieAnimationView to a custom view and add that view to the layout. Write a test that needs to use the LottieIdlingAnimationResource to wait for the animation to finish.

In the custom view, replace the animation with another by rebinding the view with a new LottieAnimationView (detach the old one by calling removeAllViews() etc).

In LottieAnimationView onDetachedFromWindow is not handled, and it works it's way up to ImageView where it is handled by calling mDrawable.setVisible(false, false). Taking a look at what happens in LottieDrawable.setVisible we see that it will eventually call through to pauseAnimation() - the animation was running when the view was deatched to be recreated with a new LottieAnimationView.

pauseAnimation() goes to the LottieValueAnimator and sucessfully pauses the animation - but makes no notification of that to any callbacks - after all, in AnimatorListener there's no concept of pausing.

This causes an issue though, because the idling resource is never cleared.

Steps To Reproduce Steps to reproduce the behavior:

  1. Create a new FrameLayout that has a method like bindModel().
  2. Inside bindModel call removeAllViews() and then inflate a new layout containing a LottieAnimationView.
  3. Save off that layout for use in a lateinit var for the binding
  4. Have the animation run.
  5. Call bindModel() again, notice the animation on screen changes.
  6. Notice that you got no callback when the view was detached and the animation was paused.

To solve this, we can add something like this to bindModel() - but it's sort of messy.

        if(this::binding.isInitialized) {
            if(binding.iconAnimation.isAnimating) {
                binding.iconAnimation.cancelAnimation()
            }
        }

This code does result in the animation notifying that it's complete, and makes the idling resources happy - but it's not really the best api.

inktomi avatar Mar 16 '22 16:03 inktomi

@inktomi Could you create a project that reproduces this?

gpeal avatar Apr 23 '22 20:04 gpeal

There is a separate interface for pause listeners, have you tried that?

Given that there has been no sample project or update here, I'm going to go ahead and close this but let me know if the pause listener works for you.

gpeal avatar Nov 24 '22 17:11 gpeal