From 1eb4002c788de32cfaedc0138383a1dfde45dfda Mon Sep 17 00:00:00 2001 From: Mario Guzman Date: Sat, 1 Oct 2022 12:03:51 -0700 Subject: [PATCH] Fix timeline, details views for proper toolbar scroll behavior Both the details and timeline container views were not extending behind the toolbar and thus content would not show when scrolled behind it. Top anchors should anchor to the top of the super view rather than safe area guides and AppKit automatically adjusts the scroll insets for NSToolbar and optionally (if available) NSTitlebarAccessoryViewController. This allows for the divider to appear when content scrolls behind it and for content to "shine through" the translucency of the NSToolbar. --- Mac/Base.lproj/MainWindow.storyboard | 44 +++++++++++-------- .../Detail/DetailContainerView.swift | 5 +-- Shared/Extensions/NSView-Extensions.swift | 20 +++------ 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/Mac/Base.lproj/MainWindow.storyboard b/Mac/Base.lproj/MainWindow.storyboard index 9d501c240..323606b38 100644 --- a/Mac/Base.lproj/MainWindow.storyboard +++ b/Mac/Base.lproj/MainWindow.storyboard @@ -3,6 +3,7 @@ + @@ -294,27 +295,23 @@ - - - - + - + - + - - - - - + + + + @@ -332,16 +329,24 @@ - + - + + + + + + + + + - + diff --git a/Mac/MainWindow/Detail/DetailContainerView.swift b/Mac/MainWindow/Detail/DetailContainerView.swift index 01480ad40..b98e18b0d 100644 --- a/Mac/MainWindow/Detail/DetailContainerView.swift +++ b/Mac/MainWindow/Detail/DetailContainerView.swift @@ -30,11 +30,10 @@ final class DetailContainerView: NSView, NSTextFinderBarContainer { contentView.translatesAutoresizingMaskIntoConstraints = false addSubview(contentView, positioned: .below, relativeTo: detailStatusBarView) - // Constrain the content view to fill the available space on all sides except the top, which we'll constrain to the find bar - var constraints = constraintsToMakeSubViewFullSize(contentView).filter { $0.firstAttribute != .top } + // Constrain the content view to fill the available space on all sides + var constraints = constraintsToMakeSubViewFullSize(contentView) constraints.append(findBarContainerView.topAnchor.constraint(equalTo: self.safeAreaLayoutGuide.topAnchor)) - constraints.append(findBarContainerView.bottomAnchor.constraint(equalTo: contentView.topAnchor)) NSLayoutConstraint.activate(constraints) contentViewConstraints = constraints } diff --git a/Shared/Extensions/NSView-Extensions.swift b/Shared/Extensions/NSView-Extensions.swift index e9449208e..2c5aff1d0 100644 --- a/Shared/Extensions/NSView-Extensions.swift +++ b/Shared/Extensions/NSView-Extensions.swift @@ -11,20 +11,10 @@ import AppKit extension NSView { func constraintsToMakeSubViewFullSize(_ subview: NSView) -> [NSLayoutConstraint] { - - 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] - } - + 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] } }