Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Navigation Animation] Add contentZIndex for AnimatedNavHost #1282

Closed
wants to merge 1 commit into from

Conversation

ommiao
Copy link

@ommiao ommiao commented Aug 6, 2022

The problem

I found a weird issue is that the back layer covers the front layer when pop back stack like this:

old.mp4

Why and How

The reason is that the z-indices of all layers are same as default. I add contentZIndex for NavGraphBuilder.navigation() and pass it to AnimatedContent in AnimatedNavHost.

Now it looks good:

new.mp4

Here is my test code:

AnimatedNavHost(
    navController = navHostController,
    startDestination = Screen.Homepage.route,
    enterTransition = {
        slideIntoContainer(
            towards = AnimatedContentScope.SlideDirection.Left,
            animationSpec = tween(800)
        )
    },
    exitTransition = {
        slideOutOfContainer(
            towards = AnimatedContentScope.SlideDirection.Left,
            animationSpec = tween(800),
            targetOffset = { it / 2 }
        )
    },
    popEnterTransition = {
        slideIntoContainer(
            towards = AnimatedContentScope.SlideDirection.Right,
            animationSpec = tween(800),
            initialOffset = { it / 2 }
        )
    },
    popExitTransition = {
        slideOutOfContainer(
            towards = AnimatedContentScope.SlideDirection.Right,
            animationSpec = tween(800)
        )
    }
) {
    composable(route = Screen.Homepage.route) {
        HomepageScreen()
    }
    composable(route = Screen.Theme.route) {
        ThemeScreen(theme = theme) { theme = it }
    }
}

@google-cla
Copy link

google-cla bot commented Aug 6, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@v1kee
Copy link

v1kee commented Aug 11, 2022

I was looking for a solution to this yesterday, thanks! Hope to be able to use it soon!

@ommiao
Copy link
Author

ommiao commented Aug 12, 2022

I was looking for a solution to this yesterday, thanks! Hope to be able to use it soon!

@v1kee No worries. The workaround is that clone the code of navigation with animation and do the changes like this PR. It's won't take much effort.

@maurycyw
Copy link

Great solution! Could we just rely on the order within the backstack instead? having a z index override could still be useful tho.

@ommiao
Copy link
Author

ommiao commented Sep 11, 2022

Great solution! Could we just rely on the order within the backstack instead? having a z index override could still be useful tho.

@maurycyw That's great! Now I use the orders of backQueue as z-index.

@ommiao
Copy link
Author

ommiao commented Oct 7, 2022

@jbw0033 Hi, any updates?

@ianhanniballake
Copy link
Collaborator

As explained in this comment:

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants