Closed lucanicoletti closed 3 weeks ago
As an update: I took the change to refactor to v2. The code now looks like this:
ModalNavigationDrawer(
drawerContent = {
SideMenu(destinationsNavigator = destinatorNavigator)
},
drawerState = drawerState,
gesturesEnabled = rememberIsDrawerOpen(drawerState),
scrimColor = Color.Black.withAlpha(LOW_ALPHA),
) {
val snackbarHostState = remember { SnackbarHostState() }
HandlesSnackBar(snackbarHostState)
Scaffold(
bottomBar = { SitkaBottomBar(navController, onScreenButtonClick(destinatorNavigator)) },
snackbarHost = { SitkaSnackbarHost(snackbarHostState = snackbarHostState) }
) { paddingValues ->
DestinationsNavHost(
engine = engine,
navGraph = NavGraphs.root,
start = startRoute,
navController = navController,
modifier = Modifier
.padding(paddingValues)
.background(MaterialTheme.colorScheme.surface)
.fillMaxSize(),
dependenciesContainerBuilder = {
dependency { openMenu() }
dependency(::navigateToScreen)
}
)
}
}
if (deeplink.isNotBlank()) {
navController.navigate(deeplink)
}
The error is still the same, the NavController graph has not been set.
Hey 👋
Doesn't seem related with Compose Destinations. I believe when NavHost gets called, it internally sets the graph to the NavController passed in. So are you sure that you're not calling navController.navigate
before DestinationsNavHost
gets called?
@raamcosta as you can see from the code, the navController.navigate
is done after the DestinationsNavHost
invocation. I thought it was a problem of the underneath Android SDK as googling the error I've seen it happens to other people as well, but unfortunately all the solutions I found didn't work in my scenario.
Can you log before each call and test? I don’t think it’s that easy because as you can see the DestinationsNavHost is inside a lambda.
Indeed the navigate
happens before. Any way to attach a callback to the DestinationsNavHost
?
If this is inside a composable, it should also be inside some Effect API, and probably after DestinationsNavHost but within the same lambda.
I’ll close this issue as it’s not compose destinations related. Hope that helps!
In my app I have the following setup
With this setup though, the
.navigate
throws an exception:Any idea of when/how I could prevent this from happening? Thanks.