Hey Folks, Is there a way to get the composable th...
# compose
k
Hey Folks, Is there a way to get the composable that is linked with a route for example
Copy code
composable<SomeNavroute>{
  SomeComposable
}
I want to get the
SomeComposable
using
SomeNavroute
with parameters if there are any I can get the route key and destination but not the associated composable
Copy code
navController.graph.nodes.forEach { key, value ->
    println("Key: $key, Value: $value.")
}
s
What are you trying to do?
k
I am trying o bridge uikit navigation with navigation compose, i have done it for voyager and trying to do it for compose navigation. Its working but if i could get the exact composable it would be much better
p
Unless the NavGraph saves the Composable function reference somewhere, I don't see a way to get that back. I think you would have to keep the SomeComposable function reference somewhere on your side. These references will set their values when the graph is instantiated.
k
That would work maybe creating scattermap and then iterating over it in the navhost to add those composables but I don’t have much experience with navigation compose so don’t know it would work or not but will try it tomorrow
👍 1
a
You can store key value data on the nav backstack entry. So if you want which type it is, you can just serialize a string onto it
k
@agrosner i am actually trying to get the composable
a
Ah yeah. Pabli is right, you’ll need to store the function reference, but it may take any number of parameters combined with the composabke function lambda. Voyager bundles data with screens directly where compose nav isn’t opinionated how you do it, you’d need a layer on top that works similarly where you can construct the composable with its dependencies. An alternative where It’s probably possible to wrap the nav host and nav graph builder classes to capture these references , or there are specific ways to register navigators in compose nav. If you look at material 3 bottom sheet has its own navigator and extension on compose nav dsl
(In mainline navigation material now)
Like in your library you have “pushx “ you might consider doing something similar like “composablex” . Though without further POCing not sure if it will work way you want
k
I am trykng to follow a similar approach as voyager does since with 2.8.0 you can create routes as data class/ objects and then creating the top level composable inside it. It’s working for now but ill try to dig deeper if i can do something better
👍 1
i
Note that the Navigation Component is fully agnostic to 1) how you implement each screen and 2) how you display those screens. That why the exact same NavController works with Fragments or Compose - they each just have their own Navigator, NavDestination subclass, and NavHost. That means, just like our Navigation Compose, you could write your own Navigation UIKit Compose that has your own NavHost and your own ComposeNavigator and your own
composable
navigation DSL
👍 1
That's exactly how the Accompanist Navigation Animation library worked, FWIW, if you want some inspiration
K 1
(you'll note the migration guide was essentially just swapping imports and everything else just worked)
k
Thanks for the heads up @Ian Lake i would definitely look at the accompanist code to get to know more about how these class work internally