Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Lightbox): the drag to close plays at the theme's tempo (#10630)

Christopher Chedeaufb2437f61bb2
diff --git a/.changeset/lightbox-dismiss-tempo.md b/.changeset/lightbox-dismiss-tempo.md
new file mode 100644
index 0000000000..d1e6744652
--- /dev/null
+++ b/.changeset/lightbox-dismiss-tempo.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Lightbox's drag to close now plays at the theme's tempo, like the viewer's other motion. At the default tempo it plays exactly as before.
+
+@vjeux
diff --git a/docs/specs/AST-094-touch-presentations/motion-roles.md b/docs/specs/AST-094-touch-presentations/motion-roles.md
index fa5f0477ac..496b2603f1 100644
--- a/docs/specs/AST-094-touch-presentations/motion-roles.md
+++ b/docs/specs/AST-094-touch-presentations/motion-roles.md
@@ -4,41 +4,43 @@
The owner's goal: "The main goals are consistent timings and well-coordinated pieces." The rules serve it: springs for a component whose main interaction is a gesture, including the moves a tap starts inside it; curve tokens for a component whose main interaction is a tap, tap-to-expand included; the nearest-token mapping for a measured duration; one coordinated scale for springs and curves through `tempo`, each spring paired with a timing tier (`spec:AST-094` FR45); and no per-component exceptions and no platform-native option. The owner's guidance: "The guidance im thinking is: timing should be coordinated between spring and motion curve tokens, then use spring for gestures where velocity matters, use motion curves for taps presses and other non gesture motion." A component whose main interaction is a gesture plays springs for its motion, including moves a tap starts inside it (a tap on a sheet detent or a close button settles on the same spring), so its pieces stay coordinated. A component whose main interaction is a tap plays the theme's curve tokens (duration and easing, scaled by `tempo`), never a spring, since a tap carries no velocity; no character or option plays a platform-measured curve for it (owner decision, 2026-11-04). `spec:AST-094` FR45 lists which components each covers. Every motion role a registered table lists (`spec:AST-094` FR4, DEC-5): its kind, its default as the table measures it, and the record that names it. A role FR4 lists is named by FR4; any other role is one a component's own record measures, named by the current component records that carry its id. In a component whose main interaction is a tap, a role plays only for motion a gesture drives; in a gesture component, its roles also settle the moves a tap, a key or the program starts (`spec:AST-094` FR45). In a component whose main interaction is a tap, motion that a tap, a click, a hold, a key or the program starts plays the theme's duration and easing tokens, and an exit it starts plays the theme's exit duration and easing (`spec:AST-094` FR7), and a role measured for that motion stays as the native reference. Two approved motions keep their springs until their own records change: the animator's `animate` (`spec:AST-107` FR3) and `useDragToSnapPoints`'s `settleTo` (`spec:AST-107`). AST-105's glide, swap and edge reveal are tap-started layout motion and play the theme's curve tokens, except a gesture's release, which settles on its spring (`spec:AST-105` FR4). Reduce Motion substitutions and continuous busy loops (such as ProgressBar's indeterminate pulse, `component:ProgressBar` FR6) keep their named roles; they are neither gesture- nor interaction-started motion. Measured input timings, such as gesture thresholds, hold durations and flick speeds, are not motion roles.
-| Role | Kind | Default | Named by |
-| ------------------------------- | -------- | --------------------------------------------------------------- | ----------------------- |
-| `picker.tapSpin.durationMs` | duration | 300 ms | `component:DateInput` |
-| `progress.curves.fill` | curve | cubic-bezier(0, 0, 1, 1) | `component:ProgressBar` |
-| `progress.fillTrackMs` | duration | 1000 ms | `component:ProgressBar` |
-| `progress.reducedMotionPulseMs` | duration | 2000 ms | `component:ProgressBar` |
-| `segmented.selectionSpring` | spring | response 0.4 s, damping ratio 0.85 | `spec:AST-094` FR4 |
-| `springs.contextMenuDismiss` | spring | response 0.35 s, damping ratio 0.85 | `spec:AST-094` FR4 |
-| `springs.contextMenuLift` | spring | response 0.32 s, damping ratio 0.8 | `spec:AST-094` FR4 |
-| `springs.contextMenuMorph` | spring | response 0.3 s, damping ratio 0.8 | `spec:AST-094` FR4 |
-| `springs.directChange` | spring | response 0.5 s, damping ratio 0.825 | `spec:AST-094` FR4 |
-| `springs.emphasis` | spring | duration 0.5 s, bounce 0.3 | `spec:AST-094` FR4 |
-| `springs.fingerTracking` | spring | response 0.15 s, damping ratio 0.86 | `spec:AST-094` FR4 |
-| `springs.menuClose` | spring | response 0.35 s, damping ratio 0.85 | `spec:AST-094` FR4 |
-| `springs.menuOpen` | spring | response 0.32 s, damping ratio 0.8 | `spec:AST-094` FR4 |
-| `springs.quickChange` | spring | duration 0.5 s, bounce 0.15 | `spec:AST-094` FR4 |
-| `springs.settle` | spring | duration 0.5 s, bounce 0 | `spec:AST-094` FR4 |
-| `springs.sheetDismissSwipe` | spring | response 0.3441442326 s, damping ratio 0.8 | `component:BottomSheet` |
-| `springs.sliderDrop` | spring | response 0.5 s, damping ratio 0.7 | `component:Slider` |
-| `springs.sliderLift` | spring | response 0.215 s, damping ratio 0.6 | `component:Slider` |
-| `springs.sliderRelease` | spring | response 0.4 s, damping ratio 1 | `component:Slider` |
-| `springs.stateChange` | spring | response 0.55 s, damping ratio 1 | `spec:AST-094` FR4 |
-| `springs.subMenuBack` | spring | response 0.4 s, damping ratio 1 | `spec:AST-094` FR4 |
-| `springs.subMenuOpen` | spring | response 0.4 s, damping ratio 0.85 | `spec:AST-094` FR4 |
-| `springs.timedChange` | spring | duration 0.5 s, bounce 0 | `spec:AST-094` FR4 |
-| `springs.viewChange` | spring | mass 3, stiffness 1000, damping 500 | `spec:AST-094` FR4 |
-| `switchControl.lift` | spring | response 0.23 s, damping ratio 0.55 | `component:Switch` |
-| `switchControl.minimumLiftMs` | duration | 235 ms | `component:Switch` |
-| `switchControl.settle` | spring | response 0.5 s, damping ratio 0.7 | `component:Switch` |
-| `switchControl.tracking` | spring | response 0.36 s, damping ratio 1 | `component:Switch` |
-| `switchControl.travel` | spring | response 0.3 s, damping ratio 1 | `component:Switch` |
-| `switchControl.wellOff` | spring | mass 1, stiffness 246.74011002723395, damping 31.41592653589793 | `component:Switch` |
-| `switchControl.wellOn` | spring | mass 1, stiffness 85.37720070146501, damping 18.47995678582231 | `component:Switch` |
-| `timing.curves.entrance` | curve | cubic-bezier(0, 0, 0.58, 1) | `spec:AST-094` FR4 |
-| `timing.curves.exit` | curve | cubic-bezier(0.42, 0, 1, 1) | `spec:AST-094` FR4 |
-| `timing.curves.move` | curve | cubic-bezier(0.42, 0, 0.58, 1) | `spec:AST-094` FR4 |
-| `timing.curves.viewChange` | curve | cubic-bezier(0.25, 0.1, 0.25, 1) | `spec:AST-094` FR4 |
-| `timing.stateChangeMs` | duration | 250 ms | `spec:AST-094` FR4 |
+| Role | Kind | Default | Named by |
+| ----------------------------------------- | -------- | --------------------------------------------------------------- | ----------------------- |
+| `picker.tapSpin.durationMs` | duration | 300 ms | `component:DateInput` |
+| `progress.curves.fill` | curve | cubic-bezier(0, 0, 1, 1) | `component:ProgressBar` |
+| `progress.fillTrackMs` | duration | 1000 ms | `component:ProgressBar` |
+| `progress.reducedMotionPulseMs` | duration | 2000 ms | `component:ProgressBar` |
+| `segmented.selectionSpring` | spring | response 0.4 s, damping ratio 0.85 | `spec:AST-094` FR4 |
+| `springs.contextMenuDismiss` | spring | response 0.35 s, damping ratio 0.85 | `spec:AST-094` FR4 |
+| `springs.contextMenuLift` | spring | response 0.32 s, damping ratio 0.8 | `spec:AST-094` FR4 |
+| `springs.contextMenuMorph` | spring | response 0.3 s, damping ratio 0.8 | `spec:AST-094` FR4 |
+| `springs.directChange` | spring | response 0.5 s, damping ratio 0.825 | `spec:AST-094` FR4 |
+| `springs.emphasis` | spring | duration 0.5 s, bounce 0.3 | `spec:AST-094` FR4 |
+| `springs.fingerTracking` | spring | response 0.15 s, damping ratio 0.86 | `spec:AST-094` FR4 |
+| `springs.menuClose` | spring | response 0.35 s, damping ratio 0.85 | `spec:AST-094` FR4 |
+| `springs.menuOpen` | spring | response 0.32 s, damping ratio 0.8 | `spec:AST-094` FR4 |
+| `springs.quickChange` | spring | duration 0.5 s, bounce 0.15 | `spec:AST-094` FR4 |
+| `springs.settle` | spring | duration 0.5 s, bounce 0 | `spec:AST-094` FR4 |
+| `springs.sheetDismissSwipe` | spring | response 0.3441442326 s, damping ratio 0.8 | `component:BottomSheet` |
+| `springs.sliderDrop` | spring | response 0.5 s, damping ratio 0.7 | `component:Slider` |
+| `springs.sliderLift` | spring | response 0.215 s, damping ratio 0.6 | `component:Slider` |
+| `springs.sliderRelease` | spring | response 0.4 s, damping ratio 1 | `component:Slider` |
+| `springs.stateChange` | spring | response 0.55 s, damping ratio 1 | `spec:AST-094` FR4 |
+| `springs.subMenuBack` | spring | response 0.4 s, damping ratio 1 | `spec:AST-094` FR4 |
+| `springs.subMenuOpen` | spring | response 0.4 s, damping ratio 0.85 | `spec:AST-094` FR4 |
+| `springs.timedChange` | spring | duration 0.5 s, bounce 0 | `spec:AST-094` FR4 |
+| `springs.viewChange` | spring | mass 3, stiffness 1000, damping 500 | `spec:AST-094` FR4 |
+| `switchControl.lift` | spring | response 0.23 s, damping ratio 0.55 | `component:Switch` |
+| `switchControl.minimumLiftMs` | duration | 235 ms | `component:Switch` |
+| `switchControl.settle` | spring | response 0.5 s, damping ratio 0.7 | `component:Switch` |
+| `switchControl.tracking` | spring | response 0.36 s, damping ratio 1 | `component:Switch` |
+| `switchControl.travel` | spring | response 0.3 s, damping ratio 1 | `component:Switch` |
+| `switchControl.wellOff` | spring | mass 1, stiffness 246.74011002723395, damping 31.41592653589793 | `component:Switch` |
+| `switchControl.wellOn` | spring | mass 1, stiffness 85.37720070146501, damping 18.47995678582231 | `component:Switch` |
+| `timing.curves.entrance` | curve | cubic-bezier(0, 0, 0.58, 1) | `spec:AST-094` FR4 |
+| `timing.curves.exit` | curve | cubic-bezier(0.42, 0, 1, 1) | `spec:AST-094` FR4 |
+| `timing.curves.move` | curve | cubic-bezier(0.42, 0, 0.58, 1) | `spec:AST-094` FR4 |
+| `timing.curves.viewChange` | curve | cubic-bezier(0.25, 0.1, 0.25, 1) | `spec:AST-094` FR4 |
+| `timing.stateChangeMs` | duration | 250 ms | `spec:AST-094` FR4 |
+| `zoomMedia.dismiss.dismissPositionSpring` | spring | mass 1, stiffness 918.09, damping 60.6 | `component:Lightbox` |
+| `zoomMedia.dismiss.dismissSizeSpring` | spring | mass 1, stiffness 947.14, damping 61.55 | `component:Lightbox` |
diff --git a/docs/specs/components/Lightbox/Lightbox.spec.md b/docs/specs/components/Lightbox/Lightbox.spec.md
index 456e01def7..ed2ffc9d70 100644
--- a/docs/specs/components/Lightbox/Lightbox.spec.md
+++ b/docs/specs/components/Lightbox/Lightbox.spec.md
@@ -149,7 +149,7 @@ FR21). Consumer props and usage remain documented in `Lightbox.doc.mjs`.
| FR2 | Viewer overlay carries the current `lightbox` target. Media, Caption, and Counter carry no Lightbox public target. | Current source and public docs | settled |
| FR3 | Close, Previous, and Next button surfaces use Button's `button` target through IconButton rather than Lightbox-owned button targets. | Current source and target docs | settled |
| FR4 | The open viewer is a focus region through Core's shared focus-region module (`component:Dialog/DEC-2`): Tab from its last control moves focus to its first and Shift+Tab from its first moves focus to its last, so focus never leaves the viewer for the browser's own interface. | `component:Dialog/DEC-2` | settled; implementation gap |
-| FR5 | Under a coarse primary pointer, after hydration, Lightbox presents FR6–FR10 with no opt-in. Lightbox's main interaction is a gesture, so every move in them (the zoom settle, a double tap's zoom, the page settle, a cancelled drag's return and the pinch close) is a spring on a named motion role read through the motion role table, never a literal, and a release starts at the gesture's velocity; the controls fade is companion motion on the pace of the main spring (`spec:AST-094` FR45). A drag down that closes the viewer is a gesture-driven exit, so it plays the measured springs the Motion section lists (`spec:AST-094` FR4). Under reduced motion they follow AR6. | `spec:AST-094` FR4, FR13 | settled; implementation gap |
+| FR5 | Under a coarse primary pointer, after hydration, Lightbox presents FR6–FR10 with no opt-in. Lightbox's main interaction is a gesture, so every move in them (the zoom settle, a double tap's zoom, the page settle, the dismissal, a cancelled drag's return and the pinch close) is a spring on a named motion role read through the motion role table, never a literal, and a release starts at the gesture's velocity; the controls fade is companion motion on the pace of the main spring (`spec:AST-094` FR45). The dismissal plays Photos' measured springs, on the roles the Motion section lists (`spec:AST-094` FR4). Under reduced motion they follow AR6. | `spec:AST-094` FR4, FR13 | settled; implementation gap |
| FR6 | With `hasZoom`, on an image, a pinch zooms about the fingers and pans while it zooms; past the minimum or maximum the photo resists and eases back without overshoot. A double tap zooms to the larger of filling the viewer and 2×, about the tapped point; a second double tap returns to the fitted size. A zoomed photo pans with momentum and rubber-band edges. A pinch on the controls or the caption still zooms the page. | `spec:AST-094` FR3, FR10 | settled; implementation gap |
| FR7 | In a gallery, a horizontal drag moves the row of items, which sit apart by the measured gap. The release lands on at most one neighbouring item by `spec:AST-094` FR3's paging rule (DEC-25). Paging applies over a video item's frame as over a photo; a drag that starts on the video's own controls, such as its scrubber or volume, stays the video's. A zoomed photo pans to its edge before a new drag pages. A pinch never pages. Previous, Next, and the arrow keys keep paging. A controlled `index` the caller refuses springs back. `onIndexChange` reports a swipe. | `spec:AST-094` FR3, FR14, FR36–FR39, DEC-25 | settled; implementation gap |
| FR8 | On a fitted image, a downward drag moves the photo with the finger, shrinks it, and fades the backdrop. The release decides once: a projected travel past the commit point closes the viewer and reports `onOpenChange(false)` at the lift; a release moving back springs back. Video is unchanged. | `spec:AST-094` FR4, FR36–FR40, FR45 | settled; implementation gap |
@@ -166,10 +166,11 @@ FR21). Consumer props and usage remain documented in `Lightbox.doc.mjs`.
### Motion
-A drag down that closes the viewer is a gesture-driven exit, so it plays
-Photos' measured dismissal springs (FR5, `spec:AST-094` FR4). Every other
-spring a gesture drives, a cancelled drag's return included, plays
-`springs.settle`.
+A drag down that closes the viewer plays Photos' measured dismissal springs.
+Each is a motion role, so the exit plays at the theme's tempo, as every other
+move in the viewer does. At tempo 1 it plays the values below exactly (FR5,
+`spec:AST-094` FR4). Every other spring a gesture drives, a cancelled drag's
+return included, plays `springs.settle`.
| Spring | Value | Platform source |
| ----------------------------------------- | --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
@@ -356,7 +357,7 @@ a decision that they must remain unthemeable.
| FR4, AR3 | Browser keyboard test: Tab and Shift+Tab at both ends, Escape, arrows in LTR and RTL, `+`, `-`, `0`, close focus | Single image, gallery, zoomed image, removed opener | Focus leaving the viewer, a key without its action, or focus not returning to a connected opener fails. | `audit:Lightbox/accessibility` |
| AR3 | `Lightbox.test.tsx` "Lightbox unmounting while open" suite | Viewer rendered only while open and removed by the page, with the opener still on the page; a page control that removes it keeps its focus; StrictMode | Focus left on the page body after an open viewer unmounts fails. | `audit:Lightbox/accessibility` |
| FR5–FR10 | Interaction tests on synthetic touch streams with explicit timestamps; Reduce Motion; a busy main thread | Below and past each commit point; a release moving back; a drag on a video's frame and on its scrubber; a tap beside the photo with the controls hidden | A literal timing, a second decision during a settle, a gesture that pages while pinching, a drag on a video's frame that does not page, a drag on its controls that pages, or a tap beside the photo that closes while the controls are hidden fails. | `audit:Lightbox/touch` |
-| Motion | `zoomStage.test.ts` case listing the dismissal's springs in this record | The dismissal's position spring, and its size and opacity spring | A spring the dismissal plays that the Motion section does not list with its value fails. | `audit:Lightbox/touch` |
+| Motion | `zoomStage.test.ts` case listing the dismissal's springs in this record; `selfRegistration.test.ts` zoom case; interaction case at tempo 2 | The dismissal's position spring, and its size and opacity spring, at tempo 1 and tempo 2 | A spring the dismissal plays that the Motion section does not list with its value fails. An exit that takes as long at tempo 2 as at tempo 1 fails. | `audit:Lightbox/touch` |
| FR11 | Fine-pointer browser tests | Double-click, click on the photo, drag, ctrl-wheel, trackpad scroll, mouse wheel notch | A double-click that does not zoom 2× about the point, a click that hides the controls, a fine-pointer close that animates, or a mouse wheel's notch that pans a zoomed photo fails. | `audit:Lightbox/touch` |
| FR6, AR1 | Touch test double-tapping a photo shaped like the screen and a landscape photo | 9:16 photo on a phone viewport, 3:2 photo | A double tap that zooms less than 2×, or not about the tapped point, fails. | `audit:Lightbox/touch` |
| FR16 | Touch tests closing by Close, Escape, platform close, and a tap beside the photo with the controls shown; Reduce Motion | With and without `experimental`; controls shown and hidden | A touch close without the exit, a literal timing, input reaching the viewer during the exit, or a tap beside the photo that closes while the controls are hidden fails. | `audit:Lightbox/touch` |
diff --git a/packages/core/src/Lightbox/__tests__/LightboxDismiss.interaction.browser.spec.ts b/packages/core/src/Lightbox/__tests__/LightboxDismiss.interaction.browser.spec.ts
index dc00fbd4f9..6785c8e2c6 100644
--- a/packages/core/src/Lightbox/__tests__/LightboxDismiss.interaction.browser.spec.ts
+++ b/packages/core/src/Lightbox/__tests__/LightboxDismiss.interaction.browser.spec.ts
@@ -20,6 +20,7 @@ import {
type Page,
} from '@astryxdesign/a11y-spec/playwright';
import {
+ type ActiveAnimation,
blockMainThread,
type BusyRun,
type BusyWindow,
@@ -36,8 +37,8 @@ import {
startBusyControl,
startScreencast,
timeline,
- touchDriver,
type TouchDriver,
+ touchDriver,
type TouchScript,
touchStoryboard,
trackBrightness,
@@ -47,6 +48,7 @@ import {
withStorybook,
writeEvidence,
} from '@astryxdesign/interaction-harness';
+import {slowViewer} from './viewerTempo';
const storybook = withStorybook(test);
@@ -307,6 +309,46 @@ test("a release moving down sends the photo on the dismissal's spring and closes
await expect(v.dialog).toBeHidden();
});
+test("the dismissal plays at the viewer's tempo", async ({page}) => {
+ // The same exit at tempo 1, to compare the paced one with.
+ const atTempo1 = await dismissCurves(page, await openViewer(page));
+ const v = await openViewer(page);
+ await slowViewer(page, DISMISS_TEMPO);
+ const paced = await dismissCurves(page, v);
+ // Released at rest, so each spring takes exactly that many times as long.
+ for (const part of ['move', 'fade'] as const) {
+ const ratio = paced[part] / atTempo1[part];
+ expect(ratio, part).toBeGreaterThan(DISMISS_TEMPO - 0.1);
+ expect(ratio, part).toBeLessThan(DISMISS_TEMPO + 0.1);
+ }
+});
+
+/** The tempo the dismissal's tempo case plays the viewer at. */
+const DISMISS_TEMPO = 2;
+
+/**
+ * Dismisses the photo with a slow drag held still before the lift. Returns
+ * how long the exit's curves run: the photo's move, on the position spring,
+ * and a control's fade, on the size spring.
+ */
+async function dismissCurves(
+ page: Page,
+ v: Viewer,
+): Promise<{move: number; fade: number}> {
+ const since = await page.evaluate(() => performance.now());
+ await v.driver.play(pullDown(v.centre, 110));
+ const latest = (runs: ReadonlyArray<ActiveAnimation>) =>
+ runs.reduce((a, b) => (b.from > a.from ? b : a));
+ const move = latest(await waitForAnimation(v.photo, {since}));
+ const fade = latest(
+ await waitForAnimation(v.dialog.locator('[data-lightbox-chrome]').first(), {
+ since,
+ }),
+ );
+ await expect(v.dialog).toBeHidden();
+ return {move: move.to - move.from, fade: fade.to - fade.from};
+}
+
test('a pull flicked back up springs back on springs.settle', async ({
page,
}, testInfo) => {
diff --git a/packages/core/src/motion/uikit/index.ts b/packages/core/src/motion/uikit/index.ts
index b75b5db1ec..b2b4dd1797 100644
--- a/packages/core/src/motion/uikit/index.ts
+++ b/packages/core/src/motion/uikit/index.ts
@@ -88,4 +88,4 @@ export {
} from './springs';
export {switchControl} from './switch';
export {registerTimingTable, timing} from './timing';
-export {zoomMedia} from './zoomMedia';
+export {registerZoomMediaTable, zoomMedia} from './zoomMedia';
diff --git a/packages/core/src/motion/uikit/selfRegistration.test.ts b/packages/core/src/motion/uikit/selfRegistration.test.ts
index eeb001a04e..282d45978f 100644
--- a/packages/core/src/motion/uikit/selfRegistration.test.ts
+++ b/packages/core/src/motion/uikit/selfRegistration.test.ts
@@ -4,10 +4,11 @@
* @file selfRegistration.test.ts
* @input vitest (jsdom); each touch table imported in a fresh module graph,
* with no call to its register function
- * @output Checks that each spring role row, and the navigation, paging and
- * picker tables, register at import, so a role plays at the theme's tempo
- * @position Testing; validates uikit/springs.ts, navigation.ts, paging.ts and
- * picker.ts
+ * @output Checks that each spring role row, and the navigation, paging,
+ * picker and zoom tables, register at import, so a role plays at the
+ * theme's tempo
+ * @position Testing; validates uikit/springs.ts, navigation.ts, paging.ts,
+ * picker.ts and zoomMedia.ts
*/
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
@@ -69,6 +70,32 @@ describe('the touch tables register at import', () => {
);
});
+ it('a page that imports only the zoom table plays its dismissal at the tempo', async () => {
+ const {zoomMedia} = await import('./zoomMedia');
+ const {resolveMotion} = await import('../resolveMotion');
+ const {solveSpring, toSpring} = await import('../spring');
+ const target = element();
+ for (const spring of [
+ zoomMedia.dismiss.dismissPositionSpring,
+ zoomMedia.dismiss.dismissSizeSpring,
+ ]) {
+ tempo = '';
+ expect(resolveMotion(target, spring)).toBe(spring);
+ const base = solveSpring(toSpring(spring), {from: 0, to: 1});
+ for (const scale of [0.75, 1.5]) {
+ tempo = String(scale);
+ const played = solveSpring(toSpring(resolveMotion(target, spring)), {
+ from: 0,
+ to: 1,
+ });
+ expect(played.settleTime(0.001)).toBeCloseTo(
+ base.settleTime(0.001) * scale,
+ 6,
+ );
+ }
+ }
+ });
+
it('each role row and table registers itself, at import', async () => {
const registered: string[] = [];
vi.doMock('../roles', async importOriginal => {
@@ -87,10 +114,16 @@ describe('the touch tables register at import', () => {
await import('./navigation');
await import('./paging');
await import('./picker');
+ const {zoomMedia} = await import('./zoomMedia');
const {motionRoleOf} = await import('../roles');
expect(motionRoleOf(SETTLE_SPRING)?.id).toBe('springs.settle');
// The keyboard's spring is a measured constant, not a role.
expect(motionRoleOf(KEYBOARD_SPRING)).toBeUndefined();
- expect(registered).toEqual(['navigation', 'paging', 'picker']);
+ expect(motionRoleOf(zoomMedia.dismiss.dismissSizeSpring)?.id).toBe(
+ 'zoomMedia.dismiss.dismissSizeSpring',
+ );
+ // The zoom's give past its limits plays as measured.
+ expect(motionRoleOf(zoomMedia.overshoot)).toBeUndefined();
+ expect(registered).toEqual(['navigation', 'paging', 'picker', 'zoomMedia']);
});
});
diff --git a/packages/core/src/motion/uikit/zoomMedia.ts b/packages/core/src/motion/uikit/zoomMedia.ts
index 8bc5c93ca8..4b876c73b9 100644
--- a/packages/core/src/motion/uikit/zoomMedia.ts
+++ b/packages/core/src/motion/uikit/zoomMedia.ts
@@ -2,16 +2,19 @@
/**
* @file zoomMedia.ts
- * @input Nothing; data only
+ * @input The motion registry (motion/roles.ts)
* @output Exports `zoomMedia`: UIScrollView zooming in a photo viewer. It
* holds the give past the zoom limits, and Photos' double tap, maximum
- * zoom, page gap and drag to dismiss
+ * zoom, page gap and drag to dismiss. `registerZoomMediaTable` makes the
+ * dismissal's two springs motion roles
* @position A domain of the UIKit constants table (motion/uikit). Lightbox's
* zoom stage reads it
*
* SYNC: When modified, update /packages/core/src/motion/MEASUREMENTS.md
*/
+import {registerMotionTable} from '../roles';
+
/**
* UIScrollView zooming as a photo viewer uses it, with Photos' double tap
* and maximum zoom. Re-exported from motion/uikit, inside core.
@@ -151,3 +154,19 @@ export const zoomMedia = {
dismissSizeSpring: {mass: 1, stiffness: 947.14, damping: 61.55},
},
} as const;
+
+/**
+ * Registers this table with the motion registry (motion/roles.ts). The
+ * dismissal's two springs are roles, so the exit plays at the tempo of the
+ * viewer's theme, as every other viewer motion does. At tempo 1 they play
+ * exactly their measured values. The table's other values play as measured.
+ * The module registers its own table at import (one idempotent in-memory
+ * write, no DOM).
+ */
+export function registerZoomMediaTable(): void {
+ registerMotionTable('zoomMedia', zoomMedia, {
+ roles: ['dismiss.dismissPositionSpring', 'dismiss.dismissSizeSpring'],
+ });
+}
+
+registerZoomMediaTable();