āļ‚āđ‰āļēāļĄāđ„āļ›āļĒāļąāļ‡āđ€āļ™āļ·āđ‰āļ­āļŦāļēāļŦāļĨāļąāļ
  1. Posts/

🚧Integrating Deep Links with Type-Safe Navigation Compose (and custom parsing) and fcm

·226 āļ„āļģ·2 āļ™āļēāļ—āļĩ
Android Development Android Compose Navigation Deep-Links Fcm
Jojo Chalanthorn
āļœāļđāđ‰āđ€āļ‚āļĩāļĒāļ™
Jojo Chalanthorn
A little bit about you
āļŦāļąāļ§āļ‚āđ‰āļ­āđ€āļ™āļ·āđ‰āļ­āļŦāļē
deep-link-compose-fcm - āļšāļ—āļ„āļ§āļēāļĄāđƒāļ™āļŠāļļāļ”āđ€āļ”āļĩāļĒāļ§āļāļąāļ™
āļ•āļ­āļ™āļ—āļĩāđˆ : āļšāļ—āļ„āļ§āļēāļĄāļ™āļĩāđ‰

This Post is being built
#

By using deep links, you can jump from the notifications to a certain routes in NavGraph or even Nested Graph

Prerequisites
#

  • KotlinX.Serialization
  • Navigation Compose
  • Navigating Deep Links with Intents

Url Parameters
#

image info

Using Something
#

The following DetailPage class is used as an example for the navigation

@Serializable
data class DetailPage(
    @SerialName("title_name")
    val title: String,
    @SerialName("sub_title")
    val subTitle: String? = null
    
    val id: Int,
)

If you want the navDeepLink to parse your URI, you should put it in this format

appName://DetailPage/{title_name}/{id}?sub_title={sub_title}

In the compose navigation the code will look like

composable<DetailPage>(
    deepLinks = listOf<DetailPage>(
        basePath = "appName://DetailPage",
    )
)

What if the Uri is in different format?
#

For example, you want to extract the id and name pattern from the uri or using custom uri altogether. together, you might want to write a custom uriPattern in the NavDeepLink.navDeepLink API

It can be put together as

composable<DetailPage>(
    deepLinks = listOf<DetailPage>(
        basePath = "appName://DetailPage",
    ) {
        uriPattern =  "appName://{id}_{title_name}?sub_title={sub_title}"
    }
) {
    val args = it.toRoute<DetailPage>
}

Then args can be retrieve using

1
2
3
4
5
6
7
8
Or even create something difficult to build like
composable<DetailPage>(
    deepLinks = listOf<DetailPage>(
        basePath = "appName://DetailPage",
    ) {
        uriPattern =  "example://full_name/{first_name}/{last_name}/edit"
    }
)

[!NOTE] This uriPattern might not be type safe, but it offers flexibility for those in need

deep-link-compose-fcm - āļšāļ—āļ„āļ§āļēāļĄāđƒāļ™āļŠāļļāļ”āđ€āļ”āļĩāļĒāļ§āļāļąāļ™
āļ•āļ­āļ™āļ—āļĩāđˆ : āļšāļ—āļ„āļ§āļēāļĄāļ™āļĩāđ‰