I'm trying create a WebView view in SwiftUI 2.0 Xcode 12.4 but it's so new I can't find good examples for answers and best practice. For the code below I get the following error.
Type 'SwiftUIWebView' does not conform to protocol 'UIViewRepresentable'
Also setting the config has changed and I can't enable .allowsContentJavaScript properly. Trying to add it to the "perfs" triggers an error complaining about not liking a Bool.
import SwiftUI
import WebKit
struct SwiftUIWebView: UIViewRepresentable {
let url: URL?
func makeUIView(context: Context) -> some WKWebView {
let prefs = WKWebpagePreferences()
let config = WKWebViewConfiguration()
config.defaultWebpagePreferences = prefs
return WKWebView(frame: .zero, configuration: config) //frame CGRect
}
func updateUIView(_ uiView: WKWebView, context: Context) {
guard let myURL = url else { return }
let request = URLRequest(url: myURL)
uiView.load(request)
}
}