https://kotlinlang.org logo
Title
a

andrew

05/04/2023, 7:23 PM
Out of curiosity, will we be able to hook into the predictive back animation system in compose?
s

Stylianos Gakis

05/04/2023, 7:51 PM
Not sure exactly what that means, but considering that the androidx.navigation which is for compose does support the predictive back gestures then I suppose the answer is yes? Isn’t it all basically working around the OnBackPressedDispatcher, which you can retrieve in compose using LocalOnBackPressedDispatcherOwner?
a

andrew

05/04/2023, 7:55 PM
I mean the animation that you get between activities and Android 14, I know it's already technically supported under the hood
I.e. you can peek behind to the previous activity
s

Stylianos Gakis

05/04/2023, 9:26 PM
Yes, but since androidx.navigation for compose already does this atm, I am not sure what you mean by “hook into the predictive back animation system in compose”. It’s probably me misunderstanding you here 🤔
a

andrew

05/04/2023, 9:27 PM
See the screenshot above, I was in another screen in settings, but swiping back allows me to peek the previous screen
Are they two separate composables?
i.e. no activities?
s

Stylianos Gakis

05/04/2023, 9:32 PM
Gimme a sec to triple check everything so that I am not lying to you 😅 I was in fact lying to you
a

andrew

05/04/2023, 9:32 PM
Because this looks exactly like the activity transition 😛
s

Stylianos Gakis

05/04/2023, 9:33 PM
Yeah I now remembered that we do still have some pesky activities lying around in this flow in our app, so I may be showing the wrong thing. And that I could be wrong this entire time. Gimme a sec 😵
a

andrew

05/04/2023, 9:34 PM
Gotcha, because that transition is what I'd like to see between two composables using any arbitrary navigation library
However, I just realized, we're intercepting the event with the listener
So this might need to be performed manually!
s

Stylianos Gakis

05/04/2023, 9:40 PM
I was just very confidently incorrect here ☠️ :face_with_open_eyes_and_hand_over_mouth: We are using androidx navigation, and I had seen this behavior before in our app, so in my brain I was like yes, it works. But I forgot that that transition was still between activities right now.
i

Ian Lake

05/04/2023, 9:51 PM
It was Activity 1.8.0-alpha01 that added Android 14's new progress APIs to
OnBackPressedCallback
instances - that's what allows your app to get the gesture start callback and react to finger movements to do that Predictive animation
There's three bits remaining to be done: 1.
BackHandler
is going to be getting this same ability to get start and progress events, which will mean any composable or navigation library can interact with Predictive Back in-app progress on Android 14+ 2.
AnimatedContent
and friends are going to get new APIs to handle this in between state (e.g., instead of just a
targetState
, it would let you update the
progress
between two states) - this is what you'd actually do with the progress callbacks
BackHandler
gives you 3.
NavHost
will update its
BackHandler
to call the new APIs on
AnimatedContent
, thus giving you predictive back animations based on the transitions you've set for free
a

andrew

05/04/2023, 10:20 PM
This is exciting! Thank you for the update Ian!
Glad to hear it gets first class support!
s

Stylianos Gakis

05/06/2023, 11:29 PM
What’s the status on some
AnimatedContent
which supports setting a progress too? Is there some issue that we can track, or some work that is already happening atm? Feels like that is the biggest of the pieces missing in this puzzle right?
a

Alex Vanyo

05/07/2023, 7:38 PM
1 and 2 can be achieved from the Activity 1.8 APIs with a bit of work, to a pretty nice effect. This is nothing official though, just me independently experimenting with the APIs:
a

andrew

05/07/2023, 7:38 PM
That is awesome 😎😎
Imagine with official API support
i

Ian Lake

05/07/2023, 7:41 PM
1 is just convenience at the Activity Compose layer, the underlying layer is indeed already there. And yep, if you pick a different layer than AnimatedContent, the underlying Compose animation APIs can already be driven by gestures
a

andrew

05/07/2023, 7:42 PM
I figure as much, but having high level APIs for convenience makes it accessible for everyone, too. I definitely don't mind digging for now, seeing that it is in fact possible!
a

Alex Vanyo

05/07/2023, 7:45 PM
The version of 1 I'm using is here, and part of my implementation of 2 is here