Merge pull request #53 from ok2/codex/fix-bugs-in-cobie-analog-clock-widget
Fix WKWebView setup in widget
This commit is contained in:
commit
9256d5ecb7
@ -8,6 +8,11 @@
|
||||
import WidgetKit
|
||||
import SwiftUI
|
||||
import WebKit
|
||||
#if os(iOS) || os(tvOS)
|
||||
import UIKit
|
||||
#else
|
||||
import AppKit
|
||||
#endif
|
||||
|
||||
#if os(iOS) || os(tvOS)
|
||||
typealias PlatformViewRepresentable = UIViewRepresentable
|
||||
@ -26,9 +31,18 @@ struct HTMLClockView: PlatformViewRepresentable {
|
||||
|
||||
private func createWebView() -> WKWebView {
|
||||
let webView = WKWebView()
|
||||
#if os(iOS) || os(tvOS)
|
||||
webView.isOpaque = false
|
||||
webView.backgroundColor = .clear
|
||||
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") {
|
||||
webView.loadFileURL(url, allowingReadAccessTo: url.deletingLastPathComponent())
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user