admin管理员组

文章数量:1129156

I'm using Jetpack Compose's enterTransition to animate navigation between screens. The transition works fine in authGraph (you can find its structure on homeGraph below. It is the same.), but it doesn't apply when navigating to the ChatScreen in the homeGraph. Why isn't the enterTransition applied to the ChatScreen in the homeGraph?

I tried that the enterTransition works for other screens in a different graph. There is normally multiple ways to call ChatRoute with arguments but I tried to remove all the arguments if the problem is about serialization but still didn't work. Removed current transition to just use fadeIn() but didn't work.

The NavHost that manages multiple graphs:

@Composable
fun AppNavHost(appState: MedicineAIAppState, startDestination: String) {

    val navController = appState.navController

    NavHost(
        navController = navController,
        startDestination = startDestination.toKClassRoute(),
    ) {
        onboardingGraph(navController)
        authGraph(navController)
        homeGraph(navController)
    }
}

HomeGraph includes the ChatScreen, which is the screen where the transition doesn't work. Also AuthGraph has the same structure with this and same navigation works there.

@Serializable data object HomeGraph

fun NavGraphBuilder.homeGraph(navController: NavHostController) {
    navigation<HomeGraph>(startDestination = HomeRoute) {
        homeScreen(onStartChatClick = navController::navigateToChatWithoutInbox)
        inboxScreen(
            onNewChatClick = navController::navigateToChatWithEmpty,
            onChatClick = navController::navigateToChatWithInboxAndTopic
        )
        chatScreen(
            onBackClick = navController::popBackStack,
            onChatCleared = navController::navigateToInbox
        )
        profileScreen()
    }
}

This is the ChatScreen definition with the enterTransition:

fun NavGraphBuilder.chatScreen(
    onBackClick: () -> Unit,
    onChatCleared: () -> Unit
) {
    composable<ChatRoute>(
        enterTransition = {
            fadeIn(
                animationSpec = tween(300, easing = LinearEasing)
            ) + slideIntoContainer(
                animationSpec = tween(300, easing = EaseIn),
                towards = AnimatedContentTransitionScope.SlideDirection.Start
            )
        },
    ) {
        ChatScreen(
            onBackClick = onBackClick,
            onChatCleared = onChatCleared
        )
    }
}

本文标签: androidCompose Navigation Doesn39t Apply the enterTransition AnimationStack Overflow