lottie-android
lottie-android copied to clipboard
LottieAnimationView doesn't restore the animation progress
Describe the bug
Since v5.0.1 LottieAnimationView
has a simple logic to prevent onRestoreInstanceState
from overriding user-provided values. Those changes were introduced in this PR.
So the issue is about progress
that won't be restored if user sets a value before state restoration - same logic as for other parameters. However, the progress is always set in the view init
function called from a constructor. Therefore, progress restoration is always ignored.
Progress setter:
public void setProgress(@FloatRange(from = 0f, to = 1f) float progress) {
userActionsTaken.add(UserActionTaken.SET_PROGRESS);
lottieDrawable.setProgress(progress);
}
Progress restoration:
if (!userActionsTaken.contains(UserActionTaken.SET_PROGRESS)) {
setProgress(ss.progress);
}
Setting progress in the init
function:
setImageAssetsFolder(ta.getString(R.styleable.LottieAnimationView_lottie_imageAssetsFolder));
setProgress(ta.getFloat(R.styleable.LottieAnimationView_lottie_progress, 0));
enableMergePathsForKitKatAndAbove(ta.getBoolean(
R.styleable.LottieAnimationView_lottie_enableMergePathsForKitKatAndAbove, false));
Steps To Reproduce
Steps to reproduce the behavior:
- Open Fragment A with
LottieAnimationView
proving any animation (raw resource) - Play animation (doesn't matter if it finishes or not)
- Replace Fragment A with Fragment B (Fragment A saves it's state)
- Go back from Fragment B to Fragment A (Fragment A restores it's state)
- Animation progress is not restored
Would you like to put up a PR for this?
Sure. How about preventing userActionsTaken.add(UserActionTaken.SET_PROGRESS)
from being called if setProgress()
is called from the constructor?
@flaringapp I'd have to look into it in more detail but seems like a reasonable start.
We are also facing a similar issue. is there any resolution?