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

Add a MotionLayout that animates between changing ConstraintSets #359

Merged
merged 1 commit into from Jul 30, 2021

Conversation

bentrengrove
Copy link
Contributor

This PR adds a MotionLayout that animates between changing ConstraintSets. This provides an easy way to animate layouts that change without having to worry about updating a progress variable yourself.

On recomposition if the constraint set has changed the changes will be animated using the animationSpec. On completion of the animation the finishListener will fire. This mimics the animateValueAsState API that already exists in Compose.

I changed MotionExample1 to use the new API and to provide an example of it's usage.

Happy to make changes and thanks for your help!

Copy link
Collaborator

@camaelon camaelon left a comment

Choose a reason for hiding this comment

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

Thanks! I think that makes sense, with one caveat, could we have it folded in the MotionLayout function that takes two constraintsets instead? with moving the 2nd constraintset parameter as optional. This way we ensure that API doesn't diverge too much (i.e not certain we should have animationSpec / finishedListener here)

@camaelon camaelon requested a review from jafu888 July 30, 2021 00:49
@bentrengrove
Copy link
Contributor Author

Folding it in to one would also involve making the progress parameter optional as well somehow which could be confusing.

Changing the animationSpec is also something I think that is quite useful, I almost didn't include the finishListener but just thought it would be good to match the other APIs for consistency. Happy to remove it if you don't think it's needed.

@camaelon
Copy link
Collaborator

Ok, after discussing with John, let's:

  • let's name it as ConstraintLayout, not MotionLayout
  • move it into the current ConstraintLayout function that takes a constraintset, and add an animate = false parameter

@bentrengrove
Copy link
Contributor Author

bentrengrove commented Jul 30, 2021 via email

@camaelon
Copy link
Collaborator

I think if we merge it in that ConstraintLayout function, it's probably fine to have the animationspec and simple callback as optional parameters.

@camaelon camaelon merged commit d7e308f into androidx:main Jul 30, 2021
@bentrengrove bentrengrove deleted the ml_single_constraint branch August 1, 2021 23:25
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.

None yet

2 participants