PreCompose icon indicating copy to clipboard operation
PreCompose copied to clipboard

Sliding transition

Open sleeyax opened this issue 1 year ago • 8 comments

Is it possible to create a sliding transition between scenes? For example, when I have a bottom navigation bar and click from the item on the left to the right I would like a 'sliding in' transition from the right to the left and vice versa in the other direction. See this image as an illustration:

image

(Imagine the white part on top is an interesting screen filled with content and the part in purple is the bottom navigation bar)

sleeyax avatar Jan 26 '24 16:01 sleeyax

You can use slideInHorizontally as the transition but this only does one way not the vice versa. I wonder if you can just use Pager instead of NavHost for your bottom navigation?

Tlaster avatar Jan 27 '24 02:01 Tlaster

The Pager composable is exactly what I need in terms of transitioning between the different screens, but I'm not sure how to implement back presses and deeplinks with it. Both of those are easy to add with NavHost.

sleeyax avatar Jan 28 '24 00:01 sleeyax

PreCompose does not expose the BaskStackEntry in NavTransition, so currently is limited to only the one way transition, maybe I can expose the BaskStackEntry in NavTransition so you can make your own transition according to the BackStackEntry.

Tlaster avatar Jan 28 '24 04:01 Tlaster

Something like this replicates the Pager effect nicely, but yes then I'd need access to the BackStackEntry to determine the next tab/item:

navTransition = NavTransition(slideInHorizontally(initialOffsetX = {
    val currentTabIndex = tabs.indexOfFirst { it.route == currentRoute }
    val nextTabIndex = currentTabIndex + 1 // TODO: find real next tab index using BaskStackEntry
    if (currentTabIndex < nextTabIndex) {
        1000
    } else {
        -1000
    }
})),

One thing the Pager has is the out of the box ability to switch screens by swiping (instead of tapping the icons at the bottom). I suppose I'd need to implement that manually with the NavHost approach.

How do people actually implement this properly? I would think this is a common use-case.

sleeyax avatar Jan 28 '24 15:01 sleeyax

One thing the Pager has is the out of the box ability to switch screens by swiping (instead of tapping the icons at the bottom). I suppose I'd need to implement that manually with the NavHost approach.

How do people actually implement this properly? I would think this is a common use-case.

Well seems like current material guidelines does not like this behavior: https://m3.material.io/components/navigation-bar/guidelines#f2fb63e1-cc22-4853-acf6-b345e340fc47 , and I usually use Pager instead of NavHost to do this before, with some manual handing with back presses and deeplinks.

Tlaster avatar Jan 29 '24 00:01 Tlaster

Ah I see. Well it's not exactly a requirement in for the app I'm working on anyways, I was just curious how one would implement such a feature.

maybe I can expose the BaskStackEntry in NavTransition so you can make your own transition according to the BackStackEntry.

It would be nice if this were possible.

sleeyax avatar Jan 29 '24 08:01 sleeyax

This action is inconsistent with UX

hoangchungk53qx1 avatar Jan 31 '24 06:01 hoangchungk53qx1

This action is inconsistent with UX

What do you mean?

sleeyax avatar Jan 31 '24 10:01 sleeyax