new to android, and doing it the Compose
way.
I have a BottomNavigation
and three taps, each draw a different screen.
@Composable
fun SetupNavigation(navHostController: NavHostController) {
NavHost(navController = navHostController, startDestination = "home") {
composable(route = "first") {
FirstScreen()
}
composable(route = "second") {
SecondScreen()
}
composable(route = "third") {
ThirdScreen()
}
}
}
@Composable
fun FirstScreen(
firstScreenViewModel: FirstScreenViewModel = hiltViewModel()
) {
val uiState by firstScreenViewModel.uiState.collectAsState()
Log.i("FirstScreen", "uiState: $uiState")
val coins = uiState.coinsList
ItemsList(items = items)
}
Using the backbutton or just tapping through each viewModel of the different screens seems to reinit
. Is that the expected behavior? I like to persist the viewModel when switching routes.
I don't have fragments, just one activity with composable
TIA