Skip to content

Instantly share code, notes, and snippets.

@IhwanID
Created December 13, 2020 07:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IhwanID/637c45f7ecc0ba7fc091de5369cc84d3 to your computer and use it in GitHub Desktop.
Save IhwanID/637c45f7ecc0ba7fc091de5369cc84d3 to your computer and use it in GitHub Desktop.
SwiftUI Webview Using WKWebView & Webkit
//
// 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