-
-
Save appspell/fb0e5499d08f793d4932f739117af8b5 to your computer and use it in GitHub Desktop.
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
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 { | |
component.getViewModel() | |
} | |
Screen1(viewModel = viewModel) | |
} | |
composable(NavigationDestination.Screen2.destination) { | |
val viewModel: Screen2ViewModel = daggerViewModel { | |
// option #2 create DI component and instantly get ViewModel instance | |
DaggerScreen2Component.builder().build().getViewModel() | |
} | |
Screen2(viewModel = viewModel) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment