mirror of
https://github.com/kean/Pulse.git
synced 2026-05-30 21:07:33 +00:00
49 lines
1.1 KiB
Swift
49 lines
1.1 KiB
Swift
// The MIT License (MIT)
|
|
//
|
|
// Copyright (c) 2020-2024 Alexander Grebenyuk (github.com/kean).
|
|
|
|
import SwiftUI
|
|
|
|
#if os(iOS) || os(visionOS)
|
|
|
|
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
|