Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions frontend/ios/App/Watch/RestHold.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct RestView: View {
Button { store.fixLast() } label: {
Image(systemName: "chevron.left").font(.system(size: 14, weight: .bold)).frame(width: 34, height: 34)
}
.buttonStyle(.plain)
.buttonStyle(PressStyle())
.glass(Circle(), fill: Theme.surface, dimmed: false)
.opacity(dimmed ? 0 : 1)
.accessibilityLabel(Text("Back"))
Expand Down Expand Up @@ -229,6 +229,7 @@ struct OutlineCapsule: ButtonStyle {
.glass(Capsule(), fill: configuration.isPressed ? Theme.surface2 : Color.clear, dimmed: false)
.overlay(Capsule().strokeBorder(.white.opacity(Theme.hasGlass ? 0 : 0.5), lineWidth: 1.5))
.contentShape(Capsule())
.opacity(configuration.isPressed ? 0.6 : 1) // the glass ignores `fill`: the press shows here
}
}

Expand Down Expand Up @@ -268,7 +269,7 @@ struct EffortChips: View {
.frame(minHeight: tall ? 38 : 34)
.glass(Capsule(), tint: Effort.color(kind, rated).opacity(0.35), fill: Effort.color(kind, rated).opacity(0.18), dimmed: false)
}
.buttonStyle(.plain)
.buttonStyle(PressStyle())
.accessibilityLabel(Text("Effort"))
.accessibilityValue(Text(verbatim: "\(Effort.name(kind)) \(Effort.chipLabel(kind, rated))"))
.accessibilityHint(Text("Tap to change it."))
Expand Down
2 changes: 1 addition & 1 deletion frontend/ios/App/Watch/SessionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ struct OverviewRowView: View {
.stroke(row.current ? accent : Theme.surface2, lineWidth: row.current ? 1.5 : (dimmed ? 1 : 0)))
.contentShape(RoundedRectangle(cornerRadius: 12, style: .continuous))
}
.buttonStyle(.plain)
.buttonStyle(PressStyle())
// Not while a hold runs: its seconds belong to the exercise on the set page.
.disabled(store.holdEndsAt != nil)
.accessibilityElement(children: .ignore)
Expand Down
15 changes: 8 additions & 7 deletions frontend/ios/App/Watch/SetPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ struct SetPanel: View {
.frame(minHeight: 24)
.glass(Capsule(), tint: store.fixSide == side ? Theme.teal : nil, fill: store.fixSide == side ? Theme.teal : Theme.teal.opacity(0.18), dimmed: dimmed)
}
.buttonStyle(.plain)
.buttonStyle(PressStyle())
.accessibilityAddTraits(store.fixSide == side ? AccessibilityTraits.isSelected : AccessibilityTraits())
}
}
Expand All @@ -222,7 +222,7 @@ struct SetPanel: View {
.frame(minHeight: 24)
.glass(Capsule(), tint: color.opacity(0.35), fill: color.opacity(0.18), dimmed: dimmed)
}
.buttonStyle(.plain)
.buttonStyle(PressStyle())
.accessibilityLabel(Text("Effort"))
.accessibilityValue(v.map { Text(verbatim: "\(Effort.name(kind)) \(Effort.chipLabel(kind, $0))") } ?? Text("None"))
.accessibilityHint(Text("Tap to change it."))
Expand Down Expand Up @@ -481,7 +481,7 @@ struct ArrowButton: View {
.glass(RoundedRectangle(cornerRadius: 10, style: .continuous), fill: dimmed ? Color.clear : Theme.surface, dimmed: dimmed)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.buttonStyle(PressStyle())
.disabled(!enabled)
.accessibilityLabel(left ? Text("Previous set") : Text("Next set"))
}
Expand Down Expand Up @@ -565,7 +565,7 @@ struct KeypadView: View {
Button { dismiss() } label: {
Image(systemName: "xmark").font(.system(size: 14, weight: .bold)).frame(width: 32, height: 32)
}
.buttonStyle(.plain)
.buttonStyle(PressStyle())
.glass(Circle(), fill: Theme.surface2, dimmed: dimmed)
.accessibilityLabel(Text("Cancel"))
display
Expand All @@ -584,8 +584,9 @@ struct KeypadView: View {
.frame(maxWidth: .infinity, minHeight: 34, maxHeight: 34)
.glass(Capsule(), tint: pad.fits(range) ? accent : nil, fill: dimmed || !pad.fits(range) ? Color.clear : accent, dimmed: dimmed || !pad.fits(range))
.overlay(Capsule().stroke(accent, lineWidth: pad.fits(range) && !dimmed ? 0 : 1.5))
.contentShape(Capsule()) // the whole capsule, not only its glyph, takes the tap
}
.buttonStyle(.plain)
.buttonStyle(PressStyle())
.disabled(!pad.fits(range))
.accessibilityLabel(Text("Save"))
}
Expand Down Expand Up @@ -628,10 +629,10 @@ struct KeypadView: View {
.font(.system(size: 22, weight: .semibold, design: .rounded))
.foregroundStyle(Color.white)
.frame(maxWidth: .infinity, minHeight: height, maxHeight: height)
.glass(RoundedRectangle(cornerRadius: 12, style: .continuous), fill: dimmed ? Color.clear : Theme.surface2, dimmed: dimmed)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.glass(RoundedRectangle(cornerRadius: 12, style: .continuous), fill: dimmed ? Color.clear : Theme.surface2, dimmed: dimmed)
.buttonStyle(PressStyle())
.opacity(off ? 0 : 1)
.disabled(off)
.accessibilityLabel(key == "⌫" ? Text(verbatim: "⌫") : Text(verbatim: key))
Expand Down
25 changes: 21 additions & 4 deletions frontend/ios/App/Watch/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ extension View {
/// Liquid Glass behind a control on watchOS 26 (tinted when given), `fill` before 26 and in Always On.
@ViewBuilder func glass<S: Shape>(_ shape: S, tint: Color? = nil, fill: Color, dimmed: Bool) -> some View {
if #available(watchOS 26, *), !dimmed {
glassEffect(tint.map { Glass.regular.tint($0).interactive() } ?? .regular.interactive(), in: shape)
// Not .interactive(): nearly every glass here is a button's, and an interactive glass takes
// the touch for its own bounce, so a tap now and then never reached the button (the keypad's
// ✓ on an Ultra, 2026-11-20). The press shows through the button styles instead (PressStyle,
// PrimaryButtonStyle, RowButtonStyle, OutlineCapsule).
glassEffect(tint.map { Glass.regular.tint($0) } ?? .regular, in: shape)
} else {
background(shape.fill(fill))
}
Expand Down Expand Up @@ -113,6 +117,19 @@ struct PrimaryButtonStyle: ButtonStyle {
}
}

/// A plain button that shows it was pressed: dimmed and a touch smaller while the finger is on it.
/// The glass's own bounce did that before it stopped taking the touch (glass above).
struct PressStyle: ButtonStyle {
@Environment(\.accessibilityReduceMotion) private var reduceMotion

func makeBody(configuration: Configuration) -> some View {
configuration.label
.opacity(configuration.isPressed ? 0.6 : 1)
.scaleEffect(configuration.isPressed && !reduceMotion ? 0.96 : 1)
.animation(.easeOut(duration: 0.1), value: configuration.isPressed)
}
}

/// A quieter choice: a grey row, like a row in the app's grouped lists.
struct RowButtonStyle: ButtonStyle {
var tint: Color = .white
Expand All @@ -129,7 +146,7 @@ struct RowButtonStyle: ButtonStyle {
fill: dimmed ? Color.clear : (configuration.isPressed ? Theme.surface2 : Theme.surface), dimmed: dimmed)
.overlay(RoundedRectangle(cornerRadius: Theme.radius, style: .continuous).stroke(Theme.surface2, lineWidth: dimmed ? 1 : 0))
.contentShape(RoundedRectangle(cornerRadius: Theme.radius, style: .continuous))
.opacity(enabled ? 1 : 0.35)
.opacity(enabled ? (configuration.isPressed ? 0.6 : 1) : 0.35) // the glass ignores `fill`: the press shows here
}
}

Expand Down Expand Up @@ -173,7 +190,7 @@ struct RoundButton: View {
.glass(Circle(), tint: accent, fill: dimmed ? Color.clear : accent, dimmed: dimmed)
.overlay(Circle().stroke(accent, lineWidth: dimmed ? 2 : 0))
}
.buttonStyle(.plain)
.buttonStyle(PressStyle())
.accessibilityLabel(label)
if caption { label.font(.caption2.weight(.bold)).foregroundStyle(dimmed ? Color.secondary : accent).lineLimit(1) }
}
Expand All @@ -198,7 +215,7 @@ struct EdgeButton: View {
.overlay(Circle().stroke(Theme.dim, lineWidth: dimmed ? 1 : 0))
.contentShape(Circle())
}
.buttonStyle(.plain)
.buttonStyle(PressStyle())
.accessibilityLabel(label)
}
}
Expand Down
44 changes: 44 additions & 0 deletions frontend/src/lib/watch-buttons.native.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, expect, it } from 'vitest'
import { readdirSync, readFileSync } from 'node:fs'

// The Apple Watch's buttons on watchOS 26 (ios/App/Watch). An interactive glass behind a button
// takes the touch for its own bounce, so a tap now and then never reached the button: the keypad's
// ✓ on an Ultra ignored presses. The glass stays still and the button styles show the press.
const dir = new URL('../../ios/App/Watch/', import.meta.url)
const files = readdirSync(dir).filter(f => f.endsWith('.swift'))
// The code alone, without its // comments (which explain why there is no .interactive()).
const code = f => readFileSync(new URL(f, dir), 'utf8').split('\n').map(l => l.replace(/\/\/.*$/, '')).join('\n')
// From `start` to the end of that declaration: the next line that closes at the left margin.
const block = (src, start) => { const from = src.indexOf(start); return from < 0 ? '' : src.slice(from, src.indexOf('\n}', from) + 2) }

describe('watch buttons take every tap and show it', () => {
it('has no interactive glass anywhere in the watch app', () => {
for (const f of files) {
const src = code(f)
expect(src, f).not.toMatch(/\.interactive\(/)
expect(src, f).not.toMatch(/\.buttonStyle\(\s*\.glass/)
}
expect(code('Theme.swift')).toMatch(/glassEffect\(/)
})

it('leaves no button with a glass on the bare .plain style, which shows no press', () => {
for (const f of files) {
// Each Button( … ) up to its .buttonStyle: a glass inside it must not be on .plain.
for (const m of code(f).matchAll(/Button[\s\S]*?\.buttonStyle\(([^)]*\)?)\)/g)) {
if (/\.glass\(/.test(m[0]) && !/Button[\s\S]*Button/.test(m[0])) expect(m[1], f).not.toBe('.plain')
}
}
})

it('shows the press in every style, the keypad\'s ✓ taking its whole capsule', () => {
const theme = code('Theme.swift')
expect(block(theme, 'struct PressStyle: ButtonStyle')).toMatch(/configuration\.isPressed/)
expect(block(theme, 'struct RowButtonStyle: ButtonStyle')).toMatch(/opacity\([^\n]*configuration\.isPressed/)
expect(block(code('RestHold.swift'), 'struct OutlineCapsule: ButtonStyle')).toMatch(/opacity\([^\n]*configuration\.isPressed/)
const keypad = block(code('SetPage.swift'), 'struct KeypadView')
const save = keypad.slice(keypad.indexOf('Image(systemName: "checkmark")'), keypad.indexOf('.accessibilityLabel(Text("Save"))'))
expect(save).toMatch(/\.contentShape\(Capsule\(\)\)/)
expect(save).toMatch(/\.buttonStyle\(PressStyle\(\)\)/)
expect(keypad.slice(keypad.indexOf('private func keyButton'))).toMatch(/\.glass\([\s\S]*?\}\s*\.buttonStyle\(PressStyle\(\)\)/)
})
})
Loading