Fix web view compilation issues
This commit is contained in:
parent
b749cfe5f4
commit
4b8b29a657
@ -8,6 +8,11 @@
|
|||||||
import WidgetKit
|
import WidgetKit
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import WebKit
|
import WebKit
|
||||||
|
#if os(iOS) || os(tvOS)
|
||||||
|
import UIKit
|
||||||
|
#else
|
||||||
|
import AppKit
|
||||||
|
#endif
|
||||||
|
|
||||||
#if os(iOS) || os(tvOS)
|
#if os(iOS) || os(tvOS)
|
||||||
typealias PlatformViewRepresentable = UIViewRepresentable
|
typealias PlatformViewRepresentable = UIViewRepresentable
|
||||||
@ -26,9 +31,18 @@ struct HTMLClockView: PlatformViewRepresentable {
|
|||||||
|
|
||||||
private func createWebView() -> WKWebView {
|
private func createWebView() -> WKWebView {
|
||||||
let webView = WKWebView()
|
let webView = WKWebView()
|
||||||
|
#if os(iOS) || os(tvOS)
|
||||||
webView.isOpaque = false
|
webView.isOpaque = false
|
||||||
webView.backgroundColor = .clear
|
webView.backgroundColor = .clear
|
||||||
webView.scrollView.isScrollEnabled = false
|
webView.scrollView.isScrollEnabled = false
|
||||||
|
#else
|
||||||
|
webView.setValue(false, forKey: "drawsBackground")
|
||||||
|
webView.isOpaque = false
|
||||||
|
if let scrollView = webView.value(forKey: "scrollView") as? NSScrollView {
|
||||||
|
scrollView.hasVerticalScroller = false
|
||||||
|
scrollView.hasHorizontalScroller = false
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if let url = Bundle.main.url(forResource: "analog-clock", withExtension: "html") {
|
if let url = Bundle.main.url(forResource: "analog-clock", withExtension: "html") {
|
||||||
webView.loadFileURL(url, allowingReadAccessTo: url.deletingLastPathComponent())
|
webView.loadFileURL(url, allowingReadAccessTo: url.deletingLastPathComponent())
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user