Skip to content

Instantly share code, notes, and snippets.

@SumeraMartin
Last active February 22, 2022 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SumeraMartin/c381c4553333efbdcebc6a4bd8f7a1e5 to your computer and use it in GitHub Desktop.
Save SumeraMartin/c381c4553333efbdcebc6a4bd8f7a1e5 to your computer and use it in GitHub Desktop.
// 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