After load set webview to opaque

During the initial load we need the clear + !opaque settings so
the webview does not flash a white background in dark mode. But
after load we want to use the systemBackground colour and an
opaque background, so in dark mode the scrollbars are displayed
correctly. Without this iOS will display a dark scrollbar ontop
of the dark background.

Note that due to a bug in Webkit setting the scrollbar inset
colours doesn't seem to work in current iOS:

https://developer.apple.com/forums/thread/689654
This commit is contained in:
Jackson Harper
2022-03-06 09:16:38 -08:00
parent 0a38621a3a
commit e6b4d80de2
2 changed files with 6 additions and 1 deletions

View File

@ -33,7 +33,7 @@ public let readerViewNavBarHeight = 50.0
webView.navigationDelegate = context.coordinator
webView.isOpaque = false
webView.backgroundColor = UIColor.clear
webView.backgroundColor = .clear
webView.configuration.userContentController = contentController
webView.scrollView.delegate = context.coordinator
webView.scrollView.contentInset.top = readerViewNavBarHeight

View File

@ -42,6 +42,11 @@ extension WebAppViewCoordinator: WKNavigationDelegate {
decisionHandler(.allow)
}
}
func webView(_ webView: WKWebView, didFinish _: WKNavigation!) {
webView.isOpaque = true
webView.backgroundColor = .systemBackground
}
}
#if os(iOS)