Skip to content

Commit cae55cf

Browse files
committed
chore(motion): ContextMenu's touch timeline and press curve, measured on iOS 26.2
The UIKit constants table gains the context menu's timeline: the press feedback starts at 150 ms, the press commits at 400 ms, and the menu displays at 735 ms (or at a lift after the commit). It also gains the per-axis drift tolerance, the press feedback's ramps, spring (0.6/0.4) and display latency. contextMenuPressCurve plays the closed-form curve a held press shows, and its tests check it against UIKit's per-frame presentation (0.03 pt rms on a 200 pt view). No component uses them yet.
1 parent 65fb64b commit cae55cf

9 files changed

Lines changed: 699 additions & 3 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] The UIKit constants table gains ContextMenu's touch timeline as measured on iOS 26.2: the press feedback starts at 150 ms, the press commits at 400 ms, and the menu displays at 735 ms. It also records the drift tolerance, and the press feedback's growth, spring and display latency. A closed-form press-feedback curve, checked against UIKit's per-frame presentation, comes with them. No component uses them yet. The feedback's spring and display latencies are motion roles a theme can retune, and `astryx docs motion` lists them. The onset, the commit and the menu's moment decide when a press counts and who gets the touch, so they stay out of the theme.
7+
8+
@vjeux

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,24 @@ const calmTheme = defineTheme({
184184
headers: ['Role', 'CSS variable', 'Kind', 'Default'],
185185
rows: [
186186
// motion-roles:start (generated by scripts/generate-motion-roles.mjs)
187+
[
188+
'contextMenu.press.feedbackLatencyMs',
189+
'--motion-context-menu-press-feedback-latency-ms',
190+
'duration',
191+
'38ms',
192+
],
193+
[
194+
'contextMenu.press.feedbackSpring',
195+
'--motion-context-menu-press-feedback-spring',
196+
'spring',
197+
'0.4s 0.4',
198+
],
199+
[
200+
'contextMenu.press.returnLatencyMs',
201+
'--motion-context-menu-press-return-latency-ms',
202+
'duration',
203+
'14ms',
204+
],
187205
[
188206
'navigation.transitionMs',
189207
'--motion-navigation-transition-ms',

‎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": "a86303e70a6cb63931e8e29c3b470b94f8edcc0b15576a907680a376213faddc",
204+
"skeleton": "59bab6689e5f3b7c6b0bea2c1b452fa9ff5fc487f250a4e88ee59e89af4f62cb",
205205
"mentions": []
206206
},
207207
"principles": {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/**
4+
* @file uikitPressFrames.ts
5+
* @input Nothing; measured data only
6+
* @output Exports the visible scale of UIKit's context-menu press platter,
7+
* frame by frame, for a long press and for a press lifted before the
8+
* commit, as the reference the press feedback is compared against
9+
* @position Test-only fixture of packages/core/src/ContextMenu (excluded from
10+
* the build with the rest of __tests__); read by the unit and interaction
11+
* tests of the press feedback
12+
*
13+
* UIKit lab (injected host app), iOS 26.2 simulator, iPhone 17 Pro, Oct 23
14+
* 2026: the presentation width of `_UIContentPlatterView` over a 200 × 120 pt
15+
* view, divided by 200, at each frame's display time in ms from the main
16+
* thread's receipt of the touch.
17+
*/
18+
19+
/** The measured view's width, to read scale errors in points. */
20+
export const UIKIT_PRESS_VIEW_WIDTH = 200;
21+
22+
/** A long press: the menu displayed at 734 ms. */
23+
export const UIKIT_LONG_PRESS: ReadonlyArray<readonly [number, number]> = [
24+
[199.6, 1],
25+
[215.9, 1.00014],
26+
[232.5, 1.00047],
27+
[249.2, 1.00109],
28+
[265.9, 1.00203],
29+
[282.5, 1.00331],
30+
[299.2, 1.00492],
31+
[315.9, 1.00682],
32+
[332.7, 1.00907],
33+
[349.2, 1.01159],
34+
[366.1, 1.01424],
35+
[382.5, 1.01699],
36+
[399.2, 1.01988],
37+
[415.8, 1.02286],
38+
[432.5, 1.02581],
39+
[449.2, 1.02877],
40+
[466.6, 1.03168],
41+
[483.1, 1.03444],
42+
[499.2, 1.03703],
43+
[515.8, 1.03944],
44+
[532.9, 1.04173],
45+
[554.4, 1.04388],
46+
[565.8, 1.04586],
47+
[583, 1.0477],
48+
[599.2, 1.04944],
49+
[615.8, 1.05111],
50+
[632.5, 1.0527],
51+
[649.2, 1.05425],
52+
[666.5, 1.05577],
53+
[682.5, 1.05727],
54+
[699.2, 1.05878],
55+
[716.1, 1.06029],
56+
[732.6, 1.06183],
57+
];
58+
59+
/** When the early press lifted, ms (main-thread receipt). */
60+
export const UIKIT_EARLY_LIFT_AT = 266.5;
61+
62+
/** A press lifted before the commit: no menu, the platter springs back. */
63+
export const UIKIT_EARLY_LIFT: ReadonlyArray<readonly [number, number]> = [
64+
[199.5, 1],
65+
[216.1, 1.00014],
66+
[232.7, 1.00046],
67+
[249.4, 1.00107],
68+
[267.3, 1.002],
69+
[282.8, 1.00327],
70+
[299.5, 1.00438],
71+
[316.1, 1.00493],
72+
[332.8, 1.00504],
73+
[349.5, 1.00483],
74+
[366.1, 1.0044],
75+
[382.8, 1.00382],
76+
[399.4, 1.00318],
77+
[416.1, 1.00252],
78+
[432.8, 1.00189],
79+
];
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/**
4+
* @file contextMenuPressCurve.test.ts
5+
* @input vitest, the context-menu constants, the press feedback curves, an
6+
* independent RK4 integration, and per-frame presentation sizes of UIKit's
7+
* press platter measured on iOS 26.2
8+
* @output The press feedback against UIKit: the size UIKit asks for, the
9+
* closed-form curve against a numerical integration of the same spring,
10+
* continuity where the ramp changes, and the visible size of a long press
11+
* and of a press lifted at 0.25 s against the measured frames
12+
* @position Unit tests of packages/core/src/ContextMenu/contextMenuPressCurve.ts
13+
*/
14+
15+
import {afterEach, describe, expect, it, vi} from 'vitest';
16+
import {solveSpring, toSpring} from '../motion/spring';
17+
import {contextMenu} from '../motion/uikit';
18+
import {
19+
PRESS_FEEDBACK_START_MS,
20+
pressFeedbackCurve,
21+
pressFeedbackMotion,
22+
pressFeedbackTarget,
23+
} from './contextMenuPressCurve';
24+
import {
25+
UIKIT_EARLY_LIFT,
26+
UIKIT_EARLY_LIFT_AT,
27+
UIKIT_LONG_PRESS,
28+
UIKIT_PRESS_VIEW_WIDTH,
29+
} from './__tests__/uikitPressFrames';
30+
31+
const press = contextMenu.press;
32+
33+
/** The visible scale of a held press `t` ms after the touch. */
34+
function held(t: number): number {
35+
const curve = pressFeedbackCurve();
36+
return t <= PRESS_FEEDBACK_START_MS
37+
? 1
38+
: curve.at((t - PRESS_FEEDBACK_START_MS) / 1000);
39+
}
40+
41+
/**
42+
* The visible scale of a press lifted at `lift` ms: the held curve until the
43+
* screen shows the lift, then the feedback spring back to 1 from where the
44+
* curve was (what the animator plays on `fail`).
45+
*/
46+
function liftedAt(lift: number): (t: number) => number {
47+
const curve = pressFeedbackCurve();
48+
const turn = lift + press.returnLatencyMs;
49+
const s = (turn - PRESS_FEEDBACK_START_MS) / 1000;
50+
const back = solveSpring(toSpring(press.feedbackSpring), {
51+
from: curve.at(s),
52+
to: 1,
53+
velocity: curve.velocity(s),
54+
});
55+
return t => (t < turn ? held(t) : back.value((t - turn) / 1000));
56+
}
57+
58+
function errors(
59+
measured: ReadonlyArray<readonly [number, number]>,
60+
model: (t: number) => number,
61+
): {rms: number; max: number} {
62+
const points = measured.map(
63+
([t, value]) => Math.abs(model(t) - value) * UIKIT_PRESS_VIEW_WIDTH,
64+
);
65+
return {
66+
rms: Math.sqrt(points.reduce((sum, e) => sum + e * e, 0) / points.length),
67+
max: Math.max(...points),
68+
};
69+
}
70+
71+
describe('pressFeedbackTarget', () => {
72+
it('is 1 until the onset, then ramps to 1.04 at the commit', () => {
73+
expect(pressFeedbackTarget(0)).toBe(1);
74+
expect(pressFeedbackTarget(press.feedbackOnsetMs)).toBe(1);
75+
expect(pressFeedbackTarget(press.commitMs)).toBeCloseTo(1.04, 10);
76+
});
77+
78+
it('continues on the slower ramp from the same size, and stops when the menu displays', () => {
79+
expect(pressFeedbackTarget(press.commitMs + 1e-9)).toBeCloseTo(1.04, 8);
80+
expect(pressFeedbackTarget(press.menuDisplayMs)).toBeCloseTo(
81+
1 + (press.feedbackRateAfterCommit * press.menuDisplayMs) / 1000,
82+
10,
83+
);
84+
expect(pressFeedbackTarget(5000)).toBe(
85+
pressFeedbackTarget(press.menuDisplayMs),
86+
);
87+
});
88+
});
89+
90+
describe('pressFeedbackCurve', () => {
91+
it('matches a numerical integration of the feedback spring chasing the ramp', () => {
92+
const {stiffness, damping, mass} = toSpring(press.feedbackSpring);
93+
const curve = pressFeedbackCurve();
94+
const target = (s: number) =>
95+
pressFeedbackTarget(press.feedbackOnsetMs + s * 1000);
96+
let x = 1;
97+
let v = 0;
98+
const h = 1e-4;
99+
let worst = 0;
100+
for (let step = 0; step * h < curve.duration - h; step++) {
101+
const s = step * h;
102+
if (step % 50 === 0) {
103+
worst = Math.max(worst, Math.abs(curve.at(s) - x));
104+
}
105+
const f = (px: number, pv: number, ps: number): [number, number] => [
106+
pv,
107+
(stiffness * (target(ps) - px) - damping * pv) / mass,
108+
];
109+
const [a1, b1] = f(x, v, s);
110+
const [a2, b2] = f(x + (h / 2) * a1, v + (h / 2) * b1, s + h / 2);
111+
const [a3, b3] = f(x + (h / 2) * a2, v + (h / 2) * b2, s + h / 2);
112+
const [a4, b4] = f(x + h * a3, v + h * b3, s + h);
113+
x += (h / 6) * (a1 + 2 * a2 + 2 * a3 + a4);
114+
v += (h / 6) * (b1 + 2 * b2 + 2 * b3 + b4);
115+
}
116+
expect(worst).toBeLessThan(1e-6);
117+
});
118+
119+
it('is continuous in value and velocity where the ramp changes', () => {
120+
const curve = pressFeedbackCurve();
121+
for (const ms of [press.commitMs, press.menuDisplayMs]) {
122+
const s = (ms - press.feedbackOnsetMs) / 1000;
123+
expect(curve.at(s + 1e-7)).toBeCloseTo(curve.at(s - 1e-7), 6);
124+
expect(curve.velocity(s + 1e-7)).toBeCloseTo(curve.velocity(s - 1e-7), 4);
125+
}
126+
});
127+
128+
it('starts from rest at 1 and rests on the last size', () => {
129+
const curve = pressFeedbackCurve();
130+
expect(curve.at(0)).toBe(1);
131+
expect(curve.velocity(0)).toBe(0);
132+
expect(curve.at(curve.duration)).toBeCloseTo(
133+
pressFeedbackTarget(press.menuDisplayMs),
134+
3,
135+
);
136+
expect(Math.abs(curve.velocity(curve.duration))).toBeLessThan(1e-3);
137+
});
138+
139+
it('continues from a press still moving', () => {
140+
const curve = pressFeedbackCurve({from: 1.02, velocity: -0.05});
141+
expect(curve.at(0)).toBeCloseTo(1.02, 10);
142+
expect(curve.velocity(0)).toBeCloseTo(-0.05, 10);
143+
});
144+
});
145+
146+
describe('the press feedback against UIKit (iOS 26.2, measured frames)', () => {
147+
it('a long press: the visible size follows UIKit’s within 0.05 pt rms on a 200 pt view', () => {
148+
const {rms, max} = errors(UIKIT_LONG_PRESS, held);
149+
expect(rms).toBeLessThan(0.05);
150+
expect(max).toBeLessThan(0.12);
151+
});
152+
153+
it('a press lifted at 0.25 s: it overshoots on the way back as UIKit’s does, within 0.05 pt rms', () => {
154+
const {rms, max} = errors(UIKIT_EARLY_LIFT, liftedAt(UIKIT_EARLY_LIFT_AT));
155+
expect(rms).toBeLessThan(0.05);
156+
expect(max).toBeLessThan(0.12);
157+
// The measured peak after the lift: 1.00504 at 332.8 ms.
158+
expect(liftedAt(UIKIT_EARLY_LIFT_AT)(332.8)).toBeCloseTo(1.00504, 4);
159+
});
160+
});
161+
162+
describe('pressFeedbackMotion: the feedback is a motion role a theme retunes', () => {
163+
afterEach(() => {
164+
vi.restoreAllMocks();
165+
document.body.innerHTML = '';
166+
});
167+
168+
function themed(values: Record<string, string>) {
169+
vi.spyOn(window, 'getComputedStyle').mockImplementation(
170+
(element: Element) =>
171+
({
172+
getPropertyValue: (name: string) =>
173+
element.hasAttribute('data-astryx-theme')
174+
? (values[name] ?? '')
175+
: '',
176+
}) as CSSStyleDeclaration,
177+
);
178+
const scope = document.createElement('div');
179+
scope.setAttribute('data-astryx-theme', 'test');
180+
const child = document.createElement('div');
181+
scope.append(child);
182+
document.body.append(scope);
183+
return child;
184+
}
185+
186+
it('reads the table’s spring, onset and latency where no theme sets them', () => {
187+
const element = themed({});
188+
expect(pressFeedbackMotion(element)).toEqual({
189+
spring: contextMenu.press.feedbackSpring,
190+
onsetMs: contextMenu.press.feedbackOnsetMs,
191+
latencyMs: contextMenu.press.feedbackLatencyMs,
192+
});
193+
});
194+
195+
it('takes a theme’s spring and latency; the onset, the commit and the menu’s moment are not roles', () => {
196+
const element = themed({
197+
'--motion-context-menu-press-feedback-spring': '0.5s 0',
198+
'--motion-context-menu-press-feedback-latency-ms': '80ms',
199+
'--motion-context-menu-press-feedback-onset-ms': '300ms',
200+
'--motion-context-menu-press-commit-ms': '100ms',
201+
});
202+
const motion = pressFeedbackMotion(element);
203+
expect(motion).toEqual({
204+
spring: {duration: 0.5, bounce: 0},
205+
onsetMs: contextMenu.press.feedbackOnsetMs,
206+
latencyMs: 80,
207+
});
208+
const curve = pressFeedbackCurve({motion});
209+
expect(curve.at(0)).toBe(1);
210+
expect(curve.at(0.3)).toBeGreaterThan(1);
211+
});
212+
213+
it('starts its ramp at the onset it is given and reaches the commit continuously', () => {
214+
// Nothing until the onset; the ramp then reaches UIKit's commit
215+
// continuously.
216+
expect(pressFeedbackTarget(250, 300)).toBe(1);
217+
expect(pressFeedbackTarget(400, 300)).toBeCloseTo(1.016, 6);
218+
expect(pressFeedbackTarget(400.001, 300)).toBeCloseTo(1.016, 4);
219+
});
220+
});

0 commit comments

Comments
 (0)