Skip to content

Instantly share code, notes, and snippets.

@fergusonm
Last active February 21, 2021 23:55
Show Gist options
  • Save fergusonm/7502eb956cbeeb6647c5edc1c178b439 to your computer and use it in GitHub Desktop.
Save fergusonm/7502eb956cbeeb6647c5edc1c178b439 to your computer and use it in GitHub Desktop.
Fragment, observe using view lifecycle scope
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.eventsFlow
.onEach {
when (it) {
is MainViewModel.Event.NavigateToSettings -> {}
is MainViewModel.Event.ShowSnackBar -> {}
is MainViewModel.Event.ShowToast -> {}
}
}
.launchIn(viewLifecycleOwner.lifecycleScope)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment