Dan
03/12/2024, 3:30 PMComposeUiViewController
from iOS. I would like to trigger a redraw/recompose when the iOS app is opened by another app with a deeplink. Is there a way to do that? I have tried to use an EnvironmentObject
to trigger a redraw but I’m a little lost.Casey Brooks
03/12/2024, 3:36 PMState<T>
objects, you no longer have a “pure” UI and unexpected issues can arise. Forcing a recomposition without any change to state variables won’t have any effect on the UI.
So if you want the UI to react to or display differently when opened via deepLinks, you should update a state variable with data from the deepLink. The UI then reads that state variable and responds appropriately when it changes as a result of the deepLinkDan
03/12/2024, 3:39 PMState<T>
from the SwiftUI code into the MainViewController
and then have the composable react accordinglyDan
03/12/2024, 3:39 PMCasey Brooks
03/12/2024, 3:46 PM//deepLinkHander.kt
val deepLinkUri = mutableStateOf<String?>(null)
@Composable
fun Application() {
Text(deepLinkUri.value)
}
//deepLinkHanderiOS.swift
onDeepLinkHandled { (uri) -> void in
DeepLinkHander.deepLinkUri.setValue(uri)
}
Dan
03/12/2024, 3:48 PMAlbert Chang
03/13/2024, 2:29 AMcurrentRecomposeScope
in a composable function, and call scope.invalidate()
elsewhere to force a recomposition.Dan
03/13/2024, 8:18 AM// in Kotlin: DeepLinkHandler.kt
val deepLinkUri = MutableStateFlow<String?>(null)
// in Swift
func handleDeepLink(_ url: URL) {
DeepLinkHandlerKt.deepLinkUri.tryEmit(value: url)
}
The interop works seamlessly 👍