Files
2022-07-30 22:40:03 -04:00

46 lines
1.1 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// The MIT License (MIT)
//
// Copyright (c) 20202022 Alexander Grebenyuk (github.com/kean).
import SwiftUI
#if os(iOS)
import WebKit
import UIKit
struct WebView: UIViewRepresentable {
let data: Data
let contentType: String
func makeUIView(context: Context) -> WKWebView {
let webView = WKWebView(frame: .zero, configuration: .init())
webView.load(data, mimeType: contentType, characterEncodingName: "UTF8", baseURL: FileManager.default.temporaryDirectory)
return webView
}
func updateUIView(_ webView: WKWebView, context: Context) {
// Do nothing
}
}
#endif
#if os(macOS)
import WebKit
import AppKit
struct WebView: NSViewRepresentable {
let data: Data
let contentType: String
func makeNSView(context: Context) -> WKWebView {
let webView = WKWebView(frame: .zero, configuration: .init())
webView.load(data, mimeType: contentType, characterEncodingName: "UTF8", baseURL: FileManager.default.temporaryDirectory)
return webView
}
func updateNSView(_ nsView: WKWebView, context: Context) {
// Do nothing
}
}
#endif