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

Fix LottieAnimationView.setProgress called from the view init method prevents the progress from being restored from the saved state #2072

Merged
merged 2 commits into from
Nov 26, 2022
Merged

Conversation

flaringapp
Copy link
Contributor

See #2069

@gpeal
Copy link
Collaborator

gpeal commented May 24, 2022

If you were to set an initial progress but then were to subsequently change it or play the animation, wouldn't restoration overwrite the saved progress with what is set in XML?

@flaringapp
Copy link
Contributor Author

@gpeal I think it makes sense to check whether there is a progress attribute set in the XML and if yes - treat it as user-provided and prevent saved state restoration from overwriting the progress value.

Also it will be nice to provide an option to restore saved progress even if the progress is set in the XML. I suggest adding an attribute named lottie_useRestoredProgress with default value false. So if user wants to explicitly restore progress state instead of starting the animation from the specified progress, he can use this attribute. Behind the scenes it'll affect the setProgressInternal called from attributes init method. If the attribute is true, then we won't save the UserActionTaken.SET_PROGRESS flag (fromUser = false) or do exactly the opposite with default false value

@gpeal
Copy link
Collaborator

gpeal commented Jun 27, 2022

@flaringapp I'm still trying to wrap my head around the exact use case that's failing here. Could you create a sample project that highlights the issue?

@flaringapp
Copy link
Contributor Author

@gpeal Please take a look at this sample project
In scope of this issue I expect the animation to persist it's previous progress when a fragment is restored

Copy link
Collaborator

@gpeal gpeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay thanks for the sample. I've been very busy lately but found some time to take a look at this. let's move forward with your implementation as-is. Just swap the parameter order here but other than that, LGTM. Thanks for doing this.

setProgressInternal(true, progress);
}

private void setProgressInternal(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you swap the parameter order here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gpeal Done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've rebased on master as well

@LottieSnapshotBot
Copy link

Snapshot Tests
28: Report Diff

@gpeal gpeal merged commit 9dde5b0 into airbnb:master Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants