<@UHAJKUSTU> How to handle Deep linking with Compo...
# decompose
v
@Arkadii Ivanov How to handle Deep linking with ComposeMultiplatform for iOS, nothing is there in docs, nor in the sample app?
a
The general guide for Decompose side is applicable to iOS: https://arkivanov.github.io/Decompose/navigation/stack/deeplinking/ Then on the iOS side it should be handled by the iOS native way. There should be a way of getting the link somehow. We could add it to the sample I think.
v
iOS Native side I have handled From native I emit to a stateFlow which is in shared But when I collect it inside
ComposeUiViewController
and pass to the RootComponent, it crashes with the errors that its already been saved with the same key
Copy code
fun viewController(): UIViewController {

        return ComposeUIViewController(
            configure = { onFocusBehavior = OnFocusBehavior.DoNothing }
        ) {
            val deeplink by this.deeplink.collectAsState()
            val backDispatcher = BackDispatcher()
            val rootComponent = RootComponentImpl(
                componentContext = DefaultComponentContext(
                    lifecycle = ApplicationLifecycle(),
                    backHandler = backDispatcher
                ),
                deeplink = deeplink
            )
            val isDarkTheme =
                UIScreen.mainScreen.traitCollection.userInterfaceStyle ==
                        UIUserInterfaceStyle.UIUserInterfaceStyleDark

            PredictiveBackGestureOverlay(
                backDispatcher = backDispatcher, // Use the same BackDispatcher as above
                backIcon = { progress, _ ->
                    PredictiveBackGestureIcon(
                        imageVector = Icons.Default.ArrowBack,
                        progress = progress,
                    )
                },
                modifier = Modifier.fillMaxSize(),
            ) {
                MedialApp(
                    darkTheme = isDarkTheme,
                    dynamicColor = true,
                    component = rootComponent,
                    modifier = Modifier.fillMaxSize()
                )
            }
        }
    }
This is swift side, everytime, there is a new deeplink,
updateUiViewController
is called
Copy code
struct ComposeView: UIViewControllerRepresentable {
   var deeplink: String?

   func makeUIViewController(context: Context) -> UIViewController {
       let viewController = MedialApp.shared.viewController()
       return viewController
   }

   func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
       MedialApp.shared.setUpDeeplink(deeplink: deeplink)
   }
}
a
Yesterday I updated the docs for Android. I think the same idea can be applied to iOS? I.e. we can recreate the root component when a new deeplink is available. I will try to find some free time and deep links to the sample.
121 Views