Skip to content
Merged
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
7 changes: 7 additions & 0 deletions .changeset/uikit-constants-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[chore] Internal: the UIKit constants table for touch presentations (springs, scroll physics, timing curves and navigation values), each value with its source and a checked list of the simulator measurements still owed. Not exported from the package entry point; no component reads it yet.

@vjeux
267 changes: 267 additions & 0 deletions packages/core/src/motion/MEASUREMENTS.md

Large diffs are not rendered by default.

81 changes: 81 additions & 0 deletions packages/core/src/motion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Motion

Internal motion foundation for the touch presentations of core components. It
starts with the UIKit constants table: every spring, duration, deceleration
rate, rubber-band constant, curve and gesture threshold a touch presentation
uses, each with its source. Nothing here is exported from the package entry
point. Core's motion and gesture modules read it by path; components take
touch motion from the theme's motion roles (`spec:AST-094` FR4), not from
this table.

## Files

| File | What it is |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `uikit/` | THE constants table: every spring, duration, deceleration rate, rubber-band constant and curve, with its source. |
| `uikit/springs.ts` | Interaction springs (navigation, sheets, alerts, menus, controls, keyboard, banners) and the SwiftUI / UIKit presets. |
| `uikit/scroll.ts` | UIScrollView: deceleration rates, rubber band, bounce-back spring, paging, `delaysContentTouches`, scroll to top. |
| `uikit/timing.ts` | Non-spring clocks and curves: press highlight, Core Animation's named curves, keyboard, Reduced Motion cross-fade. |
| `uikit/navigation.ts` | UINavigationController: push velocity, parallax, dimming, transition clock, interactive pop finish rule. |
| `uikit/gestures.ts` | Gesture recognizer thresholds, the velocity filter and haptic stand-ins, as `{value, unit}` entries (sources in JSDoc). |
| `MEASUREMENTS.md` | The UIKit reference captures each unconfirmed value still needs. |

Component-specific values (a sheet's detents, a switch's geometry, a context
menu's timeline) live in a domain file per component, `uikit/<component>.ts`,
under the same rules.

## Sources

Every value in `uikit/` carries its source next to it, as a JSDoc tag on the
entry:

```
/**
* What the value is, in UIKit's words.
* @source apple-docs https://developer.apple.com/documentation/…
*/
key: value,
```

Allowed source kinds:

- `@source apple-docs <developer.apple.com URL>`
- `@source wwdc <year>-<session> "<title>": <what it says>`
- `@source webkit Source/<path> <what it says>` (Apple's engine, matched to
UIKit in its own comments; confirmed by a measurement)
- `@source measured: <app>, iOS <version>, <method>, <date>`
- `@source GUESS — <what it is based on>`

A `GUESS` or `webkit` value also names the measurement that will confirm or
replace it (`@measure M-…`, listed in MEASUREMENTS.md). An entry may carry
several sources when different parts come from different places.
The sources are documentation and stay out of the bundle: no value carries
them, `uikit/gestures.ts` included (its entries ship only `{value, unit}`).
`uikit/uikit.test.ts` enforces all of it on every domain file: an unsourced
value, an unknown kind, a guess without a task, a task missing from
MEASUREMENTS.md, or a source in a value fails the build.
Comment on lines +54 to +56

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reaches less than it says: leavesOf parses only export const X = { objects (uikit.test.ts:64-66), so an unsourced export const STRAY_THRESHOLD_MS = 12; added to timing.ts, or an unsourced export const strayScroll: Record<string, number> = {…} added to scroll.ts, leaves every motion test green. Nothing here uses either shape unsourced today. Failing any other top-level export const in a domain file unless it is listed as an alias of a sourced leaf (as DELAYS_CONTENT_TOUCHES_MS is of scroll.delaysContentTouchesMs), or narrowing this sentence to the objects the check reads, would make it hold. Optional.


Measurements come from the iOS simulator: built-in apps (Settings, Maps,
Photos, Files, Contacts, Calendar, Reminders, Safari's own chrome) or a UIKit
host app that reads the animations, recognizers and haptics UIKit attaches.
Each names its iOS version; iOS 26.2 is the reference.

### Adding a constant

1. Find the source: Apple's documentation, a WWDC session, or a measurement on
the iOS simulator.
2. Add the entry to the domain file it belongs to, in the vocabulary of its
source (a spring published as response and damping ratio stays
`{response, dampingRatio}`).
3. Tag it with its `@source`. No source yet: write the best-founded `GUESS`,
say what it is based on, add a measurement task to MEASUREMENTS.md and tag
the entry with it.
4. When a measurement lands, replace the value, tag it
`@source measured: …`, and drop the `@measure` tag.

## Measurements

[MEASUREMENTS.md](MEASUREMENTS.md) is the one list of UIKit reference captures:
what each value still needs from the iOS simulator, the app and gesture to
capture, the value to extract and the method. Every `@measure` ID in `uikit/`
resolves there.
79 changes: 79 additions & 0 deletions packages/core/src/motion/uikit/gestures.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

/**
* @file gestures.test.ts
* @input The gesture constants table
* @output Every constant ships only its value and unit (its sources are
* JSDoc, checked by uikit.test.ts); the documented UIKit defaults keep
* their documented values
* @position Unit test of packages/core/src/motion/uikit/gestures.ts
*/

import {describe, expect, it} from 'vitest';
import {PRESS_GESTURE_MEMORY_MS} from '../../utils/pressFeedback';
import {PRESS_SLOP_PX} from '../../utils/pressGesture';
import {
HAPTIC_FEEDBACK_KINDS,
HAPTIC_VIBRATION_PATTERNS,
UIKIT_GESTURES,
type GestureConstant,
} from './gestures';

function entries(): [string, GestureConstant<unknown>][] {
const result: [string, GestureConstant<unknown>][] = [];
for (const [group, values] of Object.entries(UIKIT_GESTURES)) {
for (const [name, constant] of Object.entries(values)) {
result.push([`${group}.${name}`, constant]);
}
}
for (const [kind, constant] of Object.entries(HAPTIC_VIBRATION_PATTERNS)) {
result.push([`haptics.${kind}`, constant]);
}
return result;
}

describe('UIKIT_GESTURES', () => {
it.each(entries())('%s ships only its value and unit', (_, constant) => {
// Its sources are JSDoc (uikit.test.ts): a source in the value would ship
// in every bundle that reads it.
expect(Object.keys(constant).sort()).toEqual(['unit', 'value']);
const values = Array.isArray(constant.value)
? constant.value
: [constant.value];
for (const value of values) {
expect(Number.isFinite(value)).toBe(true);
}
});

it('keeps the documented and measured UIKit values', () => {
expect(UIKIT_GESTURES.longPress.minimumPressDuration.value).toBe(500);
expect(UIKIT_GESTURES.longPress.allowableMovement.value).toBe(10);
expect(UIKIT_GESTURES.tap.allowableMovement.value).toBe(45);
expect(UIKIT_GESTURES.tap.maximumIntervalBetweenTaps.value).toBe(350);
expect(UIKIT_GESTURES.pan.hysteresis.value).toBe(10);
expect(UIKIT_GESTURES.pinch.hysteresis.value).toBe(8);
expect(UIKIT_GESTURES.control.trackingExpansion.value).toBe(70);
expect(UIKIT_GESTURES.velocity.currentWeight.value).toBe(0.2);
});

it('holds the press entries to the press model, one value per use', () => {
// The touch press model (utils/pressGesture.ts, utils/pressFeedback.ts)
// and the table name the same clocks: they cannot drift apart.
expect(UIKIT_GESTURES.press.slop.value).toBe(PRESS_SLOP_PX);
expect(UIKIT_GESTURES.press.momentumMemory.value).toBe(
PRESS_GESTURE_MEMORY_MS,
);
});

it('keeps the pan decision within the distance WebKit claims a scroll at', () => {
// Mobile Safari's last cancelable touchmove of a slow drag is at 10 px; a
// pan that must cancel the native scroll decides by then.
expect(UIKIT_GESTURES.pan.hysteresis.value).toBeLessThanOrEqual(10);
});

it('has a vibration pattern for every feedback kind', () => {
for (const kind of HAPTIC_FEEDBACK_KINDS) {
expect(HAPTIC_VIBRATION_PATTERNS[kind].value.length).toBeGreaterThan(0);
}
});
});
Loading
Loading