https://kotlinlang.org logo
#compose
Title
# compose
v

vide

09/19/2023, 4:51 PM
Is there a way to override animations for just a single navigation call? My best idea at the moment would to add a nav argument to every single route and check it's value in the transition lambda, which is quite clumsy and not very maintainable.
something like this:
Copy code
@OptIn(ExperimentalAnimationApi::class)
fun NavGraphBuilder.composableNoAnimation(
    route: String,
    arguments: List<NamedNavArgument> = emptyList(),
    deepLinks: List<NavDeepLink> = emptyList(),
    enterTransition: (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?)? = null,
    exitTransition: (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?)? = null,
    popEnterTransition: (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?)? = enterTransition,
    popExitTransition: (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?)? = exitTransition,
    content: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit
) {
    composable(
        "$route${if (arguments.isEmpty()) "?" else "&"}noAnimation={noAnimation}",
        arguments + navArgument("noAnimation") { defaultValue = false; type = NavType.BoolType },
        deepLinks,
        enterTransition,
        exitTransition,
        popEnterTransition,
        popExitTransition,
        content
    )
}
Thinking about this a bit more, the argument would still be saved on the back stack, so it wouldn't work 😕