Skip to content

Commit 420f6ab

Browse files
committed
chore(core): UIPickerView's values, the wheel's pure math and its compositor player
UIPickerView's values measured on iOS 26.2 (UIKit lab, iPhone 17 Pro) join the UIKit constants table as uikit/picker.ts: the wheel's geometry (32 pt rows on a 97.2 pt cylinder seen at perspective 900, the 34 pt capsule band, the band row's 23.5/21 magnification, the dimmed rows' 0.447 opacity), the rubber band's dimension, the coast's stop speed, the 0.25 pt/ms velocity floor, the snap at rest, the 0.3 s tap spin and the 40 ms tick. The tap spin's duration is registered as a motion role a theme may retune (picker.tapSpin.durationMs); the motion docs' role table lists it. wheelPhysics.ts plans a release the way UIPickerView does: it projects the rest row at the normal deceleration rate as UIScrollView sums it (r ÷ (1 − r) ms of speed, motion/projection.ts), then coasts with the rate re-solved to stop exactly on that row at the stop speed, snaps when the wheel is slow, coasts into an end and bounces, or returns from past an end. It also has the rubber band, the tap spin and the row crossings that tick. wheelDrum.ts turns each row onto the cylinder and bakes a curve into per-row keyframes. Both are checked against UIKit's recorded frames and cell transforms. A release that bounces at an end runs on the bounce spring it is handed (a theme's scroll.bounce, resolved by the caller). wheelMotion.ts plays those curves: per-row Web Animations that run on the compositor, read back analytically, with a selection tick per row reached; disposed mid-motion, it leaves the rows where they are shown (wheelMotion.test.ts). For reduced motion it can land a wheel without travel: crossFade dips the rows' drawings out, lands them at the midpoint and fades them back in, opacity only (design:reduced-motion DR2).
1 parent 1203525 commit 420f6ab

14 files changed

Lines changed: 2179 additions & 4 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@astryxdesign/core': patch
3+
'@astryxdesign/cli': patch
4+
---
5+
6+
[chore] Internal: UIPickerView's values measured on iOS 26.2 join the UIKit constants table. They cover the wheel's geometry (row pitch, cylinder radius, perspective, the selection band, the band row's magnification), the coast's stop speed and velocity floor, the snap at rest, the tap spin and the selection tick. The tap spin's duration is a new motion role a theme may retune, `picker.tapSpin.durationMs`, listed in the motion roles table of `astryx docs motion`. The pure math a wheel moves and draws with comes with them. It projects the row a release rests on as UIScrollView sums its deceleration, coasts with the rate re-solved to stop on that row, snaps, bounces at an end on the bounce spring a theme resolved, rubber-bands, spins to a tapped row, and turns each row onto the cylinder. It is checked against UIKit's recorded frames. A player bakes a wheel's motion into per-row Web Animations that run on the compositor, and lands a wheel without travel for reduced motion (an opacity-only cross-fade). Not exported from the package entry point.
7+
8+
@vjeux

‎packages/cli/assets/docs/motion.doc.mjs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ const calmTheme = defineTheme({
190190
'duration',
191191
'350ms',
192192
],
193+
[
194+
'picker.tapSpin.durationMs',
195+
'--motion-picker-tap-spin-duration-ms',
196+
'duration',
197+
'300ms',
198+
],
193199
['scroll.bounce', '--motion-scroll-bounce', 'spring', '0.5s 0'],
194200
[
195201
'scroll.paging.snap',

‎packages/cli/test/__golden__/no-icon-set/docs-topics.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
"touch-motion",
202202
"best-practices"
203203
],
204-
"skeleton": "4e143d414ca7c67934fc05b9833def62b7c172992675f9a5decaa7f93c085834",
204+
"skeleton": "e74e7174af033f98e61d253badfe1e08039778baf83ba58ccd554c0ca6e6b09e",
205205
"mentions": []
206206
},
207207
"principles": {
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/**
4+
* @file wheelDrum.test.ts
5+
* @input wheelDrum.ts and wheelPhysics.ts, and a UIPickerView's cell
6+
* transforms read at rest
7+
* @output Proves the drum puts rows where UIKit's cylinder does, and that a
8+
* baked motion stays within tolerance, never sweeps a parked row across the
9+
* front, and leaves rows that never show without animations
10+
* @position Unit coverage for DateInput/wheelDrum.ts
11+
*/
12+
13+
import {describe, expect, it} from 'vitest';
14+
import {
15+
BAKE_TOLERANCE,
16+
PARKED_ANGLE,
17+
drumGeometry,
18+
isRowVisible,
19+
rowAngle,
20+
rowAtPoint,
21+
rowDistance,
22+
rowKeyframes,
23+
rowOrigin,
24+
rowTransform,
25+
sampleCurve,
26+
stripKeyframes,
27+
stripTranslation,
28+
} from './wheelDrum';
29+
import {planRelease, spinCurve, type WheelLayout} from './wheelPhysics';
30+
31+
const MINUTES: WheelLayout = {rowHeight: 32, rowCount: 60};
32+
const LOOPING: WheelLayout = {...MINUTES, looping: true};
33+
const GEOMETRY = drumGeometry(32);
34+
35+
/** Where CSS puts a row's centre: rotateX(−θ) about an origin R behind it. */
36+
function cylinderPosition(angle: number, radius: number) {
37+
return {y: radius * Math.sin(angle), z: radius * (Math.cos(angle) - 1)};
38+
}
39+
40+
describe('the drum at rest', () => {
41+
it('turns rows ±1 to ±4 as UIPickerView does', () => {
42+
// UIKit's cell transforms: rotations of 18.85, 37.8, 56.7 and 75.7°
43+
// (18.92° a row; its depths fit R = 97.2, which gives 18.86°).
44+
const measured = [18.85, 37.8, 56.7, 75.7];
45+
measured.forEach((degrees, i) => {
46+
const angle = rowAngle(
47+
rowDistance(31 + i + 1, 31 * 32, MINUTES),
48+
GEOMETRY,
49+
);
50+
expect(Math.abs((angle * 180) / Math.PI - degrees)).toBeLessThan(0.3);
51+
const above = rowAngle(
52+
rowDistance(31 - i - 1, 31 * 32, MINUTES),
53+
GEOMETRY,
54+
);
55+
expect(above).toBeCloseTo(-angle, 12);
56+
});
57+
});
58+
59+
it('moves rows onto the cylinder where UIKit’s cells sit', () => {
60+
// UIKit's cells, relative to the band: depth −5.2, −20.4, −43.9, −73.2
61+
// pt; along y 32k minus 0.41, 4.23, 14.5, 33.6 pt (at a rest offset a
62+
// fraction of a point off the row).
63+
const depth = [-5.2, -20.4, -43.9, -73.2];
64+
const pull = [0.41, 4.23, 14.5, 33.6];
65+
depth.forEach((z, i) => {
66+
const k = i + 1;
67+
const position = cylinderPosition(
68+
rowAngle(k * 32, GEOMETRY),
69+
GEOMETRY.radius,
70+
);
71+
expect(Math.abs(position.z - z)).toBeLessThan(0.5);
72+
expect(Math.abs(position.y - (32 * k - pull[i]))).toBeLessThan(0.4);
73+
});
74+
});
75+
76+
it('writes the turn as one rotation about an origin R behind the row', () => {
77+
expect(rowOrigin(GEOMETRY)).toBe('50% 50% -97.2px');
78+
expect(rowTransform(32 / 97.2)).toBe('rotateX(-0.32922rad)');
79+
});
80+
81+
it('parks rows past a quarter turn instead of turning them round', () => {
82+
const angle = rowAngle(400, GEOMETRY);
83+
expect(angle).toBe(PARKED_ANGLE);
84+
expect(isRowVisible(angle)).toBe(false);
85+
expect(isRowVisible(rowAngle(140, GEOMETRY))).toBe(true);
86+
});
87+
88+
it('scales the whole drum with the row height', () => {
89+
const geometry = drumGeometry(28);
90+
expect(geometry.radius).toBeCloseTo(85.05, 2);
91+
expect(geometry.height).toBe(189);
92+
expect(rowAngle(28, geometry)).toBeCloseTo(rowAngle(32, GEOMETRY), 12);
93+
});
94+
95+
it('shows each row of a looping wheel once, at the copy nearest the band', () => {
96+
// Minute 0 at an offset on minute 58 sits two rows below the band.
97+
expect(rowDistance(0, 58 * 32, LOOPING)).toBe(64);
98+
expect(rowDistance(58, 0, LOOPING)).toBe(-64);
99+
expect(rowDistance(30, 0, LOOPING)).toBe(-960);
100+
});
101+
});
102+
103+
describe('which row is under a point', () => {
104+
it('inverts the cylinder', () => {
105+
const y = GEOMETRY.radius * Math.sin(32 / GEOMETRY.radius);
106+
expect(rowAtPoint(y, 31 * 32, MINUTES, GEOMETRY)).toBe(32);
107+
expect(rowAtPoint(-y, 31 * 32, MINUTES, GEOMETRY)).toBe(30);
108+
expect(rowAtPoint(0, 31 * 32, MINUTES, GEOMETRY)).toBe(31);
109+
});
110+
111+
it('finds nothing past the drum or past the rows', () => {
112+
expect(
113+
rowAtPoint(GEOMETRY.radius + 1, 31 * 32, MINUTES, GEOMETRY),
114+
).toBeNull();
115+
expect(rowAtPoint(-40, 0, MINUTES, GEOMETRY)).toBeNull();
116+
expect(rowAtPoint(-40, 0, LOOPING, GEOMETRY)).toBe(59);
117+
});
118+
});
119+
120+
describe('a baked motion', () => {
121+
const coast = planRelease(1110, 1016.2, MINUTES).curve;
122+
123+
it('stays within the tolerance between samples', () => {
124+
const samples = sampleCurve(coast);
125+
expect(samples[0].t).toBe(0);
126+
expect(samples[samples.length - 1].t).toBe(coast.duration);
127+
expect(samples.length).toBeLessThan(400);
128+
for (let i = 1; i < samples.length; i++) {
129+
const a = samples[i - 1];
130+
const b = samples[i];
131+
for (const f of [0.1, 0.33, 0.5, 0.66, 0.9]) {
132+
const t = a.t + (b.t - a.t) * f;
133+
const linear = a.value + (b.value - a.value) * f;
134+
expect(Math.abs(coast.value(t) - linear)).toBeLessThanOrEqual(
135+
BAKE_TOLERANCE * 1.5,
136+
);
137+
}
138+
}
139+
});
140+
141+
it('animates only the rows that show during the motion', () => {
142+
const samples = sampleCurve(coast);
143+
// Rows 30 to 55 show at some point between row 34.7 and row 50.
144+
expect(
145+
rowKeyframes(10, samples, coast.duration, MINUTES, GEOMETRY),
146+
).toBeNull();
147+
expect(
148+
rowKeyframes(59, samples, coast.duration, MINUTES, GEOMETRY),
149+
).toBeNull();
150+
const row40 = rowKeyframes(40, samples, coast.duration, MINUTES, GEOMETRY);
151+
expect(row40).not.toBeNull();
152+
expect(row40![0].offset).toBe(0);
153+
expect(row40![row40!.length - 1].offset).toBe(1);
154+
// It ends parked above the band, where row 40 sits when row 50 is on it.
155+
expect(row40![row40!.length - 1].transform).toBe(
156+
rowTransform(-PARKED_ANGLE),
157+
);
158+
const row50 = rowKeyframes(50, samples, coast.duration, MINUTES, GEOMETRY);
159+
expect(row50![row50!.length - 1].transform).toBe(rowTransform(0));
160+
});
161+
162+
it('steps a looping row to its other copy while it is out of sight', () => {
163+
// From minute 58 across 0 to minute 3: minute 30 changes sides behind
164+
// the drum and must never be drawn on the front on the way.
165+
const spin = spinCurve(58 * 32, 63 * 32);
166+
const samples = sampleCurve(spin);
167+
const frames = rowKeyframes(28, samples, spin.duration, LOOPING, GEOMETRY);
168+
expect(frames).toBeNull();
169+
const minute1 = rowKeyframes(1, samples, spin.duration, LOOPING, GEOMETRY)!;
170+
for (const frame of minute1) {
171+
expect(frame.transform).not.toContain('NaN');
172+
}
173+
// Minute 33 is at the back the whole time: no keyframes. Minute 0 comes
174+
// into view from below and passes the band.
175+
const minute0 = rowKeyframes(0, samples, spin.duration, LOOPING, GEOMETRY)!;
176+
expect(minute0[0].transform).toBe(rowTransform(rowAngle(64, GEOMETRY)));
177+
expect(minute0[minute0.length - 1].transform).toBe(
178+
rowTransform(rowAngle(-96, GEOMETRY)),
179+
);
180+
});
181+
182+
it('jumps a parked looping row with two keyframes at the same progress', () => {
183+
// A long looping spin: row 0 goes once round the back.
184+
const spin = spinCurve(0, 40 * 32);
185+
const samples = sampleCurve(spin);
186+
const frames = rowKeyframes(0, samples, spin.duration, LOOPING, GEOMETRY)!;
187+
const steps = frames.filter(
188+
(frame, i) => i > 0 && frame.offset === frames[i - 1].offset,
189+
);
190+
expect(steps.length).toBe(1);
191+
for (let i = 1; i < frames.length; i++) {
192+
expect(frames[i].offset).toBeGreaterThanOrEqual(frames[i - 1].offset);
193+
}
194+
});
195+
196+
it('translates the band strip with the offset, folding a looping strip', () => {
197+
expect(stripTranslation(992, MINUTES)).toBe(-992);
198+
expect(stripTranslation(992, LOOPING)).toBe(-(992 + 1920));
199+
expect(stripTranslation(-32, LOOPING)).toBe(-(1888 + 1920));
200+
const spin = spinCurve(58 * 32, 63 * 32);
201+
const frames = stripKeyframes(sampleCurve(spin), spin.duration, LOOPING);
202+
const steps = frames.filter(
203+
(frame, i) => i > 0 && frame.offset === frames[i - 1].offset,
204+
);
205+
expect(steps.length).toBe(1);
206+
});
207+
});

0 commit comments

Comments
 (0)