https://kotlinlang.org logo
Title
m

mgrazianodecastro

04/11/2023, 7:29 PM
what is the right way to "bubble up" the callback for a navigation in a nested graph? I have something like:
---> A (with public children x)
Main --/
       \---> B
and I need to pass the callback access to children x. What's I've tried is to create it inside the A module, like so:
fun NavController.navigateToX(arg: String){
    val destination = this@ScreenX.route + "/" + arg
    navigate(destination)
}
but when I access it through Main into the B module, it doesn't find the route. Should I append more things at the beginning?
I've also added
NAV_GRAPH_ROUTE + / + ...
to see if it works, but without success
m

Matt Rea

04/11/2023, 10:02 PM
Each feature should create an extension on NavGraphBuilder, then call each feature from the root graph Then just pass in a lambda to navigate
fun NavGraphBuilder.featureA(navigateToX: (String) -> Unit)
m

mgrazianodecastro

04/11/2023, 11:07 PM
that's how I've been doing, but no success
lemme double check if I'm not doing something weird with strings (lol)
Yep, I was doing something weird with the strings. Our solution works