Moves frame tweaking to end of liveResize

This commit is contained in:
Stuart Breckenridge 2021-03-08 10:28:51 +08:00
parent 27b9326d07
commit a59df3e6fc
No known key found for this signature in database
GPG Key ID: ED2F112EEA9EF8A5
2 changed files with 13 additions and 16 deletions

View File

@ -53,6 +53,19 @@ final class DetailWebView: WKWebView {
override func viewDidEndLiveResize() {
super.viewDidEndLiveResize()
evaluateJavaScript("document.body.style.overflow = 'visible';", completionHandler: nil)
/// On macOS 11, when a user exits full screen or zoomed mode (full screen with menu bar showing), the webview's origin.y is offset by a sizeable amount. This function adjusts the height of the window height by 1pt which puts the webview back in the correct place. This is an issue with SwiftUI and AppKit.
if #available(macOS 11, *) {
guard var frame = window?.frame else {
return
}
frame.size = NSSize(width: window!.frame.width, height: window!.frame.height - 1)
window!.setFrame(frame, display: false)
frame.size = NSSize(width: window!.frame.width, height: window!.frame.height + 1)
window!.setFrame(frame, display: false)
}
}
}

View File

@ -116,7 +116,6 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
NotificationCenter.default.addObserver(self, selector: #selector(avatarDidBecomeAvailable(_:)), name: .AvatarDidBecomeAvailable, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(bigSurOffsetFix(_:)), name: NSWindow.didChangeScreenNotification, object: nil)
webView.loadFileURL(ArticleRenderer.blank.url, allowingReadAccessTo: ArticleRenderer.blank.baseURL)
}
@ -142,21 +141,6 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
}
}
/// On macOS 11, when a user exits full screen or zoomed mode (full screen with menu bar showing), the webview's origin.y is offset by a sizeable amount. This function adjusts the height of the window height by 1pt which puts the webview back in the correct place. This is an issue with SwiftUI and AppKit.
@objc func bigSurOffsetFix(_ note: Notification) {
if #available(macOS 11, *) {
print(note.name)
guard var frame = view.window?.frame else {
return
}
frame.size = NSSize(width: view.window!.frame.width, height: view.window!.frame.height - 1)
view.window!.setFrame(frame, display: false)
frame.size = NSSize(width: view.window!.frame.width, height: view.window!.frame.height + 1)
view.window!.setFrame(frame, display: false)
}
}
// MARK: Media Functions
func stopMediaPlayback() {