David Attias
11/16/2020, 5:40 PMAdam Powell
11/16/2020, 6:43 PMDavid Attias
11/16/2020, 8:00 PMJeremy
11/16/2020, 8:50 PMdata class MyState(val currentScreen: String)
and then you'd have if(state.currentScreen=="a") { ScreenA() ) }
David Attias
11/16/2020, 8:56 PMJeremy
11/16/2020, 11:15 PMui = fn(state)
navigation-compose
lib or building a custom solution?David Attias
11/17/2020, 7:54 AMnavigation-compose
Archie
11/17/2020, 9:43 AMclass MyViewModel : ViewModel() {
val currentRoute: MutableStateFlow<String>()
....
}
@Composable
fun MyScreen(
navController: NavController,
myViewModel: MyViewModel,
) {
val route = myViewModel.currentRoute.collectAsState(startRoute)
navController.navigate(route)
}
But I don't how popBackStack()
or even popBackStack(id)
would be done this case? Any idea?David Attias
11/17/2020, 9:51 AMArchie
11/17/2020, 9:52 AMDavid Attias
11/17/2020, 9:55 AMMyScreen
, it will immediately navigate back to the new route....Navigator
that will handle navigation with event from the ViewModel....Archie
11/17/2020, 10:06 AMpopBackStack()
in this architecture, we would also have to set the currentRoute
to previousRoute
, which means holding on to the backStack
(consumed route) itself.
I hope there would be an official sample for this in the future...David Attias
11/17/2020, 10:19 AMnavigation-compose
?Adam Powell
11/17/2020, 4:30 PMDavid Attias
11/17/2020, 4:35 PMAdam Powell
11/17/2020, 4:38 PMDavid Attias
11/17/2020, 4:39 PMAdam Powell
11/17/2020, 4:40 PMDavid Attias
11/17/2020, 4:45 PMAdam Powell
11/17/2020, 4:48 PMLaunchedEffect(navigator, viewModel) {
viewModel.navEvents.collect { navigator.navigateTo(it) }
}
David Attias
11/17/2020, 4:55 PMharry248
03/12/2021, 8:04 AMAdam Powell
03/12/2021, 2:44 PM