oday
07/02/2022, 6:25 PMclass MainActivity @Inject constructor() : ComponentActivity() {
private val viewModel: MainViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
if (viewModel.uiState.collectAsState().value.authenticated) {
Home()
} else {
Authentication()
}
}
}
}
this authenticated
field is going to change to true
or false
inside the viewModel depending if the user is authenticated or not
the above code will first come up with false for that field, showing the Authentication composable and then the change will happen triggering the recomposition and then it will come up with true and show the Home composable
how do I listen
to changes for that field, is the above even correct or how things should be done?Zach Klippenstein (he/him) [MOD]
07/05/2022, 4:29 PMauthenticated
needs to be backed by a MutableState
, or whatever holds authenticated
(the type of uiState
) should be immutable and the entire object updated when the authentication status changes.