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

Motion: Support predictive back in Container transform #102

Merged
merged 3 commits into from
Feb 27, 2024

Conversation

yaraki
Copy link
Member

@yaraki yaraki commented Feb 16, 2024

Change-Id: I9adb4a48be47761dc725f67e50be872a8865587a

Change-Id: I9adb4a48be47761dc725f67e50be872a8865587a
@yaraki yaraki requested a review from ashnohe February 16, 2024 07:11
override fun handleOnBackPressed() {
// This invokes the sharedElementReturnTransition, which is
// MaterialContainerTransform.
// TODO: It pops the scaleX/Y back to 1f. It would look nicer to retain the
Copy link

Choose a reason for hiding this comment

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

It's the transition after the back gesture is committed (e.g. MaterialContainerTransform for the sharedElementReturnTransition) that is popping the scale back to 1f?

Copy link
Member Author

Choose a reason for hiding this comment

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

Shared elements are copied into the target fragment before the transition animations start. It seems the scale and other transformations are dropped in the process. I tried using a set of ChangeTransform (it handles scaleX/Y) and MaterialContainerTransform, but it doesn't work for some reason.

I updated the formula below, and this is hardly unnoticeable. I think I don't care about this for now.

Copy link

Choose a reason for hiding this comment

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

with the updated formulas the reset is not very noticeable at all

thanks Yuichi!

// TODO: Consider handling backEvent.touchY to reflect the vertical movement.

// Scale down from 100% to 50%.
val scale = (2f - progress) * 0.5f
Copy link

@ashnohe ashnohe Feb 21, 2024

Choose a reason for hiding this comment

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

the formula is 1F - (0.1F * progress) because the max scale is 90%

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated. I suppose you mean the "min" scale.

override fun handleOnBackProgressed(backEvent: BackEventCompat) {
val progress = backEvent.progress
// Translate as far as 20% of finger movement.
val translation = progress * background.width * 0.2f
Copy link

@ashnohe ashnohe Feb 21, 2024

Choose a reason for hiding this comment

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

the formula for translationX is (progress * maxXShift) for the left edge and -(progress * maxXShift) for the right edge, where maxXShift is windowWidth / 20

e.g. https://github.com/android/platform-samples/tree/main/samples/user-interface/predictiveback#custom-progress-api-animation

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you. I didn't know we had a motion spec.

Change-Id: I8ccbc5267ecd3aae1c1179ff5a7036030896ba8a
@yaraki
Copy link
Member Author

yaraki commented Feb 21, 2024

pb.webm

Change-Id: I8f438fe1aa25dcd452872495dd132ed62fba030e
@ashnohe ashnohe self-requested a review February 22, 2024 17:16
Copy link

@ashnohe ashnohe left a comment

Choose a reason for hiding this comment

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

lgtm

@yaraki yaraki merged commit b9ab54c into main Feb 27, 2024
1 of 2 checks passed
@yaraki yaraki deleted the yaraki/motion-predictive branch February 27, 2024 05:57
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