Colton Idle
07/21/2023, 5:00 PMNavHost
scoped ViewModel
when using a NavDrawer
?Colton Idle
07/21/2023, 5:00 PMModalNavigationDrawer(
drawerContent = {
val parentEntry = remember(navBackStackEntry) {
navController.getBackStackEntry("parentNavigationRoute")
}
val parentViewModel: RootAppViewModel = hiltViewModel(parentEntry)
NavDrawerContent(
currentDestination,
drawerState,
buttonClick = { parentViewModel.doSomething() }
)
},
content = {
ModalBottomSheetLayout(bottomSheetNavigator) {
NavHost(navController, startDestination = "home") {
Colton Idle
07/21/2023, 5:05 PMjava.lang.IllegalArgumentException: No destination with route parentNavigationRoute is on the NavController's back stack. The current destination is null
EDIT: Im trying to follow these docs btw: https://developer.android.com/topic/libraries/architecture/viewmodel/viewmodel-apis#composeStylianos Gakis
07/21/2023, 5:07 PMroute
parameter on it afaik. Then get the backstack entry just as you're doing already.
Then idk about the hilt api, but that probably looks correctColton Idle
07/21/2023, 5:09 PMrootNavGraph
. Seems like some general race condition. where my navgraph doesn't actually exist yet.
java.lang.IllegalArgumentException: No destination with route rootNavGraph is on the NavController's back stack. The current destination is null
Stylianos Gakis
07/21/2023, 5:11 PMStylianos Gakis
07/21/2023, 5:15 PMColton Idle
07/21/2023, 5:16 PMColton Idle
07/21/2023, 5:16 PMColton Idle
07/21/2023, 5:20 PM@Composable
fun MyApp(
appStateHolder: AppStateHolder
) {
val bottomSheetNavigator = rememberBottomSheetNavigator()
val navController = rememberNavController(bottomSheetNavigator)
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
ModalNavigationDrawer(
drawerContent = {
val parentEntry = remember(navBackStackEntry) {
navController.getBackStackEntry("rootNavGraph")
}
val parentViewModel: RootAppViewModel = hiltViewModel(parentEntry)
NavDrawerContent(
currentDestination,
drawerState,
buttonClick = { parentViewModel.doSomething() }
)
},
content = {
ModalBottomSheetLayout(bottomSheetNavigator) {
NavHost(route = "rootNavGraph", navController = navController, startDestination = "home") {
composable("home") { backStackEntry -> Demo1Screen() }
...
Stylianos Gakis
07/21/2023, 5:26 PMStylianos Gakis
07/21/2023, 5:27 PMStylianos Gakis
07/21/2023, 5:29 PMColton Idle
07/21/2023, 5:29 PMStylianos Gakis
07/21/2023, 5:30 PMColton Idle
07/21/2023, 5:30 PMColton Idle
07/21/2023, 5:33 PMfun MyApp(
appStateHolder: AppStateHolder,
activityViewModel: RootAppViewModel = hiltViewModel()
) {
Stylianos Gakis
07/21/2023, 6:02 PMColton Idle
07/21/2023, 10:38 PMColton Idle
07/21/2023, 10:39 PMColton Idle
07/21/2023, 10:41 PMfun MyApp(
appStateHolder: AppStateHolder,
activityViewModel: RootAppViewModel = hiltViewModel()
) {
im not sure if its actually scoping it to the Activity or NavGraph?Stylianos Gakis
07/21/2023, 10:58 PMa scope in between activity scope and the NavHost scope.
Yeah there's nothing between there because those two already are equivalent, they have the same lifecycle.
Stylianos Gakis
07/21/2023, 11:01 PMColton Idle
07/22/2023, 3:01 AMYeah there's nothing between there because those two already are equivalent, they have the same lifecycle.wait. do they really? like. i know they have a similar lifecycle, but for the navHost is it really the activity lifecycle/scope/viewModelStoreOwner? hmm. might be a pain and ping Ian when he's back from vacay 😅
Colton Idle
07/22/2023, 3:01 AM