Basic question but is there way to include SwiftUI...
# compose-ios
j
Basic question but is there way to include SwiftUI code as part of
UIKitView
within shared compose code?
l
I could have sworn there's a UIView type that lets you put SwiftUI inside it. What's stopping you from using that?
j
Interesting....will see if that works
l
j
fyi: I used the same approach to display a webview on Android (WebView) and iOS (WKWebView) and it seems to work ...
k
@Jan can you please share the resources?
For impl webView on ios
j
@Kapil Yadav regarding using Platform views like AndroidView and UIKitView I did the following as a basic test:
Copy code
// Saved in commonMain src-set within a file Named NativeViewExample.common.kt
@Composable
expect fun NativeViewExample()

// Saved in androidMain src-set within a file named NativeViewExample.android.kt
@Composable
actual fun NativeViewExample() {
    val url = "<https://www.google.com>"
    val context = LocalContext.current
    AndroidView(
        factory = {
            WebView(context).apply {
                webViewClient = WebViewClient()
                this.layoutParams =
                    LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
                loadUrl(url)
            }
        })
}

// Saved in iOSMain src-set within a file named NativeViewExample.ios.kt
@Composable
actual fun NativeViewExample() {
    val url = "<https://www.google.com>"
    val webView = WKWebView()

    UIKitView(
        modifier = Modifier.fillMaxSize(),
        factory = {
            webView
        },
        update = {
            it.loadRequest(
                request = NSURLRequest(
                    uRL = NSURL(
                        string = url
                    )
                )
            )
        }
    )
}
s
Thanks @Kapil Yadav. Would be great if you could tell how can i listening to webpage loading states.