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

[Material Motion] Add predictive back seeking support for Material Motion Transitions #3619

Open
Chozzle opened this issue Oct 6, 2023 · 10 comments · May be fixed by #4248
Open

[Material Motion] Add predictive back seeking support for Material Motion Transitions #3619

Chozzle opened this issue Oct 6, 2023 · 10 comments · May be fixed by #4248

Comments

@Chozzle
Copy link

Chozzle commented Oct 6, 2023

Is your feature request related to a problem? Please describe.
Now that Android 14 is released, the default transitions provided by Material Motion should support predictive back to take the standard navigation transitions to the next level.

Describe the solution you'd like
Allow all Material Motion Transitions to be seekable via predictive back.

The below video shows that when swiping back, the animation doesn't start until I release my finger, so predictive back animations aren't yet working.

@jienian
Copy link

jienian commented Oct 8, 2023

wow,很不错的想法

@OxygenCobalt
Copy link
Contributor

OxygenCobalt commented Oct 8, 2023

I'm not one of the maintainers, but I don't even know if this is possible with the current fragment architecture. I think existing fragment transitions just transition between the last drawn frame of the source fragment and the first frame of the destination fragment. This would require both fragments to be drawn simultaneously during a transition, as otherwise there would be jank and pop-in due to the fragments not being able to update their visual state during the gesture. I could be wrong though.

@Chozzle
Copy link
Author

Chozzle commented Oct 8, 2023 via email

@Chozzle
Copy link
Author

Chozzle commented Jan 8, 2024

@afohrman Are there any plans to enable predictive back for Activity transitions? I'm not sure if that is possible from this androidx library, or requires platform changes. If not, developers are left in a difficult position trying to add predictive back across a large legacy app, where migrating to single activity is not an option. IF manufacturers support predictive back with their default OS transitions it might be OK, but I'm doubtful that will happen.

@dsn5ft
Copy link
Contributor

dsn5ft commented Jan 8, 2024

@Chozzle Unfortunately there are no such plans as far as I know - the isSeekingSupported() API was only added to AndroidX Transitions. In order for us to enable predictive back/seeking for Activity transitions I think we would need the framework to add a similar method/support to platform transitions.

If you are interested in this, can you file a feature request?

@Pittvandewitt
Copy link
Contributor

@dsn5ft Is it now possible to use seeking with MaterialContainerTransform? If not, should I open a new issue?

@dsn5ft
Copy link
Contributor

dsn5ft commented Jan 9, 2024

Unfortunately the AndroidX Fragment library doesn't support predictive back for shared element transitions. You can file a request for them here (or check if there is an existing request to +1).

@Pittvandewitt
Copy link
Contributor

Pittvandewitt commented Jan 11, 2024

@dsn5ft I did file a request and their response was that the fragment library does actually support predictive back for shared element transitions: https://issuetracker.google.com/issues/319531491#comment2
I have been playing around modifying the code of the demo catalog but I was unable to get things to work, even with the suggestions regarding postponing transitions and overriding isSeekingSupported in MaterialContainerTransform. Where should we go from here?

@dsn5ft dsn5ft reopened this Jan 12, 2024
@dsn5ft
Copy link
Contributor

dsn5ft commented Jan 12, 2024

Interesting - have you tried experimenting with FragmentTransaction#addToBackStack and MaterialContainerTransform + isSeekingSupported? I think addToBackStack is necessary for any predictive back to work with Fragments.

@Pittvandewitt
Copy link
Contributor

A few observations I have made:
Overriding isSeekingSupported in MaterialContainerTransform and publishing it to mavenLocal for using it in my own project was enough to make the shared element transition work, but an enterTransition must be set for the fragment you're navigating to.
MaterialContainerTransform needs isSeekingSupported set to true when using fragment 1.7.0-SNAPSHOT and transition 1.5.0-SNAPSHOT, else a crash will occur with these library versions.

Although I was able to make the animation work, some undefined behaviour occurs where sometimes the animation is not performed upon navigation and the navigation icon remains visible when the home destination is displayed. It happens for example when the back gesture is performed while the transition is still in progress. I am aware this sounds like something for the navigation / fragment team, but the animation not playing can be reproduced in the catalog sample where these libraries are not used. This is the code I am currently working with: Pittvandewitt@04bc7cb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment