Resume animations if the drawable gets reset (#1712)
diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
index 18ff5c8..01757a5 100644
--- a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
+++ b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
@@ -566,8 +566,7 @@
return;
} else if (!isNewComposition) {
// The current drawable isn't lottieDrawable but the drawable already has the right composition.
- setImageDrawable(null);
- setImageDrawable(lottieDrawable);
+ setLottieDrawable();
}
// This is needed to makes sure that the animation is properly played/paused for the current visibility state.
@@ -958,8 +957,7 @@
public void setScale(float scale) {
lottieDrawable.setScale(scale);
if (getDrawable() == lottieDrawable) {
- setImageDrawable(null);
- setImageDrawable(lottieDrawable);
+ setLottieDrawable();
}
}
@@ -1162,6 +1160,18 @@
lottieOnCompositionLoadedListeners.clear();
}
+ private void setLottieDrawable() {
+ boolean wasAnimating = isAnimating();
+ // Set the drawable to null first because the underlying LottieDrawable's intrinsic bounds can change
+ // if the composition changes.
+ setImageDrawable(null);
+ setImageDrawable(lottieDrawable);
+ if (wasAnimating) {
+ // This is necessary because lottieDrawable will get unscheduled and canceled when the drawable is set to null.
+ lottieDrawable.resumeAnimation();
+ }
+ }
+
private static class SavedState extends BaseSavedState {
String animationName;
int animationResId;