accompanist icon indicating copy to clipboard operation
accompanist copied to clipboard

[Navigation] Add mechanism for specifying zOrder in transitions

Open hvisser opened this issue 2 years ago • 14 comments

Description AnimatedContent supports setting a z-order on the transitions which can be useful for navigation transitions. For example when trying to implement a "slide from bottom" transition, the enter transition slides over the exiting composable (good) but the reverse will slide the exiting (popping) composable under the entering composable. If specifying the z-order could help to explicitly set the desired order for the composables.

hvisser avatar Feb 08 '22 19:02 hvisser

How would you expect z-order to be exposed? As a property on each composable destination? Something else?

ianhanniballake avatar Feb 09 '22 05:02 ianhanniballake

I think exposing it (somehow) on the definition of the transition would make sense. In the context of the transition (initial and target) I'd know what ordering I want...That might mean the transition block is no longer an AnimatedContentScope but an extension of it maybe?

hvisser avatar Feb 09 '22 11:02 hvisser

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Mar 18 '22 03:03 github-actions[bot]

I have the same issue. Having it inside transition definition would work I suppose.

Having it for each composable destination wouldn't work. If we take @hvisser example of "slide from bottom"

  • A -> B. B on top of A
  • A, B -> C. C on top of B
  • A, B <- C. C on top B
  • A <- B. B on top of A

mvarnagiris avatar Mar 25 '22 08:03 mvarnagiris

any idea if this is something being worked on. it would be great to have.

joshrvezy avatar Apr 13 '22 06:04 joshrvezy

I think targetContentZIndex should somehow depend on screen index in backstack

vadimpikha avatar Apr 14 '22 08:04 vadimpikha

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar May 15 '22 03:05 github-actions[bot]

Same issue for me, I just copied AnimatedNavHost and modified like this

val zIndex = visibleBackStack.indexOf(backStackEntry).toFloat()

And then changed AnimatedContent

transitionSpec = { finalEnter(this) with finalExit(this) }, to

transitionSpec = { 
ContentTransform(
   targetContentEnter = finalEnter(this),
   initialContentExit = finalExit(this),
   targetContentZIndex = zIndex,
},

SergKlimov avatar May 27 '22 10:05 SergKlimov

@SergKlimov Thats cool solution, but sadly, I tried to copy the AnimatedNavHost.kt content to my local package and it wont even compile :)

Can you give tip how you do it ?

Thanks

x4080 avatar Jun 25 '22 21:06 x4080

@SergKlimov Never mind, we must also copy file AnimatedComposeNavigator

Edit : I cant find visibleBackStack variable, is your AnimatedNavHost have that variable ? Edit2 : Just copying (without modifying anything), make screen blank, dont know what's going on now :) Edit3 : I got success by copying all the files from accompanist navigation, but still cannot find the variable visibleBackStack

x4080 avatar Jun 25 '22 21:06 x4080

@x4080 https://github.com/google/accompanist/issues/1160

transition.AnimatedContent(modifier, transitionSpec = {
            val targetIndex = navController.backQueue.indexOf(targetState).takeIf { it >= 0 }
                ?: navController.backQueue.size
            ContentTransform(
                targetContentEnter = finalEnter(this),
                initialContentExit = finalExit(this),
                targetContentZIndex = targetIndex.toFloat()
            )
        }

codingfd avatar Jul 05 '22 11:07 codingfd

@codingfd thanks

x4080 avatar Jul 16 '22 21:07 x4080

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Aug 16 '22 03:08 github-actions[bot]

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Sep 15 '22 04:09 github-actions[bot]

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Oct 20 '22 03:10 github-actions[bot]

Maybe it's time to get rid of stale bot?

hvisser avatar Oct 20 '22 07:10 hvisser

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 20 '22 03:11 github-actions[bot]

We've added what we believe is the correct z-ordering in #1384, released as part of v0.27.1 and aren't planning on offering any ability to override it at this time. Please upgrade and try it out!

ianhanniballake avatar Nov 20 '22 05:11 ianhanniballake

We've added what we believe is the correct z-ordering in #1384, released as part of v0.27.1 and aren't planning on offering any ability to override it at this time. Please upgrade and try it out!

Hey @ianhanniballake , I had a try but it's not good. I tried the navigation route: A -> B -> C -> B -> A, when the screen transition running from B -> A, the zIndex looks not good. Could you have a try?

ommiao avatar Dec 17 '22 04:12 ommiao

Sounds like #1411, please follow along there.

ianhanniballake avatar Dec 17 '22 04:12 ianhanniballake