Skip to content

Commit 994190b

Browse files
Refine interface motion and surface chrome
Share spring timing that honors Reduce Motion, and animate controls, cards, the search panel, and the HUD consistently.
1 parent 220e497 commit 994190b

9 files changed

Lines changed: 628 additions & 193 deletions

‎Sources/CategoryViews.swift‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,15 @@ private struct CategoryPickerPanel: View {
8989
.foregroundStyle(Color.accentColor)
9090
.padding(.horizontal, 10)
9191
.padding(.vertical, 8)
92-
.background(Color.accentColor.opacity(0.08), in: RoundedRectangle(cornerRadius: 8))
93-
.contentShape(RoundedRectangle(cornerRadius: 8))
92+
.background(Color.accentColor.opacity(0.08), in: Radius.shape(Radius.control))
93+
.contentShape(Radius.shape(Radius.control))
9494
}
9595
.buttonStyle(.plain)
9696
.accessibilityLabel(preferences.text("category.new"))
9797
}
9898
.padding(14)
9999
.frame(width: 272)
100-
.background(Color(nsColor: .controlBackgroundColor), in: RoundedRectangle(cornerRadius: 12))
101-
.overlay {
102-
RoundedRectangle(cornerRadius: 12)
103-
.strokeBorder(Color.primary.opacity(0.07), lineWidth: 1)
104-
.allowsHitTesting(false)
105-
}
100+
.elevatedCard()
106101
}
107102
}
108103

@@ -111,6 +106,7 @@ private struct CategoryPickerRow: View {
111106
let category: CustomAppCategory
112107
let isSelected: Bool
113108
let action: () -> Void
109+
@Environment(\.accessibilityReduceMotion) private var reduceMotion
114110
@State private var isHovering = false
115111

116112
private var emblemTint: Color { isSelected ? .accentColor : .secondary }
@@ -122,7 +118,7 @@ private struct CategoryPickerRow: View {
122118
.font(.system(size: 11, weight: .semibold))
123119
.foregroundStyle(emblemTint)
124120
.frame(width: 22, height: 22)
125-
.background(emblemTint.opacity(0.10), in: RoundedRectangle(cornerRadius: 6))
121+
.background(emblemTint.opacity(0.10), in: Radius.shape(Radius.control))
126122

127123
Text(category.name)
128124
.font(.callout.weight(isSelected ? .medium : .regular))
@@ -139,16 +135,16 @@ private struct CategoryPickerRow: View {
139135
.padding(.horizontal, 9)
140136
.padding(.vertical, 7)
141137
.background(
142-
RoundedRectangle(cornerRadius: 8)
138+
Radius.shape(Radius.control)
143139
.fill(isSelected ? Color.accentColor.opacity(isHovering ? 0.13 : 0.09)
144140
: Color.primary.opacity(isHovering ? 0.05 : 0.02))
145141
)
146-
.contentShape(RoundedRectangle(cornerRadius: 8))
142+
.contentShape(Radius.shape(Radius.control))
147143
}
148144
.buttonStyle(.plain)
149145
.onHover { isHovering = $0 }
150-
.animation(.easeOut(duration: 0.16), value: isHovering)
151-
.animation(.easeOut(duration: 0.16), value: isSelected)
146+
.animation(Motion.content(reduced: reduceMotion), value: isHovering)
147+
.animation(Motion.content(reduced: reduceMotion), value: isSelected)
152148
.accessibilityLabel(category.name)
153149
.accessibilityValue(isSelected ? "1" : "0")
154150
}
@@ -189,7 +185,12 @@ struct CategoryEditor: View {
189185
VStack(alignment: .leading, spacing: 8) {
190186
Text(preferences.text("category.name")).font(.callout.weight(.medium))
191187
TextField(preferences.text("category.namePlaceholder"), text: $name)
192-
.textFieldStyle(.roundedBorder).focused($focused)
188+
.textFieldStyle(.plain)
189+
.font(.body)
190+
.focused($focused)
191+
.padding(.horizontal, 8)
192+
.padding(.vertical, 6)
193+
.fieldChrome(focused: focused)
193194
.accessibilityLabel(preferences.text("category.name"))
194195
.accessibilityIdentifier("category.name")
195196
.onSubmit(save)
@@ -327,7 +328,7 @@ private struct CategoryEmblem: View {
327328
Image(systemName: "folder")
328329
.font(.system(size: 22, weight: .medium)).foregroundStyle(Color.accentColor)
329330
.frame(width: 48, height: 48)
330-
.background(Color.accentColor.opacity(0.1), in: RoundedRectangle(cornerRadius: 12))
331+
.background(Color.accentColor.opacity(0.1), in: Radius.shape(Radius.surface))
331332
.accessibilityHidden(true)
332333
}
333334
}

‎Sources/Components.swift‎

Lines changed: 172 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
import SwiftUI
22
import AppKit
33

4+
enum Radius {
5+
static let control: CGFloat = 6
6+
static let group: CGFloat = 10
7+
static let surface: CGFloat = 14
8+
9+
static func shape(_ radius: CGFloat) -> RoundedRectangle {
10+
RoundedRectangle(cornerRadius: radius, style: .continuous)
11+
}
12+
}
13+
14+
enum AppSurface {
15+
static let card = Color(nsColor: NSColor(name: nil, dynamicProvider: cardColor))
16+
17+
/// `controlBackgroundColor` is white above the window in light mode, but darker than it in dark mode.
18+
private static func cardColor(_ appearance: NSAppearance) -> NSColor {
19+
var resolved = NSColor.controlBackgroundColor
20+
appearance.performAsCurrentDrawingAppearance {
21+
let window = NSColor.windowBackgroundColor.usingColorSpace(.sRGB) ?? .windowBackgroundColor
22+
let control = NSColor.controlBackgroundColor.usingColorSpace(.sRGB) ?? .controlBackgroundColor
23+
if luminance(control) + 0.01 >= luminance(window) {
24+
resolved = control
25+
} else {
26+
resolved = window.blended(withFraction: 0.08, of: .white) ?? window
27+
}
28+
}
29+
return resolved
30+
}
31+
32+
private static func luminance(_ color: NSColor) -> CGFloat {
33+
0.2126 * color.redComponent + 0.7152 * color.greenComponent + 0.0722 * color.blueComponent
34+
}
35+
}
36+
437
struct AppIcon: View {
538
let app: AppEntry
639
let size: CGFloat
@@ -12,47 +45,118 @@ struct AppIcon: View {
1245
}
1346

1447
struct IconButtonChrome: ViewModifier {
15-
var tint: Color = .accentColor
48+
var tint: Color = .primary
1649
var isPressed = false
1750
@State private var isHovering = false
1851
@Environment(\.isEnabled) private var isEnabled
52+
@Environment(\.accessibilityReduceMotion) private var reduceMotion
53+
54+
private var fillOpacity: Double {
55+
guard isEnabled else { return 0 }
56+
if isPressed { return 0.16 }
57+
if isHovering { return 0.10 }
58+
return 0.06
59+
}
60+
61+
private var strokeOpacity: Double {
62+
guard isEnabled, isHovering || isPressed else { return 0 }
63+
return isPressed ? 0.22 : 0.16
64+
}
1965

2066
func body(content: Content) -> some View {
2167
content
2268
.labelStyle(.iconOnly)
2369
.font(.system(size: 13, weight: .medium))
2470
.foregroundStyle(isEnabled ? tint : Color(nsColor: .tertiaryLabelColor))
2571
.frame(width: 28, height: 28)
26-
.background(
27-
RoundedRectangle(cornerRadius: 8)
28-
.fill(tint.opacity(isPressed ? 0.16 : isHovering ? 0.12 : 0.07))
29-
)
72+
.background(Color.primary.opacity(fillOpacity), in: Radius.shape(Radius.control))
3073
.overlay {
31-
RoundedRectangle(cornerRadius: 8)
32-
.strokeBorder(tint.opacity(isPressed ? 0.28 : isHovering ? 0.22 : 0.12), lineWidth: 1)
74+
Radius.shape(Radius.control)
75+
.strokeBorder(Color.primary.opacity(strokeOpacity), lineWidth: 1)
3376
}
34-
.contentShape(RoundedRectangle(cornerRadius: 8))
77+
.contentShape(Radius.shape(Radius.control))
3578
.onHover { isHovering = $0 && isEnabled }
36-
.animation(.easeOut(duration: 0.18), value: isHovering)
37-
.animation(.easeOut(duration: 0.12), value: isPressed)
79+
.onChange(of: isEnabled) { _, enabled in
80+
if !enabled { isHovering = false }
81+
}
82+
.animation(Motion.feedback(reduced: reduceMotion), value: isHovering)
83+
.animation(Motion.feedback(reduced: reduceMotion), value: isPressed)
84+
.animation(Motion.feedback(reduced: reduceMotion), value: isEnabled)
3885
}
3986
}
4087

4188
extension View {
42-
func iconButtonChrome(tint: Color = .accentColor, isPressed: Bool = false) -> some View {
89+
func iconButtonChrome(tint: Color = .primary, isPressed: Bool = false) -> some View {
4390
modifier(IconButtonChrome(tint: tint, isPressed: isPressed))
4491
}
4592
}
4693

4794
struct IconButtonStyle: ButtonStyle {
48-
var tint: Color = .accentColor
95+
var tint: Color = .primary
4996

5097
func makeBody(configuration: Configuration) -> some View {
5198
configuration.label
5299
.iconButtonChrome(tint: tint, isPressed: configuration.isPressed)
53100
}
54101
}
55102

103+
/// Neutral hover and press for controls that otherwise look like static text.
104+
struct QuietAffordance: ViewModifier {
105+
var cornerRadius: CGFloat = Radius.control
106+
@Environment(\.accessibilityReduceMotion) private var reduceMotion
107+
@State private var hovering = false
108+
@GestureState private var pressed = false
109+
110+
func body(content: Content) -> some View {
111+
content
112+
.background {
113+
Radius.shape(cornerRadius)
114+
.fill(Color.primary.opacity(pressed ? 0.08 : hovering ? 0.04 : 0))
115+
}
116+
.scaleEffect(reduceMotion || !pressed ? 1 : 0.985)
117+
.animation(Motion.feedback(reduced: reduceMotion), value: hovering)
118+
.animation(Motion.feedback(reduced: reduceMotion), value: pressed)
119+
.onHover { hovering = $0 }
120+
.simultaneousGesture(DragGesture(minimumDistance: 0).updating($pressed) { _, state, _ in
121+
state = true
122+
})
123+
}
124+
}
125+
126+
extension View {
127+
func quietAffordance(cornerRadius: CGFloat = Radius.control) -> some View {
128+
modifier(QuietAffordance(cornerRadius: cornerRadius))
129+
}
130+
}
131+
132+
struct QuietPressButtonStyle: ButtonStyle {
133+
var cornerRadius: CGFloat = Radius.control
134+
135+
func makeBody(configuration: Configuration) -> some View {
136+
QuietPressButton(cornerRadius: cornerRadius, isPressed: configuration.isPressed, label: configuration.label)
137+
}
138+
}
139+
140+
private struct QuietPressButton: View {
141+
@Environment(\.accessibilityReduceMotion) private var reduceMotion
142+
@State private var hovering = false
143+
var cornerRadius: CGFloat
144+
var isPressed: Bool
145+
var label: ButtonStyleConfiguration.Label
146+
147+
var body: some View {
148+
label
149+
.background {
150+
Radius.shape(cornerRadius)
151+
.fill(Color.primary.opacity(isPressed ? 0.08 : hovering ? 0.04 : 0))
152+
}
153+
.scaleEffect(reduceMotion || !isPressed ? 1 : 0.985)
154+
.animation(Motion.feedback(reduced: reduceMotion), value: hovering)
155+
.animation(Motion.feedback(reduced: reduceMotion), value: isPressed)
156+
.onHover { hovering = $0 }
157+
}
158+
}
159+
56160
struct EmptyState: View {
57161
let symbol: String
58162
let title: String
@@ -95,11 +199,62 @@ struct SearchField: View {
95199
}
96200
}
97201
.font(.callout).padding(.horizontal, 9).padding(.vertical, 7)
98-
.background(.quaternary.opacity(0.6), in: RoundedRectangle(cornerRadius: 7))
99-
.overlay {
100-
RoundedRectangle(cornerRadius: 7)
101-
.strokeBorder(isFocused ? Color.accentColor.opacity(0.7) : .clear, lineWidth: 2)
202+
.fieldChrome(focused: isFocused)
203+
}
204+
}
205+
206+
struct FieldChrome: ViewModifier {
207+
var focused: Bool
208+
var radius: CGFloat = Radius.control
209+
@Environment(\.accessibilityReduceMotion) private var reduceMotion
210+
211+
func body(content: Content) -> some View {
212+
content
213+
.background(Color(nsColor: .controlBackgroundColor), in: Radius.shape(radius))
214+
.overlay {
215+
FieldFocusRing(focused: focused, radius: radius)
216+
.animation(Motion.feedback(reduced: reduceMotion), value: focused)
217+
}
218+
}
219+
}
220+
221+
private struct FieldFocusRing: View {
222+
var focused: Bool
223+
var radius: CGFloat
224+
225+
var body: some View {
226+
ZStack {
227+
Radius.shape(radius)
228+
.strokeBorder(focused ? Color.accentColor : Color.primary.opacity(0.12), lineWidth: 1)
229+
Radius.shape(radius)
230+
.inset(by: -1.5)
231+
.stroke(Color.accentColor.opacity(focused ? 0.28 : 0), lineWidth: 3)
102232
}
233+
.allowsHitTesting(false)
234+
}
235+
}
236+
237+
struct ElevatedCard: ViewModifier {
238+
var radius: CGFloat = Radius.surface
239+
240+
func body(content: Content) -> some View {
241+
content
242+
.background(AppSurface.card, in: Radius.shape(radius))
243+
.overlay {
244+
Radius.shape(radius)
245+
.strokeBorder(Color.primary.opacity(0.08), lineWidth: 1)
246+
.allowsHitTesting(false)
247+
}
248+
}
249+
}
250+
251+
extension View {
252+
func fieldChrome(focused: Bool, radius: CGFloat = Radius.control) -> some View {
253+
modifier(FieldChrome(focused: focused, radius: radius))
254+
}
255+
256+
func elevatedCard(radius: CGFloat = Radius.surface) -> some View {
257+
modifier(ElevatedCard(radius: radius))
103258
}
104259
}
105260

@@ -110,7 +265,7 @@ struct ShortcutHint: View {
110265
HStack(spacing: 5) {
111266
Text(keys).font(.system(size: 11, weight: .medium, design: .monospaced))
112267
.padding(.horizontal, 5).padding(.vertical, 3)
113-
.background(.quaternary, in: RoundedRectangle(cornerRadius: 4))
268+
.background(.quaternary, in: Radius.shape(Radius.control))
114269
Text(title).font(.caption)
115270
}
116271
.foregroundStyle(.secondary)

0 commit comments

Comments
 (0)