Skip to content

Commit 0081c11

Browse files
vjeuxcixzhang
andauthored
feat(lab): under a finger, NavigationStack's bar takes the iOS 26 look (#8396)
* feat(core): useFingerScroll tells its caller when a finger's scroll ends `useFingerScroll(scroller, {onEnd})` calls `onEnd` once each time a finger's scroll on the scroller ends — its scrollend after the lift, the lift after a scrollend under a resting finger, the quiet fallback, or the pointer turning fine — after the reader already says false. Unmounting never calls it. The internal touch entry re-exports the hook for Lab's ChatVirtualizer, which will drop its own touch listeners for it. * fix(lab): NavigationStack re-measures a screen when its title resizes The large title sat outside the scroll area's content root, so a change of its height alone, such as a longer title, re-measured nothing. A screen that then overflowed stayed clipped: it did not scroll, offered no keyboard stop and contained no overscroll until another change re-measured it. The title is now first in the content root, whose size the scroll area watches. The headers of navigationTransition.ts and the browser spec keep their fields only. The transition's layer notes move to the JSDoc of the type and function they describe. * fix(core): useFingerScroll keeps the latest onEnd through the isomorphic layout effect Core hooks write commit-time refs with useIsomorphicLayoutEffect, which stays quiet under server rendering. * docs(core): the finger-scroll re-export names no reader that main does not have The changeset, the internal touch entry, the gestures README and the tests say Lab components that watch a finger's scroll, instead of naming ChatVirtualizer, which is still in an open pull request. Text only. * Merge #10172 into #10191 as this change's base Both are open: #10191 moves NavigationStack's large title into the scroll area's content, and #10172 lets useFingerScroll tell its caller when a finger's scroll ends. They share no file. * feat(lab): under a finger, NavigationStack's bar takes the iOS 26 look Under a finger, NavigationStack's bars paint no background and no hairline, as iOS 26's do. Each screen carries a scroll edge effect: a veil of the body colour that fades in once its content has moved 10px under the bar, on UIKit's measured springs. A push, a pop and a back swipe carry each screen's veil with its card, and the bar a card covers is cut at that card's leading edge. A mouse keeps opaque bars. The veil and the UIKit bar constants live in Lab. The veil reads Core's finger-scroll hook, with its end call, and Core's internal touch entry also names the gesture host and the coarse-pointer check: export-only additions, with no change to Core's behavior. * Merge main into the NavigationStack clear bars branch (#10172 and #10191 landed) * test(lab): NavigationStack's cut specs read the push at held times Under load, WebKit can report one moving layer's animated translate a frame late. The old mid-flight read then put the cut 2 to 3 px off the card's edge while the layers moved as one. The two cut specs now freeze the scene while the push runs, move every animation of the push to the same scene times, and read the rendered boxes there. * Merge branch 'main' into uikit/c16-stack-bar Co-authored-by: Cindy Zhang <cindyxz@meta.com>
1 parent f88d572 commit 0081c11

13 files changed

Lines changed: 2415 additions & 68 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 also names, for Lab's NavigationStack, the gesture host and the coarse-pointer check. Its scroll edge effect reads the internal finger-scroll hook and its end call. Apps import nothing new.
6+
7+
@vjeux

‎apps/storybook/stories/NavigationStack.stories.tsx‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,81 @@ export const LargeTitle: Story = {
308308
name: 'Large title',
309309
render: () => <LargeTitleStack />,
310310
};
311+
312+
// =============================================================================
313+
// Scrolling — content passing under the bar
314+
// =============================================================================
315+
316+
const MESSAGES = Array.from({length: 40}, (_, index) => `Message ${index + 1}`);
317+
318+
function MessageRows() {
319+
const nav = useNavigationStack<string>();
320+
return (
321+
<List>
322+
{MESSAGES.map(message => (
323+
<ListItem
324+
key={message}
325+
label={message}
326+
description="Tap to open; scroll the list under the bar."
327+
endContent={
328+
<Icon
329+
icon="chevronRight"
330+
color="secondary"
331+
xstyle={rtlStyles.mirror}
332+
/>
333+
}
334+
onClick={() => nav.push(message)}
335+
/>
336+
))}
337+
</List>
338+
);
339+
}
340+
341+
function MessageBody({title}: {title: string}) {
342+
return (
343+
<List>
344+
{Array.from({length: 30}, (_, index) => (
345+
<ListItem
346+
key={index}
347+
label={`${title}, line ${index + 1}`}
348+
description="Long content scrolls under the bar."
349+
/>
350+
))}
351+
</List>
352+
);
353+
}
354+
355+
function ScrollingStack() {
356+
const [path, setPath] = useState<string[]>([]);
357+
return (
358+
<div style={{height: '100vh'}}>
359+
<NavigationStack
360+
label="Mail"
361+
root={
362+
<NavigationScreen title="Inbox">
363+
<MessageRows />
364+
</NavigationScreen>
365+
}
366+
path={path}
367+
onPathChange={setPath}
368+
getKey={entry => entry}
369+
renderScreen={entry => (
370+
<NavigationScreen title={entry}>
371+
<MessageBody title={entry} />
372+
</NavigationScreen>
373+
)}
374+
data-testid="navigation-stack"
375+
/>
376+
</div>
377+
);
378+
}
379+
380+
/**
381+
* Screens long enough to scroll under the bar. On a touch screen the bar
382+
* paints no background. Once a screen's content has moved 10px under it, a
383+
* veil of the body colour fades in, as iOS 26's scroll edge effect does.
384+
* Each screen keeps its own veil through a push, a pop or a back swipe.
385+
*/
386+
export const Scrolling: Story = {
387+
render: () => <ScrollingStack />,
388+
};

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,23 @@ describe('internal/touch', () => {
137137
expect(entry.navigation).toBeDefined();
138138
});
139139

140+
it("re-exports by name what NavigationStack's bars and scroll edge effect read", async () => {
141+
const entry: Record<string, unknown> = await import('./touch');
142+
const host = await import('../gestures/GestureHost');
143+
const pointer = await import('../utils/coarsePointer');
144+
const fingerScroll = await import('../gestures/useFingerScroll');
145+
expect(entry.getGestureHost).toBe(host.getGestureHost);
146+
expect(entry.isCoarsePointer).toBe(pointer.isCoarsePointer);
147+
expect(entry.useFingerScroll).toBe(fingerScroll.useFingerScroll);
148+
for (const name of [
149+
'getGestureHost',
150+
'isCoarsePointer',
151+
'useFingerScroll',
152+
]) {
153+
expect(typeof entry[name], name).toBe('function');
154+
}
155+
});
156+
140157
it('attaches no window or document listeners when it loads', async () => {
141158
vi.resetModules();
142159
const onWindow = vi.spyOn(window, 'addEventListener');

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,10 @@ export {useInteractionModalityTracking} from '../utils/interactionModality';
100100
// scroll is a finger's, and act when that scroll ends.
101101
export {useFingerScroll} from '../gestures/useFingerScroll';
102102
export type {UseFingerScrollOptions} from '../gestures/useFingerScroll';
103+
104+
// Lab's NavigationStack scroll edge effect reads the finger-scroll hook
105+
// above, and drops the veil's compositing layer when a finger's scroll ends.
106+
// It reads the gesture host for a finger's landing. The stack's bars read the
107+
// coarse-pointer check.
108+
export {getGestureHost} from '../gestures/GestureHost';
109+
export {isCoarsePointer} from '../utils/coarsePointer';

‎packages/lab/src/NavigationStack/NavigationStack.doc.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const docs = {
2525
name: 'NavigationStack',
2626
displayName: 'Navigation Stack',
2727
description:
28-
"The navigator. You own the path: pass the entries pushed on the root screen and update them in onPathChange. The stack renders the root screen and one screen per entry, the top one last, keeps covered screens and their scroll positions alive, and makes them inert. The bar shows the top screen's title, its end content and a round Back button with a chevron, named by the screen it returns to. A push moves focus to the new screen's title; a pop returns it to the control that pushed the screen.",
28+
"The navigator. You own the path: pass the entries pushed on the root screen and update them in onPathChange. The stack renders the root screen and one screen per entry, the top one last, keeps covered screens and their scroll positions alive, and makes them inert. The bar shows the top screen's title, its end content and a round Back button with a chevron, named by the screen it returns to. A push moves focus to the new screen's title; a pop returns it to the control that pushed the screen. Under a finger the bar paints no background and no hairline, as iOS 26's does. Once a screen's content has moved 10px under the bar, a veil of the body colour fades in at the top of that screen. Each screen keeps its own veil through a push, a pop or a back swipe. With a mouse the bar keeps its surface and hairline.",
2929
props: [
3030
{
3131
name: 'root',

‎packages/lab/src/NavigationStack/NavigationStack.test.tsx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,23 @@ describe('NavigationStack', () => {
219219
);
220220
});
221221

222+
it('puts the scroll edge sentinel right after the large title', () => {
223+
render(<LargeHarness />);
224+
const scroller = screenCard('Settings')?.firstElementChild;
225+
const content = scroller?.firstElementChild;
226+
const [title, sentinel] = Array.from(content?.children ?? []);
227+
expect(title).toBe(
228+
screen.getByRole('heading', {level: 1, name: 'Settings'}),
229+
);
230+
// It ends where the large title ends, so the veil comes on as the
231+
// bar's title takes over. The scroller holds no other sentinel.
232+
expect(sentinel).toHaveAttribute('data-navigation-scroll-edge-sentinel');
233+
expect(sentinel).toHaveAttribute('aria-hidden', 'true');
234+
expect(
235+
scroller?.querySelectorAll('[data-navigation-scroll-edge-sentinel]'),
236+
).toHaveLength(1);
237+
});
238+
222239
it('moves focus to the pushed screen’s large title', async () => {
223240
render(<LargeHarness />);
224241
const general = screen.getByRole('button', {name: 'General'});
@@ -234,6 +251,24 @@ describe('NavigationStack', () => {
234251
});
235252
});
236253

254+
it('marks the top of an inline screen’s content with the scroll edge sentinel, under its veil', () => {
255+
render(<Harness />);
256+
const card = screenCard('Settings');
257+
const [sentinel, content] = Array.from(
258+
card?.firstElementChild?.children ?? [],
259+
);
260+
// The sentinel sits just above the content, at its static position in
261+
// the scroller. The screen's first element stays the content's first.
262+
expect(sentinel).toHaveAttribute('data-navigation-scroll-edge-sentinel');
263+
expect(
264+
content?.querySelector('[data-navigation-scroll-edge-sentinel]'),
265+
).toBeNull();
266+
// The veil is the card's own child, over the scroller, hidden from
267+
// assistive technology.
268+
const veil = card?.querySelector(':scope > [data-navigation-scroll-edge]');
269+
expect(veil).toHaveAttribute('aria-hidden', 'true');
270+
});
271+
237272
it('shows a screen’s end content in its bar, out of reach once a screen covers it', async () => {
238273
render(<Harness rootEndContent={<button type="button">Edit</button>} />);
239274
const edit = screen.getByRole('button', {name: 'Edit'});

0 commit comments

Comments
 (0)