lottie-android
lottie-android copied to clipboard
LottieAnimationView silently pauses it's drawable without any notifications
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:
- Create a new
FrameLayout
that has a method likebindModel()
. - Inside
bindModel
callremoveAllViews()
and then inflate a new layout containing aLottieAnimationView
. - Save off that layout for use in a
lateinit var
for the binding - Have the animation run.
- Call
bindModel()
again, notice the animation on screen changes. - 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 Could you create a project that reproduces this?
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.