-1

I want to add screen transition animation using Compose Destinations library for Navigation. here is the code While calling DestinationsNavHost() in the main composable screen without transition animation:

setContent {
        DestinationsNavHost(navGraph = NavGraphs.root)
    }
Jahid Hasan
  • 439
  • 1
  • 4
  • 4

1 Answers1

0

While calling DestinationsNavHost() in the main composable screen, do this:

        val navController = rememberAnimatedNavController()

        val navHostEngine = rememberAnimatedNavHostEngine(
            navHostContentAlignment = Alignment.TopCenter,
            rootDefaultAnimations = RootNavGraphDefaultAnimations.ACCOMPANIST_FADING,
            defaultAnimationsForNestedNavGraph = mapOf(
                NavGraphs.root to NestedNavGraphDefaultAnimations(
                    enterTransition = { slideInHorizontally() },
                    exitTransition = { slideOutHorizontally() }
                ),
            ))
        DestinationsNavHost(
            navGraph = NavGraphs.root,
            navController = navController,
            engine = navHostEngine
        )
Jahid Hasan
  • 439
  • 1
  • 4
  • 4