I want to adopt navigation compose, in an app wher...
# compose
s
I want to adopt navigation compose, in an app where we got activity based navigation 👴. To test this out, I figured in a new feature we're building, I can make an activity and have the internal navigation be compose.navigation. Thing is, in there, the start destination already is one which requires some sort of ID, think of it as maybe seeing a detail of an item, and the ID of an item is passed in there. Now the thing is, I need a top level NavHost in this new Activity, but reading these docs about fixed start destination, I guess I can't really get the start destination to be one with arguments. Is there a path of how one could do a slow adoption like this? I know the NavHost is not supposed to be used like this, but at the root of your project, but I'm just exploring my options.
a
This isn’t a guide, but what we’ve done is to start sort of in the other end. When we were about to redesign a view, or make a new one, we used Compose Navigation within that view . It might only have one or two internal destinations, but it was a good way to start learning and then you can just use those nav graphs as nested graphs when you start migrating other stuff.
s
Right, but that means that you would in fact have many NavHost composables in all these places right? Until they can be replaced, one nested graph for whatever was a NavHost previously.
a
Yes, one per Activity more or less
d
You could approach this from the other said - get your activity passed data to your Repository layer (or similar). From there your compose code can be the same like it would be if the data was coming from the network.
i
If you want to keep it as a separate activity, just set the
defaultValue
for your argument from your intent extras, it is just a variable: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1639326228018000?thread_ts=1639318886.014900&cid=CJLTWPH7S
a
Also ignore me, because I apparently didn’t read your question fully 😄
s
Thanks a lot Ann! I think this is a reasonable way forward in general, good to hear others have tried this too! Your input is still appreciated, it does give me the confidence that you’re doing the same and it has been working for you! And thanks for this Ian! I will give this a shot 😊 edit: Adding the default value directly from my intent extras worked like a charm!