Created
June 25, 2022 12:58
-
-
Save attilakruchio/19d1ac5bbe5239818b5e40cbdd2c0596 to your computer and use it in GitHub Desktop.
Gist for 'Easy and elegant navigation with Jetpack Navigation and Hilt' Medium article (https://medium.com/@kruchio98/6f93a0461298)
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
abstract class BaseFragment : Fragment() { | |
abstract val viewModel: BaseViewModel | |
@CallSuper | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
viewLifecycleOwner.lifecycleScope.launch { | |
repeatOnLifecycle(Lifecycle.State.STARTED) { | |
viewModel.events.collect { event -> | |
onEvent(event) | |
} | |
} | |
} | |
} | |
open fun onEvent(event: SingleEvent) { | |
when (event) { | |
is NavigateTo -> { | |
findNavController().navigate(event.navDirections) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment