Vivek Modi
07/22/2022, 10:03 AMnavigateToResultScreen
is calling twice with screen flicks. Is it correct behaviour?
MainActivity.kt
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)
}
}
@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))
}
}
}