KotlinLeaner
02/27/2023, 10:09 PMdewildte
02/27/2023, 11:13 PMKotlinLeaner
03/01/2023, 12:22 AMval uistate = loading, error, fetching
Some conditions in the viewmodel to emit the state
fun sendLoadingState{
If ()
Uistate = Loading
else()
}
In compose function
I am calling sendLoadingState
In Launcheffect.
When(viewmodel.uistate){
Loading -> LoadingScreen()
.. // more code in here
}
I see in the documentation of navigation to use navigateUp.
navigateUp
?
fun sendLoadingState(navigation){
If ()
navigateUp(Loading)
else()
}
navcontroller
can be inject in viemodel class in there. So it is recommended by the compose team ?dewildte
03/01/2023, 12:30 AMKotlinLeaner
03/01/2023, 12:31 AMdewildte
03/01/2023, 12:31 AMonNavigateToFriends = { navController.navigate("friendsList") },
ViewModel
fetches, holds and manages the data for the UI to render.@Composable
handles the navigation.KotlinLeaner
03/01/2023, 12:36 AMdewildte
03/01/2023, 12:36 AMKotlinLeaner
03/01/2023, 12:38 AMdewildte
03/01/2023, 12:38 AMKotlinLeaner
03/01/2023, 12:42 AM@Composable
handles the navigation. I found an article in droidcon. I don't want to refector my business logic code in viewmodel. Can I emit an event there and launch it in something like this example?dewildte
03/01/2023, 12:55 AM@Composable
in a controller @Composable
.
Like this:
@Composable
fun MyScreen(
onThingClick: () -> Unit,
...
) {
MyThing(onClick = onThingClick)
}
@Composable
fun MyScreenController(
navController: NavController,
viewModel: MyViewModel = hiltViewModel(),
) {
MyScreen(
onThingClick = {
navController.navigate("thing_route"
}
)
}
KotlinLeaner
03/01/2023, 12:59 AM