oday
07/03/2022, 3:44 PMlifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.uiState.collect { uiState ->
if (uiState.authenticated) {
setContent {
Home()
}
} else {
setContent {
Authentication()
}
}
}
}
}
and the issue is that it’s collecting the stateFlow immediately before my viewModel gets the chance return the result, so it shows Authentication, then when the value comes back ti shows Home again
I want it to…well observe like LiveData doesdistinctUntilChanged
is trying to do with its signatureif (uiState.authenticated != null) {
if (uiState.authenticated) {
setContent {
Home()
}
} else {
setContent {
Authentication()
}
}
}
but is that really how to do it ?authenticated
has an initial valueAdam Powell
07/03/2022, 4:43 PModay
07/03/2022, 4:43 PMAdam Powell
07/03/2022, 4:46 PModay
07/03/2022, 4:46 PMAdam Powell
07/03/2022, 4:47 PModay
07/03/2022, 4:47 PMAdam Powell
07/03/2022, 4:47 PMauthenticated
can't be a boolean because you're assuming that there's something special about, "not yet authenticated because I'm waiting on some sort of confirmation"oday
07/03/2022, 4:49 PMAdam Powell
07/03/2022, 4:49 PModay
07/03/2022, 4:49 PMAdam Powell
07/03/2022, 4:49 PModay
07/03/2022, 4:50 PMAdam Powell
07/03/2022, 4:50 PModay
07/03/2022, 4:50 PMAdam Powell
07/03/2022, 4:51 PMdistinctUntilChanged
by default and "skip" intermediate values if an observer isn't responding fast enough: it should never matter to an observer so long as the state is being modeled fully. The latest, current state is all you ever need.oday
07/03/2022, 5:35 PM