Also, it seems like deep links aren't going to the...
# compose-destinations
d
Also, it seems like deep links aren't going to their destination when the app is working in the background (only when closed completely, it works) and when coming from a link from Whatsapp... I don't know if it really concerns compose destinations -- but maybe I'm not using it right?
r
In regards to deep links, all we do is take the info from the annotation directly into:
Copy code
navDeepLink {
    uriPattern = ....
    ...
}
from the official compose navigation APIs
d
Sorry to bother you about this again... just wondering if you know if the navigation component handles onNewIntent that gets sent when a new deep link is requested and launchMode in the AndroidManifest on my MainActivity is set to singleInstance...? I'm just maybe not understanding the inner workings of the component.
And is there a way to bypass the home screen when navigating to a deep link deeper in the hierarchy?
r
I sure hope so, that’s exactly what deep links are for, right?
But other than that, I’m not the most knowledgeable about deep links tbh. I think you’ll get better luck asking on #navigation-architecture-component or #compose
d
Ok thanks, I'll try.
No answer there... but the studio bot (Gemini) seems to say I need the
navDeepLink { }
in the
composable(deepLinks = ...)
function AND
NavDeepLink
to actually handle them... does compose destinations generate both?
Or maybe Gemini is wrong?
r
Yes, that is what CD does.
you can check the corresponding genrated Destination object. There is a "deepLinks" field that returns the deep links in the way you would have written yourself.
That gets called when registering the destination, with the
composable()
call.
d
Yeah, I saw that, but what about
NavDeepLink
composable?
r
how is that used? any documentation?
From the top of my head, i don't remember it
d
This is what gemini gave me:
Copy code
@OptIn(ExperimentalNavigationApi::class)
val navGraph = navGraph(
    startDestination = "main",
    route = "root"
) {
    composable(
        route = "main",
        deepLinks = listOf(navDeepLink { uriPattern = deepLinkMain })
    ) {
        // Main screen content
    }
    composable(
        route = "sub",
        deepLinks = listOf(navDeepLink { uriPattern = deepLinkSub })
    ) {
        // Sub screen content
    }
}

@OptIn(ExperimentalNavigationApi::class)
@Composable
fun DeepLinkHandler(navController: NavHostController) {
    NavDeepLink(
        uriPattern = deepLinkMain
    ) {
        navController.navigate("main")
    }
    NavDeepLink(
        uriPattern = deepLinkSub
    ) {
        navController.navigate("sub")
    }
}

@OptIn(ExperimentalNavigationApi::class)
@Composable
fun MyComposable(navController: NavHostController) {
    NavHost(
        navController = navController,
        startDestination = "main"
    ) {
        composable(
            route = "main",
            deepLinks = listOf(navDeepLink { uriPattern = deepLinkMain })
        ) {
            // Main screen content
        }
        composable(
            route = "sub",
            deepLinks = listOf(navDeepLink { uriPattern = deepLinkSub })
        ) {
            // Sub screen content
        }
    }

    DeepLinkHandler(navController)
}
Maybe it's wrong...?
r
I've never seen such thing 🤷
I based my implementation on these official docs
d
Yeah... that's AI for you... it's not even a composable: NavDeepLink
Well, I guess my problem is somewhere else...
r
that NavDeepLink probably is something that gets instantiated internally
👍🏼 1
when we use the APIs provided by compose nav