Lottie-android: Animating item changes in RecyclerView doesn't work

Created on 24 Jun 2019  路  10Comments  路  Source: airbnb/lottie-android

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?

Help wanted

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());

All 10 comments

@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.

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

Was this page helpful?
0 / 5 - 0 ratings