Is there a way to run a callback when a composable is finished animating it's transition in? In my u...
a
Is there a way to run a callback when a composable is finished animating it's transition in? In my use case I have a BottomSheetScaffold with a constant peekheight. However, when We use an animation, to navigate to the screen, it looks off as the bottom sheet slides towards the bottom nav bar, with a visible gap to begin with in between. I would like to show the sheet after the transition is done animating in.
d
There's usually a finished listener
a
Do you happen to have links to documentation?
d
You could check
Transition#currentState
against
Transition#targetState
to know when the animation is finished.
a
Pardon my inexperience, but how would I be able to even get the current transition's state? I can see that AnimatedContentScope holds the transition property, but I have no clue how to get a reference to it.
d
Are you using
AnimatedContent
or
AnimatedNavHost
?
a
I am using
AnimatedNavHost
d
Please feel free to file a feature request for a way to observe animation state in
AnimatedNavHost
i
I'm a bit confused on what animation you're talking about? Opening a bottom sheet wouldn't animate your underlying content at all and your BottomSheetLayout would want to be above your Scaffold that has your bottom nav bar anyways (so it would already be above it). Can you share a video or some code to help us better understand what you're trying to do and how you've structured your code?
a
@Ian Lake As they say a picture speaks a thousand words, so I probably should of started out with this. As you can see here, the bottom sheet starts out smaller due to the scaleIn animation, but I've realized this is due to me not having the BottomSheetScaffold as the outer scaffold. Currently, that bottomsheet is an inner scaffold used only in that composable destination. I'll try moving it out to the external scaffold and simply showing it based on the current destination state.
i
If your bottom sheet is a separate screen entirely, you might consider using the support specifically for bottom sheet destinations: https://google.github.io/accompanist/navigation-material/
a
I have considered that library, but my use case is of a persistent bottom sheet such as this, in which both elements needs to be interactable with at the same time. So a modal sheet doesn't seem like the right tool to use.
i
Ah, yeah, it wouldn't be appropriate for that kind of use case
a
Do you have an idea of how I could wrap a singular Scaffold to have both a bottom navigation bar and a Bottomsheet? Bottomsheet scaffold does not support a bottom navigation bar composable slot.
i
Wouldn't you just put one inside the other? They're just Composables, like any other
a
Good point, got the nested scaffolds working showing the sheet based on current destination, but getting all the animations to play nicely with each other is another pain