lottie-android icon indicating copy to clipboard operation
lottie-android copied to clipboard

LottieAnimationView doesn't restore the animation progress

Open flaringapp opened this issue 2 years ago • 4 comments

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:

  1. Open Fragment A with LottieAnimationView proving any animation (raw resource)
  2. Play animation (doesn't matter if it finishes or not)
  3. Replace Fragment A with Fragment B (Fragment A saves it's state)
  4. Go back from Fragment B to Fragment A (Fragment A restores it's state)
  5. Animation progress is not restored

flaringapp avatar May 02 '22 14:05 flaringapp

Would you like to put up a PR for this?

gpeal avatar May 02 '22 15:05 gpeal

Sure. How about preventing userActionsTaken.add(UserActionTaken.SET_PROGRESS) from being called if setProgress() is called from the constructor?

flaringapp avatar May 03 '22 17:05 flaringapp

@flaringapp I'd have to look into it in more detail but seems like a reasonable start.

gpeal avatar May 03 '22 22:05 gpeal

We are also facing a similar issue. is there any resolution?

ketanMuttha avatar Sep 02 '22 20:09 ketanMuttha