Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Blur what scrolls under the top of every list on macOS 27

Țugui Dragoș12e960311cca
diff --git a/Peel/Navigation/ListColumn.swift b/Peel/Navigation/ListColumn.swift
index e422bd88..086d41a5 100644
--- a/Peel/Navigation/ListColumn.swift
+++ b/Peel/Navigation/ListColumn.swift
@@ -45,6 +45,38 @@ extension View {
func listColumn() -> some View {
modifier(ListColumnWidth())
}
+
+ /// Builds the list column only once it knows the title bar above it, keeping the column's width meanwhile. On
+ /// macOS 27, a list built before then, as the window changes from two columns to three, gets neither the blur
+ /// under its bar at the top nor the margin of its scroll bar.
+ @ViewBuilder
+ func builtWithItsTitleBar() -> some View {
+ if #available(macOS 27, *) {
+ BuiltWithItsTitleBar(column: self)
+ .navigationSplitViewColumnWidth(min: ListColumn.minimum, ideal: ListColumn.minimum)
+ } else {
+ self
+ }
+ }
+}
+
+@available(macOS 27, *)
+private struct BuiltWithItsTitleBar<Column: View>: View {
+ let column: Column
+ @State private var knowsItsTitleBar = false
+
+ var body: some View {
+ Group {
+ if knowsItsTitleBar {
+ column
+ } else {
+ Color.clear
+ }
+ }
+ .onGeometryChange(for: Bool.self) { $0.safeAreaInsets.top > 0 } action: { known in
+ if known { knowsItsTitleBar = true }
+ }
+ }
}
private struct ListColumnWidth: ViewModifier {
diff --git a/Peel/Navigation/TitleBarBackground.swift b/Peel/Navigation/TitleBarBackground.swift
index 7a57db61..ec0d1b7d 100644
--- a/Peel/Navigation/TitleBarBackground.swift
+++ b/Peel/Navigation/TitleBarBackground.swift
@@ -1,13 +1,13 @@
import SwiftUI
extension View {
- /// Keeps the title bar clear on macOS 27: no background behind each column's section of it, and, outside the
- /// sidebar's head, nothing drawn over what scrolls beneath it.
+ /// Keeps the title bar clear on macOS 27, as it is on macOS 26. There the window draws a background behind each
+ /// column's section of the title bar even when nothing is under it; without it, what scrolls beneath the title
+ /// bar is still blurred by the scroll edge effect.
@ViewBuilder
func clearTitleBar() -> some View {
if #available(macOS 27, *) {
toolbarBackgroundVisibility(.hidden, for: .windowToolbar)
- .scrollEdgeEffectHidden(true, for: .top)
} else {
self
}
diff --git a/Peel/Navigation/ToolSidebar.swift b/Peel/Navigation/ToolSidebar.swift
index b3be232a..3a2c4c52 100644
--- a/Peel/Navigation/ToolSidebar.swift
+++ b/Peel/Navigation/ToolSidebar.swift
@@ -75,8 +75,8 @@ struct ToolSidebar: View {
group(.storage, isExpanded: $isStorageExpanded)
group(.system, isExpanded: $isSystemExpanded)
}
- // A bar on every macOS, unlike a page's (`edgeBar`): the face is glass on the sidebar's glass, and glass
- // cannot sample other glass, so the bar's own edge effect is what blurs the rows passing under it.
+ // A bar on every macOS: the face is glass on the sidebar's glass, and glass cannot sample other glass, so the
+ // bar's own edge effect is what blurs the rows passing under it.
.safeAreaBar(edge: .top, spacing: 0) { mascot }
.takesFocusWhenNothingHasIt()
.onReceive(
diff --git a/Peel/Views/ContentView.swift b/Peel/Views/ContentView.swift
index 527149ee..ce290966 100644
--- a/Peel/Views/ContentView.swift
+++ b/Peel/Views/ContentView.swift
@@ -312,6 +312,7 @@ struct ContentView: View {
.listColumn()
}
}
+ .builtWithItsTitleBar()
// A scroll view that keeps its own background paints a panel of its own inside the column:
// `ContentUnavailableView` is the visible case, drawing a lighter slab whose top edge reads as a
// line under the title bar. Hidden, the window's own material shows through instead.
diff --git a/Peel/Views/EdgeBar.swift b/Peel/Views/EdgeBar.swift
index f19abe2b..5d58c944 100644
--- a/Peel/Views/EdgeBar.swift
+++ b/Peel/Views/EdgeBar.swift
@@ -2,14 +2,32 @@ import SwiftUI
extension View {
/// A bar across the top or the foot of a scrolling page, such as a search field or a button with its note.
- /// macOS 27 draws a background across the page behind a bar even when nothing is under it, so there the bar
- /// takes room as an inset instead, with nothing drawn behind it.
+ /// What scrolls under a bar at the top blurs, as macOS draws it. At the foot, macOS 27 draws a background across
+ /// the page behind a bar even when nothing is under it, so there a bar at the foot takes room as an inset
+ /// instead, with nothing drawn behind it.
@ViewBuilder
func edgeBar(_ edge: VerticalEdge, spacing: CGFloat? = nil, @ViewBuilder content: () -> some View) -> some View {
if #available(macOS 27, *) {
- safeAreaInset(edge: edge, spacing: spacing ?? 0, content: content)
+ if edge == .top {
+ TopBar(page: self, spacing: spacing, bar: content())
+ } else {
+ safeAreaInset(edge: edge, spacing: spacing ?? 0, content: content)
+ }
} else {
safeAreaBar(edge: edge, spacing: spacing, content: content)
}
}
}
+
+/// A bar at the top of a page on macOS 27, put on the page inside a view of its own: there, a bar put directly on a
+/// case of a `switch` can crash SwiftUI when that case is chosen.
+@available(macOS 27, *)
+private struct TopBar<Page: View, Bar: View>: View {
+ let page: Page
+ let spacing: CGFloat?
+ let bar: Bar
+
+ var body: some View {
+ page.safeAreaBar(edge: .top, spacing: spacing) { bar }
+ }
+}