WKWebView
as NSViewRepresentable
for usage in macOS environment and UIViewRepresentable
for UIKit
Loading a website inside a frame, navigation is possible inside a webpage, but there is no ObservedObject
struct MyWebView: View {
var body: some View {
SwiftUIWKWebView(viewModel: .init(urlString: "https://apple.com")!)
}
}
extend WebViewModel
for more actions from WKNavigationDelegate
struct MyWebView: View {
@ObservedObject var viewModel: WebViewModel
var body: some View {
SwiftUIWKWebView(viewModel: viewModel)
}
}
struct MyWebView_Previews: PreviewProvider {
static var previews: some View {
MyWebView(viewModel: .init(urlString: "https://twitter.com/jkmazur")!)
}
}