Skip to content

Commit 62b989d

Browse files
committed
chore(core): Core's internal touch entry re-exports what Lab's TabBar reads, and its strings join the catalog
Re-exports only, no new behavior: @astryxdesign/core/internal/touch adds the pan recognizer, the press tracker, the action-group tracker, the finger-scroll reader, the text-selection lock, the touch query, the rubber band and UIKit's gesture values, none under a public factory's name. Core's message catalog gains TabBar's three strings: the More tab's label, the search's Cancel button and a badged tab's name. They land ahead of the Lab component, so the Lab batches change 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. One type widens: useFingerScroll also takes a ref that holds a document. It already watched a document passed to it directly, so nothing runs differently. A component can then fill the ref from its own element and watch the page of the document that element is in.
1 parent ee42864 commit 62b989d

6 files changed

Lines changed: 73 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+
[experimental] Core's internal `@astryxdesign/core/internal/touch` entry re-exports the pan recognizer, press tracker, action-group tracker, finger-scroll reader, selection lock, touch query, rubber band and UIKit gesture values for Lab components. The finger-scroll reader also takes a ref that holds a document. Three tab-bar strings join Core's message catalog.
6+
7+
@vjeux

‎packages/core/locales/en.json‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,22 @@
811811
"defaultMessage": "Maximum value",
812812
"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."
813813
},
814+
"@astryx.tabBar.badgedItem": {
815+
"defaultMessage": "{label}, {badge}",
816+
"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."
817+
},
814818
"@astryx.tabList.label": {
815819
"defaultMessage": "Tabs",
816820
"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."
817821
},
822+
"@astryx.tabBar.more": {
823+
"defaultMessage": "More",
824+
"description": "Label of the tab that collects a phone tab bar's sections past the fourth (iOS's More tab), and the name of the list of those sections it shows. One short word."
825+
},
826+
"@astryx.tabBar.cancelSearch": {
827+
"defaultMessage": "Cancel",
828+
"description": "Name of the button that ends search in a phone tab bar's search tab. The tab bar draws it over its search circle, beside the active field, as iOS draws its cancel button. It is the tab bar's own button, not the search field's own Cancel button. One short word."
829+
},
818830
"@astryx.table.label": {
819831
"defaultMessage": "Table",
820832
"description": "Fallback screen-reader-only accessible name for a data-table region when the consumer provides none. Noun (\"a table\"), not the verb \"to table\"."

‎packages/core/src/gestures/__tests__/useFingerScroll.test.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ function Page() {
7676
return <p data-testid="row">row</p>;
7777
}
7878

79+
const pageByRef: {current: Document | null} = {current: null};
80+
const fillPageByRef = (element: HTMLElement | null) => {
81+
pageByRef.current = element?.ownerDocument ?? null;
82+
};
83+
84+
function PageByRef() {
85+
read = useFingerScroll(pageByRef);
86+
return (
87+
<p data-testid="row" ref={fillPageByRef}>
88+
row
89+
</p>
90+
);
91+
}
92+
7993
// A phone: the finger-scroll watch listens only where the primary pointer is
8094
// coarse.
8195
let restorePointer: () => void;
@@ -135,6 +149,16 @@ describe('useFingerScroll', () => {
135149
expect(read()).toBe(false);
136150
});
137151

152+
it('reads the page’s own scroll through a ref that an element’s ref fills with its document', () => {
153+
const {getByTestId} = render(<PageByRef />);
154+
touch('touchstart', getByTestId('row'), true);
155+
document.dispatchEvent(new Event('scroll'));
156+
expect(read()).toBe(true);
157+
touch('touchend', getByTestId('row'), false);
158+
document.dispatchEvent(new Event('scrollend'));
159+
expect(read()).toBe(false);
160+
});
161+
138162
it("follows the ref's node, and stops watching on unmount", () => {
139163
const {getByTestId, rerender, unmount} = render(<List />);
140164
rerender(<List other />);

‎packages/core/src/gestures/useFingerScroll.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ function documentOf(node: Element | Document): Document {
4545

4646
/**
4747
* Watch a scroller's finger scrolls. Pass a ref to a scrolling element, or
48-
* the document for the page's own scroll. Returns a reader, stable across
49-
* renders: `true` while the scroller's scroll is a finger's.
48+
* the document (or a ref that holds it) for the page's own scroll. Returns a
49+
* reader, stable across renders: `true` while the scroller's scroll is a
50+
* finger's.
5051
* Internal: not exported from the package.
5152
*/
5253
export function useFingerScroll(
53-
scroller: RefObject<Element | null> | Document,
54+
scroller: RefObject<Element | Document | null> | Document,
5455
): () => boolean {
5556
/** The node the watch is on now, for the reader. */
5657
const watchedRef = useRef<Element | Document | null>(null);

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ describe('internal/touch', () => {
5656
expect(entry).not.toHaveProperty('touchModule');
5757
});
5858

59+
it('re-exports the pan recognizer, the press tracker, the action-group tracker, the finger-scroll reader, the selection lock, the touch query, the rubber band and UIKit gesture values by name', async () => {
60+
const entry: Record<string, unknown> = await import('./touch');
61+
const modules: Record<string, Record<string, unknown>> = {
62+
PanGestureRecognizer: await import('../gestures/PanGestureRecognizer'),
63+
useFingerScroll: await import('../gestures/useFingerScroll'),
64+
usePressTracker: await import('../gestures/usePressTracker'),
65+
createActionGroupTracker: await import('../hooks/actionGroupTracker'),
66+
lockSelection: await import('../utils/selectionLock'),
67+
TOUCH_QUERY: await import('../utils/touchQueries'),
68+
rubberBand: await import('../motion/rubberBand'),
69+
UIKIT_GESTURES: await import('../motion/uikit/gestures'),
70+
};
71+
for (const [name, module] of Object.entries(modules)) {
72+
expect(entry[name], name).toBe(module[name]);
73+
}
74+
});
75+
5976
it('attaches no window or document listeners when it loads', async () => {
6077
vi.resetModules();
6178
const onWindow = vi.spyOn(window, 'addEventListener');

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ export {
3838
unwrapAngle,
3939
} from '../gestures/geometry';
4040
export {LongPressGestureRecognizer} from '../gestures/LongPressGestureRecognizer';
41+
export {PanGestureRecognizer} from '../gestures/PanGestureRecognizer';
4142
export {TapGestureRecognizer} from '../gestures/TapGestureRecognizer';
4243
export {DEFAULT_ENVIRONMENT} from '../gestures/types';
44+
export {useFingerScroll} from '../gestures/useFingerScroll';
4345
export {useGestureRecognizer} from '../gestures/useGestureRecognizer';
46+
export {usePressTracker} from '../gestures/usePressTracker';
47+
export {createActionGroupTracker} from '../hooks/actionGroupTracker';
48+
export type {ActionGroupTarget} from '../hooks/actionGroupTracker';
4449
export {isRtlElement} from '../hooks/isRtlElement';
4550
// The animator's internal factory, under a name no public factory has: the
4651
// public animator factory is `createAnimator`.
@@ -53,6 +58,10 @@ export type {
5358
MotionHandle,
5459
} from '../motion/animator';
5560
export {cubicBezier} from '../motion/bezier';
61+
export {rubberBand} from '../motion/rubberBand';
62+
export {UIKIT_GESTURES} from '../motion/uikit/gestures';
5663
export {timing} from '../motion/uikit/timing';
5764
export {claimFocusMoves} from '../utils/claimFocusMoves';
65+
export {lockSelection} from '../utils/selectionLock';
5866
export {useTouchPresentation} from '../utils/touchPresentation';
67+
export {TOUCH_QUERY} from '../utils/touchQueries';

0 commit comments

Comments
 (0)