Repository navigation
chore(core): the UIKit constants table for touch presentations #8053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c784084
spec(AST-094): touch presentations feel native by default
cixzhang 0c35c43
chore(core): the UIKit constants table for touch presentations
vjeux 6bd2851
chore(core): the constants table names only what exists, and dates ev…
vjeux 4b3de64
Merge main into the constants table (lab typechecks with its tests)
vjeux e7df427
perf(core): the gesture table's sources move to JSDoc, out of the bundle
vjeux 439dcc3
docs(spec): the draft AST-094 copy leaves this stack
vjeux 0bf13da
Merge main (the deploy typecheck gate test reads the step as written)…
vjeux bbbcb60
refactor(core): the platform presets are named for their use
vjeux 03f66c3
fix(core): the UIKit table keeps only what a touch presentation plays…
cixzhang 1133bf9
Merge remote-tracking branch 'origin/main' into m8053
cixzhang eded944
style(core): MEASUREMENTS.md table widths after the dropped rows
cixzhang 7e36bcd
fix(core): the table's notes point at what exists, and the press entr…
cixzhang 1f751c9
docs(core): M-S2 feeds scroll.decelerationRate, where the coast readi…
cixzhang 0032cb6
Merge main (#8043, #7308 landed) into the UIKit constants table
cixzhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
|
|
||
| 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. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
leavesOfparses onlyexport const X = {objects (uikit.test.ts:64-66), so an unsourcedexport const STRAY_THRESHOLD_MS = 12;added totiming.ts, or an unsourcedexport const strayScroll: Record<string, number> = {…}added toscroll.ts, leaves every motion test green. Nothing here uses either shape unsourced today. Failing any other top-levelexport constin a domain file unless it is listed as an alias of a sourced leaf (asDELAYS_CONTENT_TOUCHES_MSis ofscroll.delaysContentTouchesMs), or narrowing this sentence to the objects the check reads, would make it hold. Optional.