Skip to content

Commit a8195e0

Browse files
vjeuxcixzhang
andauthored
chore(core): Core's internal touch entry re-exports the action-group tracking hook, extended for Lab's TabBar, and a tab-bar string joins the catalog (#9699)
* chore(lab): Lab's animator hook, over Core's internal touch entry Internal entries land with their first user, per #8562. Lab components, TabBar first, animate with Core's motion engine and read the touch presentation and the writing direction as Core does. `@astryxdesign/core/internal/touch`, which already carries the pan recognizer, its hook, the engine and the rubber band for Lab's refresh control (#9807), gains by name: - `useTouchPresentation` and `TOUCH_QUERY`, the finger-or-mouse decision in render and outside it; - `isRtlElement`, the writing direction a pan mirrors by; - UIKit's `UIKIT_GESTURES` table. The engine's factory is renamed from `createMotionAnimator` to `createMotionEngine` at its source and in every internal caller, with its types `MotionEngine` and `MotionEngineOptions` (the engine's `Animator` and `AnimatorOptions`), so the engine and the public `createAnimator` differ by more than one word (architecture:react-component-runtime INV13). Named re-exports of code already on main, plus that rename: no behavior changes, no public 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 tests check it re-exports the same values Core imports by path and carries no public factory's name; the touch-support bundle test keeps every Lab-only name out of the root entry. One Lab module those components share comes with them: `internal/useMotionEngine`, a stable motion engine bound to an element through a callback ref. Lab's refresh control now uses it in place of its own identical `RefreshControl/useMotionAnimator.ts`. * chore(core): Core's internal touch entry re-exports the action-group tracking hook, extended for Lab's TabBar, and a tab-bar string joins the catalog Re-exports only on the entry: @astryxdesign/core/internal/touch adds useActionGroupTracking and its options type. So Lab's TabBar presses through the hook AlertDialog uses: a second finger ends the press with nothing acting, and focus follows the lift. The hook gains options for a group that draws its own highlight. All are optional, and without them the hook runs as before, so AlertDialog does not change. A no-paint option leaves the highlight to the group. Press callbacks report the action under the press as it begins and after each move, the lift before its action runs, and a cancel. Core's message catalog gains TabBar's badged-tab name. It lands ahead of the Lab component, so the Lab batch changes only Lab. The entry stays outside the public API: no docs, no root re-export, and the @astryx/no-core-internal-import rule keeps it to Core and Lab. * Merge branch 'main' into c09/core-touch-entry-lab-animator * Merge the updated lower stack branch into tabbar/core-touch-entry * Merge main (#9754 landed) into tabbar/core-touch-entry # Conflicts: # packages/core/src/internal/touch.test.ts # packages/core/src/internal/touch.ts * Merge main into tabbar/core-touch-entry # Conflicts: # packages/core/src/hooks/useActionGroupTracking.ts * Merge main into tabbar/core-touch-entry # Conflicts: # packages/core/src/internal/touch.test.ts # packages/core/src/internal/touch.ts * Merge main into the TabBar lab entry branch (#10188 landed) * Merge main into tabbar/core-touch-entry # Conflicts: # packages/core/src/internal/touch.ts * Merge main into tabbar/core-touch-entry # Conflicts: # packages/core/src/internal/touch.test.ts # packages/core/src/internal/touch.ts * Merge main into tabbar/core-touch-entry # Conflicts: # packages/core/src/internal/touch.ts * Merge branch 'main' into tabbar/core-touch-entry * Merge main into tabbar/core-touch-entry * Merge main into tabbar/core-touch-entry Co-authored-by: Cindy Zhang <cindyxz@meta.com>
1 parent 8484dc4 commit a8195e0

6 files changed

Lines changed: 147 additions & 3 deletions

File tree

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 action-group tracking hook, which gains a no-paint option and press callbacks for Lab's TabBar. A tab-bar string joins Core's message catalog. Apps import nothing new.
6+
7+
@vjeux

‎packages/core/locales/en.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,10 @@
943943
"defaultMessage": "Maximum value",
944944
"description": "Accessible name of the upper thumb of a range Slider (two thumbs), announced together with the Slider's own label, for example \"Price range, Maximum value, 80\". Never shown on screen."
945945
},
946+
"@astryx.tabBar.badgedItem": {
947+
"defaultMessage": "{label}, {badge}",
948+
"description": "Screen-reader name of a bottom tab bar item that shows a badge (\"Library, 3\"). {label} is the tab's visible name; {badge} is the badge's count or its own label (\"3 unread\"). Translators may reorder the two or change the separator."
949+
},
946950
"@astryx.tabList.label": {
947951
"defaultMessage": "Tabs",
948952
"description": "Screen-reader-only fallback name for a horizontal tab bar. Plural noun; \"Tabs\" here = UI tab panels, not browser tabs or the Tab key."

‎packages/core/src/hooks/useActionGroupTracking.test.tsx‎

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* action is skipped; a second finger or the window losing focus cancels;
1313
* inside a scroller a flick is left to the scroller; a mouse under a fine
1414
* pointer is tracked like a finger; the shared tracker does the tracking;
15-
* no render per move
15+
* a caller's no-paint option and press callbacks; no render per move
1616
* @position jsdom tests of packages/core/src/hooks/useActionGroupTracking.ts
1717
*/
1818

@@ -313,6 +313,96 @@ describe('useActionGroupTracking', () => {
313313
expect(onDelete).not.toHaveBeenCalled();
314314
});
315315

316+
describe('a group that draws its own highlight (Lab TabBar)', () => {
317+
const nameOf = (element: Element | null) => element?.textContent ?? 'none';
318+
319+
it('paints nothing with paintsHighlight off, and still runs the action it lifts on', () => {
320+
const {cancel, del, onCancel} = mount({
321+
options: {paintsHighlight: false},
322+
});
323+
const f = finger();
324+
f.down(cancel, centerOf(CANCEL));
325+
expect(paintOf(cancel)).toBeNull();
326+
f.move(cancel, centerOf(DELETE));
327+
expect(paintOf(del)).toBeNull();
328+
f.move(cancel, centerOf(CANCEL));
329+
f.up(cancel, centerOf(CANCEL));
330+
expect(paintOf(cancel)).toBeNull();
331+
expect(onCancel).toHaveBeenCalledTimes(1);
332+
});
333+
334+
it('reports the press around the tracker: the action at the begin and after each move, then the lift before its action runs', () => {
335+
const log: string[] = [];
336+
const {cancel} = mount({
337+
options: {
338+
onPressBegin: (_x, _y, action) => log.push(`begin ${nameOf(action)}`),
339+
onPressMove: (_x, _y, action) => log.push(`move ${nameOf(action)}`),
340+
onPressEnd: action => log.push(`end ${nameOf(action)}`),
341+
onPressCancel: () => log.push('cancel'),
342+
onActivate: action => log.push(`activate ${nameOf(action)}`),
343+
},
344+
});
345+
const f = finger();
346+
f.down(cancel, centerOf(CANCEL));
347+
f.move(cancel, {x: 104, y: 124});
348+
f.move(cancel, centerOf(DELETE));
349+
f.up(cancel, centerOf(DELETE));
350+
expect(log).toEqual([
351+
'begin Cancel',
352+
'move none',
353+
'move Delete',
354+
'end Delete',
355+
'activate Delete',
356+
]);
357+
});
358+
359+
it('reports a press that a second finger ends as a cancel, and runs nothing (family:action-groups FR3)', () => {
360+
const log: string[] = [];
361+
const {cancel, del} = mount({
362+
options: {
363+
onPressBegin: (_x, _y, action) => log.push(`begin ${nameOf(action)}`),
364+
onPressEnd: () => log.push('end'),
365+
onPressCancel: () => log.push('cancel'),
366+
onActivate: () => log.push('activate'),
367+
},
368+
});
369+
const first = {id: nextTouchId++, ...centerOf(CANCEL)};
370+
const second = {id: nextTouchId++, ...centerOf(DELETE)};
371+
time += 1000;
372+
touch('touchstart', cancel, first, time);
373+
time += 30;
374+
touch('touchstart', del, second, time, [first]);
375+
time += 16;
376+
touch('touchend', del, second, time, [first]);
377+
time += 16;
378+
touch('touchend', cancel, first, time);
379+
expect(log).toEqual(['begin Cancel', 'cancel']);
380+
});
381+
382+
it('reports a press that turning tracking off ends as a cancel, and runs nothing', () => {
383+
const log: string[] = [];
384+
const options: Partial<ActionGroupTrackingOptions> = {
385+
paintsHighlight: false,
386+
onPressBegin: (_x, _y, action) => log.push(`begin ${nameOf(action)}`),
387+
onPressEnd: () => log.push('end'),
388+
onPressCancel: () => log.push('cancel'),
389+
onActivate: () => log.push('activate'),
390+
};
391+
const view = mount({options});
392+
const f = finger();
393+
f.down(view.cancel, centerOf(CANCEL));
394+
view.rerender(
395+
<Group
396+
onCancel={view.onCancel}
397+
onDelete={view.onDelete}
398+
options={{...options, isEnabled: false}}
399+
/>,
400+
);
401+
f.up(view.cancel, centerOf(CANCEL));
402+
expect(log).toEqual(['begin Cancel', 'cancel']);
403+
});
404+
});
405+
316406
it('ends the gesture with nothing acting when the window loses focus (family:action-groups FR3)', () => {
317407
const {cancel, onCancel} = mount();
318408
const f = finger();

‎packages/core/src/hooks/useActionGroupTracking.ts‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
* @position Internal hook, not exported from the hooks entry. A long press
1313
* drives the shared action-group tracker (hooks/actionGroupTracker.ts) for
1414
* a group that a held pointer slides across. AlertDialog and
15-
* useGroupPressTracking consume it.
15+
* useGroupPressTracking consume it, and Lab components through the internal
16+
* touch entry.
1617
*
1718
* SYNC: When modified, update useActionGroupTracking.test.tsx
1819
*/
@@ -71,6 +72,22 @@ export interface ActionGroupTrackingOptions {
7172
manageStyle?: boolean;
7273
/** Runs the action under the finger at the lift. @default its own click */
7374
onActivate?: (item: HTMLElement) => void;
75+
/**
76+
* Paint the tracked action with the press attribute. Off, the group draws
77+
* its own highlight. @default true
78+
*/
79+
paintsHighlight?: boolean;
80+
/** A press began at viewport (x, y) on `action` (null: none). */
81+
onPressBegin?: (x: number, y: number, action: HTMLElement | null) => void;
82+
/** The press moved to viewport (x, y), now on `action` (null: none). */
83+
onPressMove?: (x: number, y: number, action: HTMLElement | null) => void;
84+
/** The lift, before its action runs, with the tracked action (null: none). */
85+
onPressEnd?: (action: HTMLElement | null) => void;
86+
/**
87+
* The press ended with nothing acting: a cancel, a second finger, or
88+
* tracking turned off.
89+
*/
90+
onPressCancel?: () => void;
7491
}
7592

7693
const PRESS = UIKIT_PRESS;
@@ -185,6 +202,7 @@ export function useActionGroupTracking(
185202
optionsRef.current.resolveTarget,
186203
neighboursRef.current,
187204
),
205+
paintsHighlight: optionsRef.current.paintsHighlight,
188206
onActivate: optionsRef.current.onActivate,
189207
// The browser's own click for a press the group ran is taken, so the
190208
// action runs once. The gesture host swallows it for a press it claims.
@@ -196,11 +214,16 @@ export function useActionGroupTracking(
196214
// Synchronizes the tracker with tracking on and mounted. Turning tracking
197215
// off, or unmounting, drops a tracked press and ends its release fades.
198216
// The host reports no cancellation to a disabled recognizer, and the lift
199-
// that runs an action often closes the owner before its fade ends.
217+
// that runs an action often closes the owner before its fade ends. The
218+
// group hears the dropped press as a cancel, so its own highlight goes out.
200219
useEffect(
201220
() => () => {
221+
const wasTracking = tracker.isTracking;
202222
tracker.cancel();
203223
tracker.dispose();
224+
if (wasTracking) {
225+
optionsRef.current.onPressCancel?.();
226+
}
204227
},
205228
[tracker, isEnabled],
206229
);
@@ -238,14 +261,17 @@ export function useActionGroupTracking(
238261
? measureNeighbours(ref.current, optionsRef.current)
239262
: NO_TARGETS;
240263
tracker.begin(x, y, {landed: landedRef.current});
264+
optionsRef.current.onPressBegin?.(x, y, tracker.highlighted);
241265
break;
242266
}
243267
case 'changed': {
244268
const {x, y} = recognizer.location();
245269
tracker.move(x, y);
270+
optionsRef.current.onPressMove?.(x, y, tracker.highlighted);
246271
break;
247272
}
248273
case 'ended': {
274+
optionsRef.current.onPressEnd?.(tracker.highlighted);
249275
const doc = ref.current?.ownerDocument;
250276
const focusedBefore = doc?.activeElement ?? null;
251277
const beganOn = tracker.beganOn;
@@ -278,6 +304,7 @@ export function useActionGroupTracking(
278304
case 'cancelled':
279305
neighboursRef.current = NO_TARGETS;
280306
tracker.cancel();
307+
optionsRef.current.onPressCancel?.();
281308
break;
282309
case 'possible':
283310
case 'failed':

‎packages/core/src/internal/touch.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ describe('internal/touch', () => {
176176
}
177177
});
178178

179+
it('re-exports the action-group tracking hook by name', async () => {
180+
const entry: Record<string, unknown> = await import('./touch');
181+
// Identity alone passes when both sides are undefined.
182+
expect(typeof entry.useActionGroupTracking).toBe('function');
183+
const modules: Record<string, Record<string, unknown>> = {
184+
useActionGroupTracking: await import('../hooks/useActionGroupTracking'),
185+
};
186+
for (const [name, module] of Object.entries(modules)) {
187+
expect(entry[name], name).toBe(module[name]);
188+
}
189+
});
190+
179191
it('attaches no window or document listeners when it loads', async () => {
180192
vi.resetModules();
181193
const onWindow = vi.spyOn(window, 'addEventListener');

‎packages/core/src/internal/touch.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,7 @@ export {animatorFor} from '../motion/animator';
113113
export {reducedMotionFade} from '../motion/reducedMotion';
114114
export {useTouchHitArea} from '../utils/touchHitArea';
115115
export {touchHitAreaStyles} from './touchHitArea.stylex';
116+
117+
// Lab's TabBar tracks its press with the shared action-group tracker.
118+
export {useActionGroupTracking} from '../hooks/useActionGroupTracking';
119+
export type {ActionGroupTrackingOptions} from '../hooks/useActionGroupTracking';

0 commit comments

Comments
 (0)