Hi fellow comopsers, I am working on a navigation ...
# compose
u
Hi fellow comopsers, I am working on a navigation graph and would like to integrate a DisposableEffect tied to the lifecycle of a navigation entry:
Copy code
internal fun NavGraphBuilder.mainFlowDestination(
    navController: NavHostController,
) {
  DisposableEffect(Unit) { ... }
  navigation<MainFlowRoute>(Route1::class) {
    composable<Route1> { ... }
    composable<Route2> { ... }
  }
}
The problem here is, that
fun mainFlowDestination
is not
@Composable
. Is there a common pattern for it, like introducing a `comosable{}`around the whole method that gets inserted as a ‘silent’ node? What would the route be? Wold it affect back naviagtion? Something like this. But that looks fishy:
Copy code
internal fun NavGraphBuilder.mainFlowDestination(
    navController: NavHostController,
) {
  composable<MainFlowRoute> {
    DisposableEffect(Unit) { ... }
    navigation<MainFlowRoute>(Route1::class) {
      composable<Route1> { ... }
      composable<Route2> { ... }
    }
  }
}
Should I replace
navigation<MainFlowRoute>
with a nested NavHost?
Copy code
internal fun NavGraphBuilder.mainFlowDestination(
    navController: NavHostController,
) {
  composable<MainFlowRoute> {
    DisposableEffect(Unit) { ... }
    NavHost(navController, Route1::class) {
      composable<Route1> { ... }
      composable<Route2> { ... }
    }
  }
}