Skip to content

Commit 4e363d8

Browse files
committed
chore(lab): Lab's animator hook, over Core's internal touch entry
Internal entries land with their first user, per #8562. Lab's NavigationStack, PageControl and TabBar animate with Core's animator, solve UIKit's timing curves with Core's cubic-bézier solver, listen for taps and pans with Core's gesture hook and pan recognizer, stretch past their ends with Core's rubber band and read the writing direction as Core does, so `@astryxdesign/core/internal/touch` re-exports, by name: - the motion engine, `createMotionEngine`, for its jobs beyond the public `createAnimator` (architecture:react-component-runtime INV13), with its types `MotionEngine` and `MotionEngineOptions` (the engine's `Animator` and `AnimatorOptions`), `AnimateOptions`, `MotionCurve` and `MotionHandle`. The engine's factory is renamed from `createMotionAnimator` at its source and in every internal caller, so the engine and the public animator differ by more than one word; - `cubicBezier` and UIKit's `timing` table; - `useGestureRecognizer`, `useTouchPresentation` and `isRtlElement`; - `PanGestureRecognizer`, `rubberBand`, UIKit's `UIKIT_GESTURES` table and `TOUCH_QUERY`, which more than one of those components reads. Named re-exports of code already on main, plus that rename: no behavior changes, no docs, no root re-export, and the `@astryx/no-core-internal-import` lint rule already limits the entry to Core and Lab. The entry's test checks it re-exports the same values Core imports by path, and that it carries no public factory's name. One Lab module that those components share comes with them: `internal/useMotionEngine`, a stable motion engine bound to an element through a callback ref.
1 parent 58c5b8a commit 4e363d8

21 files changed

Lines changed: 286 additions & 54 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[chore] Internal: Core's internal touch entry re-exports the motion engine, curve and gesture helpers Lab's touch components use, and the engine's factory is renamed `createMotionEngine`. Apps import nothing new.
6+
7+
@vjeux

‎packages/core/src/SegmentedControl/useSegmentedSelectionMotion.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
1515
import {motionRoleOf} from '../motion/roles';
16-
import {createMotionAnimator, type Animator} from '../motion/animator';
16+
import {createMotionEngine, type Animator} from '../motion/animator';
1717
import {solveSpring, toSpring} from '../motion/spring';
1818
import {cubicBezier} from '../motion/bezier';
1919
import {segmentedControl, springs} from '../motion/uikit';
@@ -105,12 +105,12 @@ function setup(selected: string, {coarse = true}: {coarse?: boolean} = {}) {
105105
document.head.append(style);
106106
document.body.append(track);
107107
// A finger by default: Reduced Motion fades (design:reduced-motion DR2).
108-
const animator: Animator = createMotionAnimator(null, {
108+
const animator: Animator = createMotionEngine(null, {
109109
now: () => clock,
110110
pseudoElement: '::before',
111111
});
112112
// The ::after: the lifted lens's shadow, or the surface fading out.
113-
const afterAnimator: Animator = createMotionAnimator(null, {
113+
const afterAnimator: Animator = createMotionEngine(null, {
114114
now: () => clock,
115115
pseudoElement: '::after',
116116
initial: {opacity: 0},

‎packages/core/src/SegmentedControl/useSegmentedSelectionMotion.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
type RefObject,
2626
} from 'react';
2727
import {
28-
createMotionAnimator,
28+
createMotionEngine,
2929
type AnimateOptions,
3030
type Animator,
3131
type MotionCurve,
@@ -539,7 +539,7 @@ export class SegmentedSelectionMotion {
539539
private readonly after: Animator;
540540

541541
constructor(
542-
private readonly animator: Animator = createMotionAnimator(null, {
542+
private readonly animator: Animator = createMotionEngine(null, {
543543
pseudoElement: '::before',
544544
}),
545545
options: SegmentedSelectionMotionOptions = {},
@@ -552,7 +552,7 @@ export class SegmentedSelectionMotion {
552552
this.now = options.now ?? defaultNow;
553553
this.after =
554554
options.afterAnimator ??
555-
createMotionAnimator(null, {
555+
createMotionEngine(null, {
556556
pseudoElement: '::after',
557557
initial: {opacity: 0},
558558
});

‎packages/core/src/Slider/sliderTouchController.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {TapGestureRecognizer} from '../gestures/TapGestureRecognizer';
2929
import type {PointerKind} from '../gestures/types';
3030
import {isRtlElement} from '../hooks/isRtlElement';
3131
import {
32-
createMotionAnimator,
32+
createMotionEngine,
3333
type Animator,
3434
type MotionCurve,
3535
type MotionHandle,
@@ -1186,7 +1186,7 @@ export class SliderTouchController {
11861186
private animatorFor(element: HTMLElement): Animator {
11871187
let animator = this.animators.get(element);
11881188
if (animator == null) {
1189-
animator = createMotionAnimator(element);
1189+
animator = createMotionEngine(element);
11901190
this.animators.set(element, animator);
11911191
}
11921192
return animator;

‎packages/core/src/Switch/useSwitchTouch.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ vi.mock('../motion/animator', async importOriginal => {
3939
const actual = await importOriginal<typeof AnimatorModule>();
4040
return {
4141
...actual,
42-
createMotionAnimator: (
42+
createMotionEngine: (
4343
element: Element,
4444
options: {pseudoElement?: string} = {},
4545
) => {

‎packages/core/src/Switch/useSwitchTouch.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import type {GestureTouch} from '../gestures/types';
2323
import {isRtlElement} from '../hooks/isRtlElement';
2424
import {useIsomorphicLayoutEffect} from '../hooks/useIsomorphicLayoutEffect';
2525
import {
26-
createMotionAnimator,
26+
createMotionEngine,
2727
type Animator,
2828
type MotionCurve,
2929
} from '../motion/animator';
@@ -282,15 +282,15 @@ export class SwitchTouchController {
282282
return;
283283
}
284284
registerSwitchTable();
285-
this.thumb = createMotionAnimator(elements.thumb);
285+
this.thumb = createMotionEngine(elements.thumb);
286286
// The layer rests clear (its class's opacity 0) while the visuals show
287287
// the value; from here its opacity is the animator's.
288-
this.fade = createMotionAnimator(elements.track, {
288+
this.fade = createMotionEngine(elements.track, {
289289
pseudoElement: '::after',
290290
initial: {opacity: 0},
291291
});
292292
this.fade.set({opacity: 0});
293-
this.shadow = createMotionAnimator(elements.thumb, {
293+
this.shadow = createMotionEngine(elements.thumb, {
294294
pseudoElement: '::after',
295295
initial: {opacity: 0},
296296
});

‎packages/core/src/animator/createAnimator.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
import {
21-
createMotionAnimator,
21+
createMotionEngine,
2222
SETTLE_THRESHOLD,
2323
type Animator as MotionAnimator,
2424
type MotionCurve,
@@ -199,7 +199,7 @@ export function createAttachableAnimator(): {
199199
readonly animator: Animator;
200200
readonly attach: (element: HTMLElement | null) => void;
201201
} {
202-
const motion: MotionAnimator = createMotionAnimator(null);
202+
const motion: MotionAnimator = createMotionEngine(null);
203203
// Calls do nothing while no element is attached, before the ref attaches
204204
// or after it lets go. They also do nothing after destroy, and animate and
205205
// decay then resolve at once.

‎packages/core/src/animator/publicSurface.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const SRC = path.join(__dirname, '..');
2121

2222
/** Names of the motion module beneath the public animator. */
2323
const INTERNAL = [
24-
'createMotionAnimator',
24+
'createMotionEngine',
2525
'createAttachableAnimator',
2626
'animatorFor',
2727
'coast',
@@ -67,6 +67,6 @@ describe('the public animator surface', () => {
6767
'utf8',
6868
);
6969
expect(motion).not.toMatch(/export function createAnimator\b/);
70-
expect(motion).toMatch(/export function createMotionAnimator\b/);
70+
expect(motion).toMatch(/export function createMotionEngine\b/);
7171
});
7272
});

‎packages/core/src/gestures/__tests__/browser/presentedFixture.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @position Browser fixture of presentedHitTesting.interaction.browser.spec.ts; test-only
2323
*/
2424

25-
import {createMotionAnimator} from '../../../motion/animator';
25+
import {createMotionEngine} from '../../../motion/animator';
2626
import {presentedOffsetOf} from '../../../motion/presentation';
2727
import {GestureHost} from '../../GestureHost';
2828
import {PanGestureRecognizer} from '../../PanGestureRecognizer';
@@ -101,7 +101,7 @@ const TRAVEL = 444;
101101
*/
102102
const SPRING = {response: 6, dampingRatio: 1} as const;
103103

104-
const animator = createMotionAnimator(sheet);
104+
const animator = createMotionEngine(sheet);
105105
const drawn = (target: Element): DOMRect =>
106106
Element.prototype.getBoundingClientRect.call(target);
107107

‎packages/core/src/hooks/usePager.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
1717
import {GestureHost} from '../gestures/GestureHost';
1818
import {PanGestureRecognizer} from '../gestures/PanGestureRecognizer';
1919
import {ManualClock} from '../gestures/__tests__/harness';
20-
import {createMotionAnimator, type Animator} from '../motion/animator';
20+
import {createMotionEngine, type Animator} from '../motion/animator';
2121
import {solveAnimatedPageScroll, solvePaging} from '../motion/paging';
2222
import type * as motionResolution from '../motion/resolveMotion';
2323
import {resolveMotion} from '../motion/resolveMotion';
@@ -305,7 +305,7 @@ function setup(options: Partial<PagerOptions> = {}, rtl = false): Fixture {
305305
value: WIDTH,
306306
configurable: true,
307307
});
308-
const animator = createMotionAnimator(track, {
308+
const animator = createMotionEngine(track, {
309309
now: () => now,
310310
requestFrame: callback => {
311311
frameQueue.push(callback);
@@ -1259,7 +1259,7 @@ describe('createPager', () => {
12591259
// (DR3). The drag itself follows the pointer.
12601260
function reducedPager(f: Fixture, defaultIndex: number, coarse: boolean) {
12611261
stubMedia(true, coarse);
1262-
const reduced = createMotionAnimator(f.track, {
1262+
const reduced = createMotionEngine(f.track, {
12631263
now: () => now,
12641264
requestFrame: callback => {
12651265
frameQueue.push(callback);
@@ -1928,7 +1928,7 @@ function setupChildren(
19281928
value: WIDTH,
19291929
configurable: true,
19301930
});
1931-
const animator = createMotionAnimator(track, {
1931+
const animator = createMotionEngine(track, {
19321932
now: () => now,
19331933
requestFrame: callback => {
19341934
frameQueue.push(callback);
@@ -2461,7 +2461,7 @@ describe('pre-review fixes', () => {
24612461
configurable: true,
24622462
});
24632463
const host = {attach: () => () => {}} as unknown as GestureHost;
2464-
const animator = createMotionAnimator(track, {
2464+
const animator = createMotionEngine(track, {
24652465
now: () => now,
24662466
requestFrame: callback => {
24672467
frameQueue.push(callback);

0 commit comments

Comments
 (0)