material-components-android
material-components-android copied to clipboard
[Material Motion] Add predictive back seeking support for Material Motion Transitions
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.
wow,很不错的想法
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.
It's possible with the latest Fragment release: https://twitter.com/ianhlake/status/1710113646792314998?s=19
On Mon, 9 Oct 2023, 7:03 am Alexander Capehart, @.***> wrote:
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.
— Reply to this email directly, view it on GitHub https://github.com/material-components/material-components-android/issues/3619#issuecomment-1752161008, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACX5QX474DPLLOO3I5V4XILX6MIJJAVCNFSM6AAAAAA5VDR636VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJSGE3DCMBQHA . You are receiving this because you authored the thread.Message ID: <material-components/material-components-android/issues/3619/1752161008@ github.com>
@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.
@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?
@dsn5ft Is it now possible to use seeking with MaterialContainerTransform
? If not, should I open a new issue?
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).
@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?
Interesting - have you tried experimenting with FragmentTransaction#addToBackStack and MaterialContainerTransform + isSeekingSupported? I think addToBackStack is necessary for any predictive back to work with Fragments.
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: https://github.com/Pittvandewitt/material-components-android/commit/04bc7cbba8bdc157be5ba1e82e59d46c908cf5c6