Hi all. A navigation question about deep links, ar...
# compose-android
b
Hi all. A navigation question about deep links, arguments, and type-safety. I've read the documentation about deep links, as well as an Android Developers blog post and I think I understand the basics. In my case, I an additional custom url that I need to handle. I can define those deep link easy enough, but I'm not sure how to get them parsed into a route instance? A brief example in the 🧵.
here's an example:
Copy code
composable<Profile>(
    deepLinks = listOf(
        navDeepLink<Profile>(basePath = "$uri/profile"),

        // I also need this URL pattern. How do I handle it?
        navDeepLink { uriPattern = "$uri/users/{userId}/profile" },
    )
) { backStackEntry ->
    ProfileScreen(id = backStackEntry.toRoute<Profile>().id)
}
s
We hand-write all of our deep links, and they just work if you know that you're matching the expectations of what the library will generate given some data class https://github.com/HedvigInsurance/android/blob/develop/app%2Fnavigation%2Fnavigation-core%2Fsrc%2Fmain%2Fkotlin%2Fcom%2Fhedvig%2Fandroid%2Fnavigation%2Fcore%2FHedvigDeepLinkContainer.kt#L118 If you want your deep link to look a specific way which the library doesn't actually generate for your data class, you are blocked I think actually. We've had to change how some of our data classes look like, even if it's semantically wrong to do so, only for the auto-gen of the deep link to match the kind of deep link we've had before and unfortunately still have to maintain. See https://issuetracker.google.com/issues/396060181 for an example where we had to add a default value to a class which should definitely not have a default value normally
Now for your case, where the user id is in-between the paths, does it just work if your variable name matched that "userId"? If it does not you may be out of luck, unless I am missing something.
b
Yeah, we have an existing web application, and our marketing team needs to be able to send out various communications with "universal" links that will work across platforms. If you have the app installed, open that. If not, open the appropriate page on the web site, etc. So I don't really have the ability to control what the deep link is for a given destination, and in fact, there may be several deep links that all work to get to a given destination. Add to it that it's a fairly large scale application, and I'm really kind of stuck. I really like the "object based routes" that you can use with the navigation component to get type safe arguments. But if they don't work with custom deep link patterns, I don't think I'm going to be able to use them.
Wonder if I could write some kind of "adapter" that would handle an intent with a deep link, parse it, convert the deep link to one that that navigation component would expect, and create a new intent with that converted value. That seems .... not great. But maybe it's an option...
s
I had filed this too https://issuetracker.google.com/issues/366146254#comment2 and I basically got an answer as WAI and got ignored after the fact and I really think my point was not understood there. Perhaps you should make a new issue to see if they provide any possible way for you to make that custom handler or something like that