Post

Replies

Boosts

Views

Activity

Reply to How do I implement a WebView (WebKit) in SwiftUI?
subclass WKWebView and use that in your UIViewRepresentable, e.g. MyWKWebView. Implement the delegate methods on MyWKWebView as usual.```struct WebView : UIViewRepresentable { let request: URLRequest func makeUIView(context: Context) -> MyWkWebView { return MyWkWebView() } func updateUIView(_ uiView: MyWkWebView, context: Context) { uiView.load(request) } }===thenclass MyWkWebView: WKWebView { /* // Only override draw() if you perform custom drawing. // An empty implementation adversely affects performance during animation. override func draw(_ rect: CGRect) { // Drawing code } */}extension MyWkWebView: WKNavigationDelegate { func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {// track("didFinish")// self.hideProgressView() } func webViewWebContentProcessDidTerminate(_ webView: WKWebView) {// track("webViewWebContentProcessDidTerminate") } func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {// track("didFail")// self.hideProgressView() }}
Apr ’20