Skip to content

Instantly share code, notes, and snippets.

Created May 11, 2021 06:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save appspell/fb0e5499d08f793d4932f739117af8b5 to your computer and use it in GitHub Desktop.
setContent {
val navController = rememberNavController()
NavHost(navController, startDestination = NavigationDestination.Screen1.destination) {
composable(NavigationDestination.Screen1.destination) {
// option #1 create a component inside NavBackStackEntry,
// which can be helpful if we need to provide more than one object from DI here
val component = DaggerScreen1Component.builder().build()
val viewModel: Screen1ViewModel = daggerViewModel {
Screen1(viewModel = viewModel)
composable(NavigationDestination.Screen2.destination) {
val viewModel: Screen2ViewModel = daggerViewModel {
// option #2 create DI component and instantly get ViewModel instance
Screen2(viewModel = viewModel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment