Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LottieAnimationView doesn't restore the animation progress #2069

Closed
flaringapp opened this issue May 2, 2022 · 4 comments
Closed

LottieAnimationView doesn't restore the animation progress #2069

flaringapp opened this issue May 2, 2022 · 4 comments

Comments

@flaringapp
Copy link
Contributor

flaringapp commented May 2, 2022

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
@gpeal
Copy link
Collaborator

gpeal commented May 2, 2022

Would you like to put up a PR for this?

@flaringapp
Copy link
Contributor Author

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

@gpeal
Copy link
Collaborator

gpeal commented May 3, 2022

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

@ketanMuttha
Copy link

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

@gpeal gpeal closed this as completed Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants