Last active
February 21, 2021 23:55
-
-
Save fergusonm/7502eb956cbeeb6647c5edc1c178b439 to your computer and use it in GitHub Desktop.
Fragment, observe using view lifecycle scope
This file contains hidden or 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
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