-
-
Save SumeraMartin/c381c4553333efbdcebc6a4bd8f7a1e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ViewState | |
class ViewState { | |
... | |
var screenState by mutableStateOf(ScreenState.FORM) | |
... | |
} | |
// ViewModel | |
class ViewModel { | |
... | |
fun test() { | |
viewState.screenState = ScreenState.SUCCESS | |
Log(${viewState.screenState}) // This prints correct value | |
} | |
... | |
} | |
// Composable | |
fun Screen() { | |
LaunchedEffect(Unit) { | |
snapshotFlow { viewModel.viewState.screenState }.collect { | |
Log($it) // This prints correct value | |
} | |
} | |
Screen.Content( | |
state = viewModel.viewState.screenState | |
) | |
} | |
// Content | |
fun Content(state: ScreenState) { | |
Log($state) // This doesn't print nothing | |
LaunchedEffect(screenState) { | |
Log($screenState) // This doesn't print nothing | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment