Jeisson Sáchica
12/05/2020, 5:21 PMAdam Powell
12/05/2020, 5:33 PMJeisson Sáchica
12/05/2020, 5:46 PMMutableState<String>
on my MainActivity which I pass to one of my screen composables and I update its value like this state.value = googleToken
after I get a token on onActivityResult from GoogleSignInActivity. Inside my login screen i have a onCommit block that I execute whenever this token changes.
val googleIdToken by googleIdTokenState
onCommit(googleIdToken) {
googleIdToken?.let { token ->
loginViewModel.checkIfGoogleUserExists(token) {
// If it exists, login and navigate "Home" immediately
// If it does not exist, navigate to next screen "Register" for the user to input a username
}
}
}
My problem comes when for example, the user navigates to register screen and then navigates back and again clicks on the "Sign in with Google" button. on the onActivityResult I will get the same token but the MutableState won't change. I managed to make it change by creating it with a neverEqualPolicy()
but of course the onCommit block won't execute againAdam Powell
12/05/2020, 6:54 PMonCommit
to dispatch change events to some other part of your system it's a bit of a code smellonCommit
is going away, replaced by SideEffect
and DisposableEffect
snapshotFlow
Jeisson Sáchica
12/05/2020, 7:23 PM