skinnyhrit
skinnyhrit

Reputation: 1

Navigation destination is being called 4 times for some reason in jetpack compose?

This is my NavGraph, here the destination "VerificationScreen/{verificationId}" is being called 4 times thus creating the viewmodel 4 times. What could be reason for this?

@Composable
fun NavGraph(
    navController: NavHostController,
    startDestination:String
) {
    NavHost(navController = navController,startDestination) {

        composable("LogInOrSignUpScreen") {


            LoginOrSignUpScreen(
                onNavigateToVerificationScreen = { verificationId ->

                    navController.navigate("VerificationScreen/$verificationId")
                }
            )

        }

        composable("VerificationScreen/{verificationId}") {backStackEntry ->
            BackHandler(true) {

            }
            val viewModel: VerificationScreenViewModel = VerificationScreenViewModel(
                backStackEntry.arguments?.getString("verificationId")
            )

            //println(backStackEntry.arguments?.getString("verificationId"))

            VerificationScreen(viewModel)
        }
    }
}

I have checked the callback to onNavigateToVerificationScreen is only being done once. Please let me know if you need additional information.

Upvotes: 0

Views: 70

Answers (0)

Related Questions