-
|
Because if I try to add webkit then I can't compile or build successfully import SwiftUI
#if !SKIP
import WebKit
struct WebView : UIViewRepresentable {
let urlString: String
@Binding var clickedLink: URL?
func makeUIView(context: Context) -> WKWebView {
let wkWebView = WKWebView()
wkWebView.navigationDelegate = context.coordinator
return wkWebView
}
func updateUIView(_ webView: WKWebView, context: Context) {
// let url = URL(string: "https://www.youtube.com/watch?v=aQUKMwJg0n0")
let url = URL(string: urlString)
if let url = url {
let request = URLRequest(url: url)
webView.load(request)
}
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
class Coordinator: NSObject, WKNavigationDelegate {
var parent: WebView
init(_ parent: WebView) {
self.parent = parent
}
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if navigationAction.navigationType == .linkActivated {
if let url = navigationAction.request.url {
parent.clickedLink = url
print("Clicked link:", url)
}
}
decisionHandler(.allow)
}
}
}
#endif |
Beta Was this translation helpful? Give feedback.
Answered by
marcprux
Sep 14, 2024
Replies: 1 comment
-
|
Skip doesn't support |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
marcprux
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Skip doesn't support
UIViewRepresentable(because we generally don't support UIKit). However, we do have an early preview of support for embedded web views in the https://github.com/skiptools/skip-web framework. It handles very basic web embedding, but you can always fork the repo and add whatever customizations you need.