Created
December 13, 2020 07:14
-
-
Save IhwanID/637c45f7ecc0ba7fc091de5369cc84d3 to your computer and use it in GitHub Desktop.
SwiftUI Webview Using WKWebView & Webkit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// WebView.swift | |
// SwiftUIWebView | |
// | |
// Created by Ihwan ID on 13/12/20. | |
// | |
import SwiftUI | |
import WebKit | |
struct SwiftUIWebView: UIViewRepresentable{ | |
let url: URL? | |
func makeUIView(context: Context) -> WKWebView { | |
let prefs = WKWebpagePreferences() | |
prefs.allowsContentJavaScript = true | |
let config = WKWebViewConfiguration() | |
config.defaultWebpagePreferences = prefs | |
return WKWebView( | |
frame: .zero, configuration: config) | |
} | |
func updateUIView(_ uiView: WKWebView, context: Context) { | |
guard let myURL = url else {return} | |
let request = URLRequest(url: myURL) | |
uiView.load(request) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment