Hi. I had original <question about compose destina...
# compose
t
Hi. I had original question about compose destination library, but it looks that it is not specific to that library but the same issue is even with
androidx.navigation.compose.NavHost
. There is also no way how to directly open target destination from deeplink without opening
startDestination
. So it is basically the same problem. Why there is no way to put deepLinkUri as initial destination for NavHost 😞. Even
navController.findDestination()
can't accept deep link 😞
i
Everything you're saying is incorrect. NavHost automatically handles deep links from your Activity's Intent, you don't need to write any code for that case. When handling a deep link, the start destination is not invoked at all, but it is used to create the synthetic back stack of the deep linked destination. See the docs that explain the automatic handling and the sythetic back stack parts: https://developer.android.com/guide/navigation/design/deep-link
t
Problem is that I'm not in activity directly, in my case the origin is Fragment. So I need to replicate the same behavior, but in Fragment. 😞
I need to found where exactly is that Activity's Intent handled, that it happen before invoking start destination. So far I was not successful.
i
The
onGraphCreated
is what is called once the graph is set (via the
NavHost
) and any state is restored. If there wasn't any state to restore, it checks whether it needs to handle a deep link and otherwise goes to the start destination: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:navigati[…]otlin/androidx/navigation/internal/NavControllerImpl.kt;l=971
gratitude thank you 1
gratitude thank you 1
But you shouldn't be using deep links when you are internal to your app, so I think what is actually happening is an XY Problem: https://en.wikipedia.org/wiki/XY_problem Where you're running into this issue 'Y' without explaining the 'X' of how you've set things up in the first place. Maybe taking a step back and talking through what you are trying to do at a base level would be helpful context?
👍 1
t
Thanks I will investigate it. To to the XY problem. It is hard. I'm working in corporate env. where many thing doesn't make any sense. We are using internal framework which purpose is to split one big app to many fully independent parts and then allows to build any app from them just by choosing independent features to it. It is based of XML nav graphs and fragments. It has many disadvantages, dev hate it, but sadly management likes it. It for example using internal deep links to navigate between that independent parts quite heavily. And I'm trying to start migration to compose. So I want to allows to build fully compose features based on this and allows them to be used together with other that are fragment based. With "fully" I mean that I don't want to see any fragment or fragment navigation inside of it. So me whole feature will live inside of one Fragment with own compose based navigation. One time when all features will be compose we will remove also fragment navigation from the framework itself. But now it must cooperate. So if there is some deep link (internal or external) , it will start or update the MainActivity, that will switch to right fragment (feature) and inside of that fragment (feature) will be navigated to the right compose screen.
It really works only if that deeplink intent is in the activity, which is not in my case. I'm getting it by
Copy code
val deepLinkIntent = requireArguments().getParcelable(
    NavController.KEY_DEEP_LINK_INTENT,
    Intent::class.java
)
inside of the fragment. So I can do two thing 1. quite and dirty, just call this before NavHost and restore it after
Copy code
(LocalContext.current as Activity).intent = deepLinkUri
2) override NavController and override handleDeepLink() and use own intent instead of the actiity one.