From 8dc6e4e33281b59c53e52379b9eb4163088720ae Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sun, 7 Mar 2021 14:20:03 +0800 Subject: [PATCH 1/4] Contraint Changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Fixes #2850 • #2634: resizing vertically downards (expanding) is smooth --- .../Detail/DetailWebViewController.swift | 8 +------- Shared/Extensions/NSView-Extensions.swift | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Mac/MainWindow/Detail/DetailWebViewController.swift b/Mac/MainWindow/Detail/DetailWebViewController.swift index 857a34b1b..fbb97fa4f 100644 --- a/Mac/MainWindow/Detail/DetailWebViewController.swift +++ b/Mac/MainWindow/Detail/DetailWebViewController.swift @@ -90,13 +90,7 @@ final class DetailWebViewController: NSViewController, WKUIDelegate { // Use the safe area layout guides if they are available. if #available(OSX 11.0, *) { - let constraints = [ - webView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), - webView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor), - webView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor), - webView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor), - ] - NSLayoutConstraint.activate(constraints) + // These constraints have been removed as they were unsatisfyable after removing NSBox. } else { let constraints = [ webView.topAnchor.constraint(equalTo: view.topAnchor), diff --git a/Shared/Extensions/NSView-Extensions.swift b/Shared/Extensions/NSView-Extensions.swift index 2c5aff1d0..e9449208e 100644 --- a/Shared/Extensions/NSView-Extensions.swift +++ b/Shared/Extensions/NSView-Extensions.swift @@ -11,10 +11,20 @@ import AppKit extension NSView { func constraintsToMakeSubViewFullSize(_ subview: NSView) -> [NSLayoutConstraint] { - let leadingConstraint = NSLayoutConstraint(item: subview, attribute: .leading, relatedBy: .equal, toItem: self, attribute: .leading, multiplier: 1.0, constant: 0.0) - let trailingConstraint = NSLayoutConstraint(item: subview, attribute: .trailing, relatedBy: .equal, toItem: self, attribute: .trailing, multiplier: 1.0, constant: 0.0) - let topConstraint = NSLayoutConstraint(item: subview, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: 0.0) - let bottomConstraint = NSLayoutConstraint(item: subview, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .bottom, multiplier: 1.0, constant: 0.0) - return [leadingConstraint, trailingConstraint, topConstraint, bottomConstraint] + + if #available(macOS 11, *) { + let leadingConstraint = NSLayoutConstraint(item: subview, attribute: .leading, relatedBy: .equal, toItem: self.safeAreaLayoutGuide, attribute: .leading, multiplier: 1.0, constant: 0.0) + let trailingConstraint = NSLayoutConstraint(item: subview, attribute: .trailing, relatedBy: .equal, toItem: self.safeAreaLayoutGuide, attribute: .trailing, multiplier: 1.0, constant: 0.0) + let topConstraint = NSLayoutConstraint(item: subview, attribute: .top, relatedBy: .equal, toItem: self.safeAreaLayoutGuide, attribute: .top, multiplier: 1.0, constant: 0.0) + let bottomConstraint = NSLayoutConstraint(item: subview, attribute: .bottom, relatedBy: .equal, toItem: self.safeAreaLayoutGuide, attribute: .bottom, multiplier: 1.0, constant: 0.0) + return [leadingConstraint, trailingConstraint, topConstraint, bottomConstraint] + } else { + let leadingConstraint = NSLayoutConstraint(item: subview, attribute: .leading, relatedBy: .equal, toItem: self, attribute: .leading, multiplier: 1.0, constant: 0.0) + let trailingConstraint = NSLayoutConstraint(item: subview, attribute: .trailing, relatedBy: .equal, toItem: self, attribute: .trailing, multiplier: 1.0, constant: 0.0) + let topConstraint = NSLayoutConstraint(item: subview, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: 0.0) + let bottomConstraint = NSLayoutConstraint(item: subview, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .bottom, multiplier: 1.0, constant: 0.0) + return [leadingConstraint, trailingConstraint, topConstraint, bottomConstraint] + } + } } From 7a653db1dd553ce723c27565f608887545988f15 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sun, 7 Mar 2021 15:51:43 +0800 Subject: [PATCH 2/4] typo --- Mac/MainWindow/Detail/DetailWebViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mac/MainWindow/Detail/DetailWebViewController.swift b/Mac/MainWindow/Detail/DetailWebViewController.swift index fbb97fa4f..b661a3e86 100644 --- a/Mac/MainWindow/Detail/DetailWebViewController.swift +++ b/Mac/MainWindow/Detail/DetailWebViewController.swift @@ -90,7 +90,7 @@ final class DetailWebViewController: NSViewController, WKUIDelegate { // Use the safe area layout guides if they are available. if #available(OSX 11.0, *) { - // These constraints have been removed as they were unsatisfyable after removing NSBox. + // These constraints have been removed as they were unsatisfiable after removing NSBox. } else { let constraints = [ webView.topAnchor.constraint(equalTo: view.topAnchor), From 86981a0c5b29d50c9d1d23a337f987572283fbab Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sun, 7 Mar 2021 16:47:39 +0800 Subject: [PATCH 3/4] #2597 Fixes #2597: Toggles a small window height change to get webview to behave on macOS 11. --- Mac/MainWindow/Detail/DetailWebViewController.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Mac/MainWindow/Detail/DetailWebViewController.swift b/Mac/MainWindow/Detail/DetailWebViewController.swift index b661a3e86..5ad51eae5 100644 --- a/Mac/MainWindow/Detail/DetailWebViewController.swift +++ b/Mac/MainWindow/Detail/DetailWebViewController.swift @@ -116,6 +116,7 @@ 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.didExitFullScreenNotification, object: nil) webView.loadFileURL(ArticleRenderer.blank.url, allowingReadAccessTo: ArticleRenderer.blank.baseURL) } @@ -141,6 +142,18 @@ final class DetailWebViewController: NSViewController, WKUIDelegate { } } + /// On macOS 11, when a user exits full screen, 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, *) { + // On macOS 11, at the end of a resize down + guard var frame = self.view.window?.frame else { + return + } + frame.size = NSSize(width: self.view.window!.frame.width, height: self.view.window!.frame.height - 1) + self.view.window!.setFrame(frame, display: true) + } + } + // MARK: Media Functions func stopMediaPlayback() { From 2e12f5a078f5c3a5223ccf039cab94df6dfb983d Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sun, 7 Mar 2021 21:34:52 +0800 Subject: [PATCH 4/4] removes code comment --- Mac/MainWindow/Detail/DetailWebViewController.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Mac/MainWindow/Detail/DetailWebViewController.swift b/Mac/MainWindow/Detail/DetailWebViewController.swift index 5ad51eae5..5c6f9a5ed 100644 --- a/Mac/MainWindow/Detail/DetailWebViewController.swift +++ b/Mac/MainWindow/Detail/DetailWebViewController.swift @@ -145,7 +145,6 @@ final class DetailWebViewController: NSViewController, WKUIDelegate { /// On macOS 11, when a user exits full screen, 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, *) { - // On macOS 11, at the end of a resize down guard var frame = self.view.window?.frame else { return }