Fix LottieAnimationView.setProgress called from the view init method prevents the progress from being restored from the saved state (#2072)
diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
index 037b6f9..166e59a 100644
--- a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
+++ b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
@@ -184,7 +184,10 @@
}
setImageAssetsFolder(ta.getString(R.styleable.LottieAnimationView_lottie_imageAssetsFolder));
- setProgress(ta.getFloat(R.styleable.LottieAnimationView_lottie_progress, 0));
+
+ boolean hasProgress = ta.hasValue(R.styleable.LottieAnimationView_lottie_progress);
+ setProgressInternal(ta.getFloat(R.styleable.LottieAnimationView_lottie_progress, 0f), hasProgress);
+
enableMergePathsForKitKatAndAbove(ta.getBoolean(
R.styleable.LottieAnimationView_lottie_enableMergePathsForKitKatAndAbove, false));
if (ta.hasValue(R.styleable.LottieAnimationView_lottie_colorFilter)) {
@@ -294,7 +297,7 @@
setAnimation(animationResId);
}
if (!userActionsTaken.contains(UserActionTaken.SET_PROGRESS)) {
- setProgress(ss.progress);
+ setProgressInternal(ss.progress, false);
}
if (!userActionsTaken.contains(UserActionTaken.PLAY_OPTION) && ss.isAnimating) {
playAnimation();
@@ -996,7 +999,15 @@
}
public void setProgress(@FloatRange(from = 0f, to = 1f) float progress) {
- userActionsTaken.add(UserActionTaken.SET_PROGRESS);
+ setProgressInternal(progress, true);
+ }
+
+ private void setProgressInternal(
+ @FloatRange(from = 0f, to = 1f) float progress,
+ boolean fromUser) {
+ if (fromUser) {
+ userActionsTaken.add(UserActionTaken.SET_PROGRESS);
+ }
lottieDrawable.setProgress(progress);
}