Skip to content

Commit ca613db

Browse files
committed
feat(TreeList): rows expand and collapse the way an iOS outline list does
A UIKit outline list (iOS 26.2) slides a row's children out from under it as one block inside a clip that grows with them, moves the rows below with them, and turns the disclosure chevron 90°, all on one critically damped spring (response 0.25 s), with no fade; collapse runs it back, and Reduce Motion keeps it. On a touch screen a TreeList row now does the same on the compositor: the group clips its own box for the motion, its children translate from the group's height above it, every row after the group translates with them, and the chevron turns by an additive rotate over its final transform, all played by the motion foundation's animator and retargeted from the value on screen. A collapse keeps the children rendered, inert and skipped by the arrow keys, until they have slid away. TreeList renders a row's children lazily for that. With a mouse nothing moves.
1 parent e05c1f4 commit ca613db

9 files changed

Lines changed: 875 additions & 20 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+
[feat] On a touch screen, a `TreeList` row's children slide out from under it as it expands, with the rows below moving down alongside and the chevron turning, and slide back under it as it collapses, as in an iOS outline list. They used to appear and vanish in a single frame. The motion runs on the compositor and keeps going while the page runs script. Lists driven by a mouse are unchanged.
6+
7+
@vjeux

‎packages/core/src/List/__tests__/rowPixels.ts‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,35 @@ export async function sampleVideo(
182182
probe: {x: number; y: number},
183183
viewport: {width: number; height: number},
184184
): Promise<VideoSample[]> {
185+
const frames = await sampleVideoPoints(videoPath, [probe], viewport);
186+
return frames.map(({t, values, beacon}) => ({t, value: values[0], beacon}));
187+
}
188+
189+
export interface VideoPointsSample {
190+
/** Video time, s. */
191+
readonly t: number;
192+
/** Mean of the RGB channels at each probe, 0–255, in the probes' order. */
193+
readonly values: ReadonlyArray<number>;
194+
/** Whether each probe shows the harness marker colour (magenta). */
195+
readonly marker: ReadonlyArray<boolean>;
196+
readonly beacon: 'before' | 'blocked' | 'after';
197+
}
198+
199+
/**
200+
* Like `sampleVideo`, at several probe points per frame: a marker moving
201+
* through them reads as the index of the probe it covers.
202+
*/
203+
export async function sampleVideoPoints(
204+
videoPath: string,
205+
probes: ReadonlyArray<{x: number; y: number}>,
206+
viewport: {width: number; height: number},
207+
): Promise<VideoPointsSample[]> {
185208
const webm = (await readFile(videoPath)).toString('base64');
186209
const decoder = await chromium.launch();
187210
try {
188211
const player = await decoder.newPage();
189212
return await player.evaluate(
190-
async ({at, data, beaconAt}) => {
213+
async ({points, data, beaconAt}) => {
191214
const element = document.createElement('video');
192215
element.muted = true;
193216
element.src = URL.createObjectURL(
@@ -210,7 +233,8 @@ export async function sampleVideo(
210233
}) as CanvasRenderingContext2D;
211234
const out: {
212235
t: number;
213-
value: number;
236+
values: number[];
237+
marker: boolean[];
214238
beacon: 'before' | 'blocked' | 'after';
215239
}[] = [];
216240
const duration = Number.isFinite(element.duration)
@@ -222,20 +246,27 @@ export async function sampleVideo(
222246
element.addEventListener('seeked', r, {once: true}),
223247
);
224248
context2d.drawImage(element, 0, 0);
225-
const px = context2d.getImageData(at.x, at.y, 1, 1).data;
249+
const pixels = points.map(
250+
p => context2d.getImageData(p.x, p.y, 1, 1).data,
251+
);
226252
const b = context2d.getImageData(beaconAt.x, beaconAt.y, 1, 1).data;
227253
const beacon =
228254
b[2] > 180 && b[0] < 80
229255
? 'blocked'
230256
: b[1] > 150 && b[2] < 80
231257
? 'after'
232258
: 'before';
233-
out.push({t, value: (px[0] + px[1] + px[2]) / 3, beacon});
259+
out.push({
260+
t,
261+
values: pixels.map(px => (px[0] + px[1] + px[2]) / 3),
262+
marker: pixels.map(px => px[0] > 200 && px[1] < 80 && px[2] > 200),
263+
beacon,
264+
});
234265
}
235266
return out;
236267
},
237268
{
238-
at: probe,
269+
points: probes,
239270
data: webm,
240271
beaconAt: {
241272
x: viewport.width - BEACON / 2,

‎packages/core/src/TreeList/TreeList.doc.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export const docs = {
137137
usage: {
138138
anatomy,
139139
description:
140-
'An expandable tree structure for displaying hierarchical data with branch connector lines. Use it for file explorers, nested category browsers, or any interface that visualizes parent-child relationships.',
140+
'An expandable tree structure for displaying hierarchical data with branch connector lines. Use it for file explorers, nested category browsers, or any interface that visualizes parent-child relationships. On a touch screen, a row\'s children slide out from under it as it expands, and back under it as it collapses, as in an iOS outline list.',
141141
bestPractices: [
142142
{guidance: true, description: 'Provide meaningful labels and icons for each node to make the hierarchy easy to scan.'},
143143
{guidance: true, description: 'Pre-expand important branches so users see key content immediately.'},

‎packages/core/src/TreeList/TreeList.tsx‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ export function TreeList({
264264
onToggleExpand: handleToggle,
265265
onActivate: activateItem,
266266
hasRovingTabIndex: true,
267+
// Rows still sliding away after a collapse sit in an inert group
268+
// (useTreeExpansionMotion): arrow keys skip them, as if already gone.
269+
itemSelector: '[role="treeitem"]:not([inert] *)',
267270
// Rows are named by their label (AR1); typeahead matches that label, not
268271
// the chevron toggle, start content or description.
269272
matchLabelledBy: true,
@@ -316,14 +319,16 @@ export function TreeList({
316319
? [...ancestorsIsLast, isLast]
317320
: ancestorsIsLast;
318321

319-
const renderedChildren =
320-
isExpanded && hasChildren
321-
? renderItems(
322+
// Rendered by the row when it shows them: while expanded, and while
323+
// they slide away after a collapse (useTreeExpansionMotion).
324+
const renderChildren = hasChildren
325+
? (): ReactNode =>
326+
renderItems(
322327
item.children ?? [],
323328
nestedLevel + 1,
324329
ancestorsIsLastForChildren,
325330
)
326-
: undefined;
331+
: undefined;
327332

328333
return (
329334
<TreeListItem
@@ -350,7 +355,7 @@ export function TreeList({
350355
onToggle={handleToggle}
351356
density={density}
352357
variant={variant}
353-
renderedChildren={renderedChildren}
358+
renderChildren={renderChildren}
354359
posInSet={index + 1}
355360
setSize={items.length}
356361
isTabbable={item.id === initialTabbableId}

‎packages/core/src/TreeList/TreeListItem.tsx‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
3030
import {pressLayerStyles} from '../utils/pressLayer.stylex';
3131
import {cellPressableProps} from '../utils/selectionHold';
3232
import {usePressFeedback} from '../hooks/usePressFeedback';
33+
import {useTreeExpansionMotion} from './useTreeExpansionMotion';
3334
import {
3435
hasInteractiveAncestor,
3536
useClickableContainer,
@@ -259,7 +260,12 @@ const styles = stylex.create({
259260
width: spacingVars['--spacing-4'],
260261
height: spacingVars['--spacing-4'],
261262
fontSize: spacingVars['--spacing-4'],
262-
transitionProperty: 'transform',
263+
// Under a mouse the turn eases on the theme's tokens; on a touch screen
264+
// the expansion turns it on UIKit's spring (useTreeExpansionMotion).
265+
transitionProperty: {
266+
default: 'transform',
267+
'@media (pointer: coarse)': 'none',
268+
},
263269
transitionDuration: durationVars['--duration-fast'],
264270
transitionTimingFunction: easeVars['--ease-standard'],
265271
},
@@ -362,8 +368,11 @@ export interface TreeListItemInternalProps {
362368
* guide element).
363369
*/
364370
variant: TreeListVariant;
365-
/** Pre-rendered children subtree (rendered by the parent recursion) */
366-
renderedChildren?: ReactNode;
371+
/**
372+
* Renders the children subtree (the parent recursion), called while the
373+
* row shows its children: expanded, or sliding them away after a collapse.
374+
*/
375+
renderChildren?: () => ReactNode;
367376
/** 1-based position of this item among its siblings (aria-posinset). */
368377
posInSet: number;
369378
/** Number of siblings at this level (aria-setsize). */
@@ -403,12 +412,14 @@ export function TreeListItem({
403412
onToggle,
404413
density,
405414
variant,
406-
renderedChildren,
415+
renderChildren,
407416
posInSet,
408417
setSize,
409418
isTabbable,
410419
}: TreeListItemInternalProps) {
411420
const pressable = usePressFeedback();
421+
const {showsChildren, groupRef} = useTreeExpansionMotion(isExpanded);
422+
const renderedChildren = showsChildren ? renderChildren?.() : undefined;
412423
const t = useTranslator();
413424
const labelId = useId();
414425
const descriptionId = useId();
@@ -535,6 +546,8 @@ export function TreeListItem({
535546
// The button/container owns the chevron color (--color-icon-secondary);
536547
// inheriting keeps that as the single source.
537548
color="inherit"
549+
// The touch presentation turns the glyph with the expansion's spring.
550+
data-tree-chevron=""
538551
xstyle={[
539552
styles.chevronSvg,
540553
isExpanded ? styles.chevronExpanded : styles.chevronCollapsed,
@@ -709,8 +722,13 @@ export function TreeListItem({
709722
<div {...stylex.props(styles.indentedContent)}>{innerContent}</div>
710723
</div>
711724
</div>
712-
{isExpanded && renderedChildren != null && (
713-
<ul role="group" {...stylex.props(styles.childGroup)}>
725+
{renderedChildren != null && (
726+
<ul
727+
ref={groupRef}
728+
role="group"
729+
// Still sliding away after a collapse: out of reach until it leaves.
730+
inert={!isExpanded || undefined}
731+
{...stylex.props(styles.childGroup)}>
714732
{renderedChildren}
715733
</ul>
716734
)}

0 commit comments

Comments
 (0)