Question about Deep Links on Compose Multiplatform...
# compose
g
Question about Deep Links on Compose Multiplatform! ๐Ÿค” For Android, in
MainActivity
, I found out we can write the following to catch the intent data and send it to the
navController
of
compose-navigation
:
Copy code
override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val navController = rememberNavController()
            DisposableEffect(Unit) {
                val listener = Consumer<Intent> {
                    navController.handleDeepLink(it)
                }
                addOnNewIntentListener(listener)
                onDispose { removeOnNewIntentListener(listener) }
            }
            ShinyApp(navController = navController)
        }
    }
}
Does someone know what is the equivalent for iOS I guess in
MainViewController()
?
Copy code
fun MainViewController() = ComposeUIViewController {
    val navController = rememberNavController()
    // How to consume Deep link from iOS?
    HolidaysApp(navController)
}
Thanks in advance! ๐Ÿ™
With that said, for Android, you don't need to do anything if you are using the right "launchMode" https://developer.android.com/guide/navigation/design/deep-link#handle The NavHost will receive the intent and handle the deep link automatically without you having to call
handleDeepLink
on it somehow
g
Thanks @Stylianos Gakis ! I'll look into the iOS side, seems like what I need to do! ๐Ÿฅณ For the Android side, without the disposable effect, the navigation library for compose multiplatform (not the android one) doesn't react on intent because it doesn't know about Android I guess, and also they say deep links are not managed automatically in the docs: https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-navigation-routing.html#limitations ``````
๐ŸŒŸ 1
s
Ah right, they might not be doing platform specific things there on the MP version of this library. Good to know, I haven't played with it yet actually!
๐Ÿ‘ 1
i
the navigation library for compose multiplatform (not the android one) doesn't react on intent
While it's true that deep-links are not supported on non-Android yet, This library uses original Google's binaries on Android, so all features that worked on Android should continue work on Android after switching to KMP version
s
Oh, well I take it back then. Try removing the extra handling to see how it looks like, it internally looks into the intent from the context and should handle the deep links automatically. It does for us ๐Ÿ˜Š
g
Hmmmm on second thought, yes that's exactly what is going on actually here, the way of the disposable is the Compose equivalent of the original way of forwarding the url from onNewIntent on a "launchedMode = singleinstance" activity. The alternative and how it's done usually is by declaring the nav controller outside of Compose, and calling handleDeeplink in onNewIntent. So we're good to go ๐Ÿ‘
s
Actually not really, if you use the default launchMode, as described here https://kotlinlang.slack.com/archives/CJLTWPH7S/p1716889267708519?thread_ts=1716886867.697359&amp;cid=CJLTWPH7S you don't need to override onNewIntent at all
g
Yes that's correct, we're saying the same thing ๐Ÿ˜… It is just missing iOS management then, the docs is not very clear about it
๐Ÿซฃ 1
520 Views