Hey guys, what is correct behaviour of loading nex...
# compose
v
Hey guys, what is correct behaviour of loading next compose function to using compose navigation. I am using State Ui event to emit ui event. My
navigateToResultScreen
is calling twice with screen flicks. Is it correct behaviour? MainActivity.kt
Copy code
when (val state = viewModel.stateResultFetchState.collectAsState().value) {
    is ResultFetchState.OnSuccess -> {
        LaunchedEffect(Unit) {
            navigateToResultScreen(state.nearestResult)
        }
    }
    is ResultFetchState.IsLoading -> {
        LoadingFunction()
    }
    is ResultFetchState.OnError,
    is ResultFetchState.OnEmpty -> {
        ActivityContent(viewModel)
    }
}
NavigationGraph.kt
Copy code
@Composable
internal fun NavigationGraph() {
    val navController = rememberNavController()
    NavHost(navController = navController, startDestination = ScreenRoute.Home.route) {
        composable(ScreenRoute.Home.route) {
            SetupMainActivityView { nearestResult ->
                val nearestResultJson = Uri.encode(Json.encodeToString(nearestResult))
                navController.navigate(ScreenRoute.Result.route + "/$nearestResultJson")
            }
        }

        composable(
            ScreenRoute.Result.route + "/{$NEAREST_RESULT_JSON}",
            arguments = listOf(
                navArgument(NEAREST_RESULT_JSON) { type = NearestResultParamType() }
            )
        ) { backStackEntry ->
            ResultScreen(navController, backStackEntry.arguments?.getParcelableArrayList(NEAREST_RESULT_JSON))
        }
    }
}