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.

A row's note no longer updates the window at every step of a scroll

Țugui Dragoș4201db50eacf
diff --git a/Peel/Views/InfoNote.swift b/Peel/Views/InfoNote.swift
index 35a798eb..9170bc56 100644
--- a/Peel/Views/InfoNote.swift
+++ b/Peel/Views/InfoNote.swift
@@ -13,6 +13,8 @@ struct InfoNote: View {
var isMarked = false
/// Only Home passes this; see `noteTint`.
var isAlbum = false
+ /// True for the note in each row of a list of items, whose button takes `RowButtonStyle`.
+ var isInRow = false
@State private var isOpen = false
@@ -22,7 +24,8 @@ struct InfoNote: View {
symbol: String? = nil,
footnote: Text? = nil,
isMarked: Bool = false,
- isAlbum: Bool = false
+ isAlbum: Bool = false,
+ isInRow: Bool = false
) {
self.name = name
self.detail = detail
@@ -30,6 +33,7 @@ struct InfoNote: View {
self.footnote = footnote
self.isMarked = isMarked
self.isAlbum = isAlbum
+ self.isInRow = isInRow
}
/// A marked note says so in its shape as well: by color alone it is the fainter of the two in light mode.
@@ -45,7 +49,7 @@ struct InfoNote: View {
.padding(4)
.contentShape(.rect)
}
- .buttonStyle(.plain)
+ .noteButtonStyle(isInRow: isInRow)
// The button takes clicks across its own frame, 4 points around the glyph; the layout keeps the glyph's.
.padding(-4)
.accessibilityLabel(isMarked ? Text("A caution about \(name)") : Text("What \(name) is for"))
@@ -106,6 +110,17 @@ struct NoteCard: View {
}
}
+private extension View {
+ @ViewBuilder
+ func noteButtonStyle(isInRow: Bool) -> some View {
+ if isInRow {
+ buttonStyle(RowButtonStyle())
+ } else {
+ buttonStyle(.plain)
+ }
+ }
+}
+
/// Home keeps the album's orange; everywhere else a note takes the accent color the user chose.
private func noteTint(isAlbum: Bool) -> Color {
isAlbum ? Album.orangeInk : .accentColor
diff --git a/Peel/Views/RemovalRow.swift b/Peel/Views/RemovalRow.swift
index 54a73950..d2205bb3 100644
--- a/Peel/Views/RemovalRow.swift
+++ b/Peel/Views/RemovalRow.swift
@@ -175,7 +175,8 @@ struct RemovalRow: View {
name: url.lastPathComponent,
detail: Text(explanation),
footnote: Text(verbatim: url.path(percentEncoded: false)),
- isMarked: warning != nil
+ isMarked: warning != nil,
+ isInRow: true
)
} else {
blank
diff --git a/Peel/Views/RowButtonStyle.swift b/Peel/Views/RowButtonStyle.swift
new file mode 100644
index 00000000..e55c2fe1
--- /dev/null
+++ b/Peel/Views/RowButtonStyle.swift
@@ -0,0 +1,41 @@
+import SwiftUI
+
+/// The style of a button in a List row. It looks like `.plain`, which draws the label at three quarters while it is
+/// pressed and at half while it is disabled, and it tracks the press with a gesture of its own.
+///
+/// A List takes keyboard focus as a whole, so a button in one of its rows is only ever pressed with the pointer or
+/// through accessibility. A standard style still makes each such button a place keyboard focus could go, and the
+/// window's list of those changes as rows scroll in and out, which updates the window's focus, its toolbar and the
+/// app's scenes at every step of a scroll. A button with this style costs none of that.
+struct RowButtonStyle: PrimitiveButtonStyle {
+ func makeBody(configuration: Configuration) -> some View {
+ PressableLabel(configuration: configuration)
+ }
+}
+
+/// Pressed while the pointer is down inside the label, and pressed for real only when it comes up there, as a
+/// button is.
+private struct PressableLabel: View {
+ let configuration: RowButtonStyle.Configuration
+ @Environment(\.isEnabled) private var isEnabled
+ @State private var isPressed = false
+ @State private var bounds = CGRect.zero
+
+ var body: some View {
+ configuration.label
+ .opacity(isEnabled ? (isPressed ? 0.75 : 1) : 0.5)
+ .onGeometryChange(for: CGRect.self) { CGRect(origin: .zero, size: $0.size) } action: { bounds = $0 }
+ .gesture(
+ DragGesture(minimumDistance: 0)
+ .onChanged { drag in
+ isPressed = isEnabled && bounds.contains(drag.location)
+ }
+ .onEnded { drag in
+ isPressed = false
+ if isEnabled, bounds.contains(drag.location) {
+ configuration.trigger()
+ }
+ }
+ )
+ }
+}