1

So I use this library com.google.accompanist:accompanist-navigation-animation for Animated Navigation in Compose.

For all screens I set the following animations when I navigate between them, and it works fine with NavController.navigate(route, ...) and NavController.navigateUp():

composable(
    enterTransition = {
        slideIntoContainer(
            towards = AnimatedContentScope.SlideDirection.Left,
            animationSpec = tween(400)
        )
    }
    exitTransition = {
        slideOutOfContainer(
            towards = AnimatedContentScope.SlideDirection.Left,
            animationSpec = tween(400)
        )
    },
    popEnterTransition = {
        slideIntoContainer(
            towards = AnimatedContentScope.SlideDirection.Right,
            animationSpec = tween(400)
        )
    },
    popExitTransition = {
        slideOutOfContainer(
            towards = AnimatedContentScope.SlideDirection.Right,
            animationSpec = tween(400)
        )
    },
    route = route,
    arguments = arguments,
    deepLinks = deepLinks,
    content = content
)

But it uses some different animation for changes with startDestination:

val startDestination = when (userStateUI) {
    UserStateUI.LOADING -> return@AppBackground
    UserStateUI.ON_BOARDING -> OnBoardingDestination.route
    UserStateUI.UNSIGNED -> WelcomeDestination.route
    UserStateUI.SIGNED -> DashboardDestination.route
}

Scaffold(
    ...
) {
    AnimatedNavHost(
        startDestination = startDestination,
        ...
    ) {
        ... screens
    }

it doesn't use animations I set at NavGraphBuilder.composable function

the animation triggers from left top corner (like diagonal animation instead of my set horizontal slide animations)

What can I do to get the same animations for all possible logic when screens change?

Updated

I tried to set the same animations for AnimatedNavHost but it didn't change anything:

AnimatedNavHost(
    ...
    startDestination = startDestination,
    enterTransition = ...
    exitTransition = ...
    popEnterTransition = ...
    popExitTransition = ...
) { ...
user924
  • 8,146
  • 7
  • 57
  • 139

0 Answers0