Skip to content

feat(core): Switch follows a finger the way the iOS switch does - #8124

Closed
vjeux wants to merge 1955 commits into
meta:mainfrom
vjeux:uikit/c02-switch-touch
Closed

vjeux wants to merge 1955 commits into
meta:mainfrom
vjeux:uikit/c02-switch-touch

Conversation

@vjeux

@vjeux vjeux commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #8118 (which carries #8360) and #8123, merged in. Review only this PR's change: vjeux/astryx@c02-8124-base...uikit/c02-switch-touch

This push re-applies this PR's Switch rows on main's current Switch record (FR10, FR13–FR15), so it needs a fresh spec approval; it also merges #8118's fold onto #8360. This PR's code is unchanged apart from comments citing the new FR numbers.

Why

On a phone, Switch acts like a desktop checkbox: a finger can't drag its thumb (P3), and it freezes while the page runs scripts (P10).

What led to it

spec:AST-094 (current) asks every control to feel native under a finger: follow it, keep moving while scripts run, and never take the page's scroll. Switch had only the browser checkbox. #8123 measured iOS's own switch for this one to match; component:Switch FR10 and FR13–FR15 change here.

Options and tradeoffs

  1. CSS only: no script, but no drag, and transitions stall while the page is busy.
  2. A script drag that restyles the thumb each frame: it follows, but stutters under load and competes with scrolling.
  3. Passive tracking plus compositor animations (translate, scale, opacity only): follows the finger, keeps moving through a blocked main thread, and a vertical swipe still scrolls. It costs the shared touch layer (34.2 KB gzip), which every touch component reuses.

Two behaviours picked a side:

  • Slid off, then lifted: it toggles, as iOS does and spec:AST-020 FR9 allows (P19).
  • A hold, then a vertical drag: the page scrolls where iOS keeps the touch, because the switch only listens passively (spec:AST-094 FR11, FR20).

Why this choice

Only option 3 meets AST-094's motion and scroll rules; its cost is shared, and the mouse, keyboard and screen-reader paths are unchanged. No API change: the thumb keeps its circle and size, and under a coarse pointer its hit area grows toward 44 px, stopping halfway to a neighbour (P17).

How to check it

Open Storybook's Switch › Default on a phone or the iOS simulator:

  1. Tap: the thumb lifts, travels, and the switch turns on.
  2. Drag the thumb 30 pt right: it flips mid-drag and stays on (P3).
  3. Drag past the middle and back, then let go: nothing changes (P4).
  4. Slide off the switch and lift: it toggles (P19).
  5. In In scrolling list, swipe up from a switch: the page scrolls and nothing toggles (P7, P8).
  6. Reduce Motion: a tap cross-fades (P12). Right to left: dragging left flips (P13). Long-press the label: its text selects (P2). A mouse click toggles as before (P11).

Switch.interaction.browser.spec.ts runs these with real touch input in Chromium and WebKit. The one red check, "is absent from the root entry", is the old bundle test that #8671 replaces.

Evidence

iOS 26.2 simulator and Android 15 emulator: main, this PR, then iOS's own switch where shown; the red ring is the finger. P4 runs in Chromium; P11 uses a mouse. A3 and A8 show this PR only: main's takes drop frames.

P1
P2
P3
P4
P7
P8
P9
P10
P11
P12
P13
P14
P15
P16
P17
P18
P19
A1
A2
A3
A8
A9

Scope

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Writing rubric results

packages/core/src/Switch/Switch.spec.md:

  • R1 narration: none; FR10, FR13–FR15 and the re-applied sections are present tense on main's current record.
  • R2 research in the record: none.
  • R3 evidence naming a change: none; FR13 and FR14 cite the owner's dated direction, FR15 cites spec:AST-094 FR11 and spec:AST-020 FR9.
  • R4 rejected alternatives over one line or outside a decision: none.
  • R5 pull request or issue references: none.
  • R6 ruled open questions still listing options: none.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review needs:spec-owner-review Current knowledge records await owner approval

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants