I'm using version 3.0.6
I call playAnimation() in onBindViewHolder() to play animation.
It works when I add item to RecyclerView, but does not work when there's some changes and call notifyItemChanged().
After a while, I noticed that there's some checks in LottieAnimationView.playAnimation().
if (isShown()) {
lottieDrawable.playAnimation();
enableOrDisableHardwareLayer();
} else {
wasAnimatingWhenNotShown = true;
}
So I tried some debugs on it, and discovered that isShown() always returns false.
In order to play animation anyway, I should call LottieDrawable.playAnimation() directly, something like this:
fun LottieAnimationView.forcePlay() {
(drawable as? LottieDrawable)?.playAnimation()
}
Is this an intended behavior, or not?
@turastory Can you attach a project that reproduces this? isShown() might be false in onBind but the play call should be deferred until it is attached and will eventually return true.
In fact, there is a test for exactly this in the repo
https://github.com/airbnb/lottie-android/blob/master/LottieSample/src/androidTest/java/com/airbnb/lottie/samples/FragmentVisibilityTests.kt#L187
I have the same problem.
playAnimation inside onBindViewHolder does not work.
I only works if I post it on the main thread.
lav.post(() -> lav.playAnimation());
@venjirai what version of Lottie? And can you post a sample project if it's 3.0.7, if it's not, try that version
this problem is still present in v3.0.7
I have the same problem. Is there any update for this issue?
I have the same issue with v3.0.7
@abeade @HimanshuNarang @goemic @venjirai @turastory I would accept a PR for this. I don't have time to work on this issue at the moment.
@gpeal I don't know if this can help. But I've been debuging the issue and I saw that the problem is related with isShown() and RecyclerView as described here: https://github.com/airbnb/lottie-android/issues/1322#issuecomment-512261248
I think this is a duplicate of #1324 which has more info
Most helpful comment
I have the same problem.
playAnimation inside onBindViewHolder does not work.
I only works if I post it on the main thread.
lav.post(() -> lav.playAnimation());