Skip to content

feat: implement design-system.md's four micro-animations, gated on reduce-motion - #783

Merged
wei18 merged 4 commits into
mainfrom
feat/design-system-micro-animations
Jul 12, 2026
Merged

wei18 merged 4 commits into
mainfrom
feat/design-system-micro-animations

Conversation

@wei18

@wei18 wei18 commented Jul 11, 2026

Copy link
Copy Markdown
Owner

What

Implements the four micro-animations design-system.md §Motion specifies, none of which existed in the UI layer before this branch (repo-wide, exactly one file — SettingsUI/ReminderPrimerSheet — gated any animation behind accessibilityReduceMotion; everywhere else had no animation, hence no gate, either).

  1. Cell tap → selection (100 ms ease-out) — Sudoku BoardCellView's background fill, scoped to isSelected alone.
  2. Cell digit place (80 ms scale 0.9→1.0 ease-out) — Sudoku BoardCellView's digit Text; MS's equivalent content-appearing moment (reveal glyph / flag icon) in MinesweeperCellButton.
  3. Error highlight pulse (200 ms × 2, ease-in-out / reduced motion: static fill only) — Sudoku BoardCellView, two explicit withAnimation(...completion:) legs rather than Animation.repeatCount(_:autoreverses:) (see commit message for why).
  4. CompletionView hero stat reveal (350 ms fade + 8 pt rise, stagger 60 ms / reduced motion: instant fade) — implemented once in the shared GameShellUI.CompletionScreen, so it covers both apps' completion/win/loss screens.

Every animation routes through a new MotionGate helper (GameShellKit/Sources/GameShellUI/Motion/MotionGate.swift) reading @Environment(\.accessibilityReduceMotion), so reduced motion turns each one OFF (not shorter), per the spec.

MS scope note: MS has no per-cell equivalent of "cell tap → selection" (no persistent selected-cell state — each tap immediately reveals/flags) or "error highlight pulse" (no per-cell wrong state; a hit mine is a terminal/board-level event, not a transient per-cell error). Both are intentionally left unmapped for MS rather than inventing new behavior; see the MS commit message.

No animation is added to completion beyond the spec — no celebration/confetti effects, matching the design-system's explicit restriction.

Why a 4th, unplanned fix is in here

Implementing the completion hero reveal via the standard .onAppear + state-flip idiom broke the snapshot-test baselines in a way that turned out not to be "needs re-recording" but a real correctness bug: .onAppear never fires on an NSHostingView that isn't attached to a real window, which is exactly how both the snapshot-test harness and the ASC screenshot emitter (emitASCScreenshot, real App Store screenshot generation) render every fixture — a single synchronous frame, zero elapsed wall-clock time. Confirmed empirically (re-recorded, got a permanently blank hero card; adding a 600ms wait before capture didn't help, because the callback that would flip the reveal state never runs there at all, not because it hadn't finished yet).

Fixed with completionHeroSkipsReveal, an @Environment escape hatch mirroring an existing pattern in this codebase (BannerSlotView.bannerSlotLoadingPreview, #732 — same class of problem: a genuinely timing-dependent view needing a deterministic override for offline rendering). Defaults false (live app unaffected); the snapshot tests and ASC emitters for both apps inject true at their CompletionView/MinesweeperCompletionView call sites only.

An earlier attempt set this globally inside the shared hostingView(...) test helper instead of at each call site — reverted because it changed every hosted view's mangled type signature, breaking unrelated Home/DailyHub structural-baseline tests (assertViewStructure). Scoped to Completion call sites only in the final version.

Evidence / verification

  • swift build clean for GameShellKit, SudokuKit, MinesweeperKit.
  • swift test (all targets): GameShellKit 16/16, SudokuKit 287/287, MinesweeperKit 240/240 — all green.
  • All Completion-screen snapshot baselines were re-recorded (temporarily flipping SnapshotMode.recordMode to .all, scoped to the affected suites) and turned out byte-identical to the pre-existing committed PNGs — the reveal animation's settled end-state renders the same as the old unanimated static render — so no baseline files changed in this PR.
  • Manually rendered a scratch flag-mode-equivalent check is not applicable here (that was PR fix(minesweeper): tap-mode toggle readability + status.warning tint (#767) #780's verification); for this PR, visual correctness of the fix was confirmed by inspecting the re-recorded PNGs directly (both Sudoku's "Solved!" hero and MS's "You won" hero render fully, not blank).
  • mise run lint:swift: clean. mise run scan:l10n: passes (no new user-facing strings). mise run scan:hygiene / gitleaks: clean.
  • lefthook pre-commit (gitleaks + hygiene + swiftlint) passed on all 4 commits.

Not verified

  • No simulator/device visual QA of the live animations' actual motion feel (timing/easing curves) — headless macOS host only, no way to watch the animation play in real time in this environment. The values themselves are transcribed directly from design-system.md's table.
  • The completion hero reveal's live .onAppear behavior (confirmed not to fire in the offline harness, hence the escape hatch) was not independently re-verified as correctly firing in a real windowed app — this is standard, well-established SwiftUI behavior, not something this PR changes, but it's called out for completeness since the bug that motivated the escape hatch was only caught by empirical testing in the offline harness.
  • Xcode Cloud / CI-only l10n fixture-sync gate not separately re-run beyond the local scan above (no l10n changes in this PR regardless).

🤖 Generated with Claude Code

wei18 and others added 4 commits July 11, 2026 22:53
design-system.md's Motion table mandates every transform animation be OFF
(not shortened) under accessibilityReduceMotion, but that gate existed at
exactly one call site in the repo (SettingsUI/ReminderPrimerSheet) as an
inline ternary — every other animatable surface had no animation at all,
so no gate either. Centralizes the ternary in GameShellUI so the upcoming
board/completion animations (and future ones) can't reintroduce an
ungated animation by omission.

Co-Authored-By: Claude Fable 5 <[email protected]>
Implements the three per-cell rows from design-system.md's Motion table
that BoardCellView had zero coverage for (repo-wide, only one unrelated
file gated any animation before this branch):

- Cell tap → selection: 100 ms ease-out on the background fill, scoped to
  isSelected alone so the peer-highlight / same-digit / given background
  swaps (not covered by this row) stay instant.
- Cell digit place: 80 ms ease-out with a 0.9→1.0 scale transition.
  `.id(digit)` forces every new digit — including overwriting an existing
  one — to re-insert rather than update in place, since `.transition`
  only fires on insertion/removal.
- Error highlight pulse: two explicit 200 ms ease-in-out legs (dip to
  0.55 opacity, then recover) fired from `onChange(of: isError)`, rather
  than `Animation.repeatCount(_:autoreverses:)`, whose repeat/autoreverse
  combination leaves the final model value ambiguous.

All three route through MotionGate and read
`@Environment(\.accessibilityReduceMotion)`, so they turn off (not
shorten) under reduced motion, per the spec's Reduced-motion column.

Co-Authored-By: Claude Fable 5 <[email protected]>
MS's equivalent of design-system.md's "Cell digit place" row (80 ms
scale 0.9→1.0 ease-out) is a cell's content appearing on reveal (number
or mine glyph) or on flag placement — both surface through the same
`content` switch, so one MotionGate-routed `.animation(value: cell.state)`
plus a `.transition(.scale(scale: 0.9))` on each glyph covers both.

MS has no per-cell equivalent of Sudoku's "Cell tap → selection" (no
persistent selected-cell concept — each tap immediately reveals or
flags) or "Error highlight pulse" (no per-cell wrong-state; a hit mine
is a terminal/board-level event handled by the completion overlay, not
a transient per-cell error), so those two rows are intentionally not
mapped here.

Co-Authored-By: Claude Fable 5 <[email protected]>
… hatch

Implements design-system.md's "CompletionView hero stat reveal" (350 ms
fade + 8 pt rise, staggered 60 ms per element) in the shared
GameShellUI.CompletionScreen, so it covers both apps' completion/win/loss
screens from one place. Reduced motion drops straight to the revealed
state (instant fade, no rise), routed through MotionGate like the board
animations in the prior two commits.

CompletionScreen's `.onAppear`-driven reveal does not fire on an
NSHostingView that's never attached to a real window — confirmed
empirically by re-recording the hero snapshots and finding a permanently
blank card, unchanged by adding a several-hundred-ms wait beforehand.
That's exactly how the snapshot-test harness (`hostingView(...)`) AND the
ASC screenshot emitter (`emitASCScreenshot`, which routes through the same
helper) render every fixture: a single synchronous frame with zero
elapsed wall-clock time, so `.onAppear` never runs and the state that
would flip the hero visible never flips. Without a fix, App Store
screenshots of the completion screen would ship blank.

Adds `completionHeroSkipsReveal`, an `@Environment` escape hatch mirroring
the existing `bannerSlotLoadingPreview` pattern (#732: same class of
problem — a genuinely timing-dependent view needing a deterministic
override for offline rendering). `false` by default (the live app is
unaffected); the snapshot tests and ASC emitters for both apps now inject
`true` at their `CompletionView`/`MinesweeperCompletionView` call sites.
An earlier attempt to set this globally in the shared `hostingView(...)`
helper was reverted — it broke unrelated Home/DailyHub structural-baseline
tests by changing every hosted view's mangled type signature, so the
override is scoped to each Completion-rendering call site instead.

All affected Completion snapshot baselines were re-recorded and are
byte-identical to the pre-existing committed PNGs (the reveal animation's
settled end-state renders the same as the old static, unanimated render),
so no baseline files changed.

Co-Authored-By: Claude Fable 5 <[email protected]>
@wei18
wei18 merged commit daf5824 into main Jul 12, 2026
4 checks passed
@wei18
wei18 deleted the feat/design-system-micro-animations branch July 12, 2026 14:05
wei18 added a commit that referenced this pull request Jul 13, 2026
…ode-toggle contrast (#798)

Three non-blocking follow-ups from the #780/#783 reviews (issue #786):

1. Spacing literal (MinesweeperBoardView.modeToggle): `.padding(.horizontal, 12)`
   snapped to `theme.spacing.small` (8) — SpacingTokens names no 12 step, and
   `medium` (16) is reserved by the design-system pairing table for card-level
   internal padding. The chip's `.frame(minWidth: 44, minHeight: 44)` keeps the
   HIG tap-target floor independent of the padding value.

2. MotionGate consistency (SudokuKit BoardCellView error pulse): the
   hand-written `guard !reduceMotion` now routes through the shared
   `MotionGate.animation(_:reduceMotion:)` via `guard let`, matching the two
   `.animation` modifiers in the same file. `guard let` (not
   `withAnimation(nil)`) keeps behavior identical: reduce-motion on means no
   pulse at all — the opacity value never dips.

3. Mode-toggle contrast (MinesweeperBoardView.modeToggle reveal state):
   `.white` on `accent.primary` hard-failed AA in dark mode. WCAG ratios:
   - before: white / 0x3E6B8C light = 5.70:1 (pass); white / 0x7FAFCF dark
     = 2.35:1 (FAIL)
   - no text.* token passes dark either (text.primary 0xEEF1F4 / 0x7FAFCF
     = 2.07:1) — the accent ramp flips light<->dark opposite to the text ramp
   - after: `theme.surface.primary` (0xFFFFFF light / 0x1C2026 dark)
     = 5.70:1 light / 6.96:1 dark — both AA (>= 4.5:1). Light mode renders
     byte-identically (still white).

Re-recorded the 11 MS board baselines that contain the mode toggle (covered
light/dark/iPad, banner-reserved light/dark, flagged/midReveal/mineHit
light/dark); terminal-overlay baselines are pixel-identical (overlay covers
the toggle) and were left untouched. Pixel-diff confined to the toggle chip
bbox in every re-recorded PNG; eyeballed light (white on slate, narrower
chip) and dark (dark ink on light blue, readable).

Note for the record: the first re-record attempt captured Flag mode because
the swiftpm test host's UserDefaults domain (`swiftpm-testing-helper`)
carried a leaked `com.wei18.minesweeper.board.tapMode = flag` from an earlier
run (#720 G3 seeds the toggle from UserDefaults.standard at view init). The
key was cleared before the final recording; the snapshot render's dependence
on host defaults remains a latent recording hazard.

Part of #786.

Co-authored-by: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant