Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/core-internal-entries-lab-scroll-edge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[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.

@vjeux
78 changes: 78 additions & 0 deletions apps/storybook/stories/NavigationStack.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,81 @@ export const LargeTitle: Story = {
name: 'Large title',
render: () => <LargeTitleStack />,
};

// =============================================================================
// Scrolling — content passing under the bar
// =============================================================================

const MESSAGES = Array.from({length: 40}, (_, index) => `Message ${index + 1}`);

function MessageRows() {
const nav = useNavigationStack<string>();
return (
<List>
{MESSAGES.map(message => (
<ListItem
key={message}
label={message}
description="Tap to open; scroll the list under the bar."
endContent={
<Icon
icon="chevronRight"
color="secondary"
xstyle={rtlStyles.mirror}
/>
}
onClick={() => nav.push(message)}
/>
))}
</List>
);
}

function MessageBody({title}: {title: string}) {
return (
<List>
{Array.from({length: 30}, (_, index) => (
<ListItem
key={index}
label={`${title}, line ${index + 1}`}
description="Long content scrolls under the bar."
/>
))}
</List>
);
}

function ScrollingStack() {
const [path, setPath] = useState<string[]>([]);
return (
<div style={{height: '100vh'}}>
<NavigationStack
label="Mail"
root={
<NavigationScreen title="Inbox">
<MessageRows />
</NavigationScreen>
}
path={path}
onPathChange={setPath}
getKey={entry => entry}
renderScreen={entry => (
<NavigationScreen title={entry}>
<MessageBody title={entry} />
</NavigationScreen>
)}
data-testid="navigation-stack"
/>
</div>
);
}

/**
* Screens long enough to scroll under the bar. On a touch screen the bar
* paints no background. Once a screen's content has moved 10px under it, a
* veil of the body colour fades in, as iOS 26's scroll edge effect does.
* Each screen keeps its own veil through a push, a pop or a back swipe.
*/
export const Scrolling: Story = {
render: () => <ScrollingStack />,
};
17 changes: 17 additions & 0 deletions packages/core/src/internal/touch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ describe('internal/touch', () => {
expect(entry.navigation).toBeDefined();
});

it("re-exports by name what NavigationStack's bars and scroll edge effect read", async () => {
const entry: Record<string, unknown> = await import('./touch');
const host = await import('../gestures/GestureHost');
const pointer = await import('../utils/coarsePointer');
const fingerScroll = await import('../gestures/useFingerScroll');
expect(entry.getGestureHost).toBe(host.getGestureHost);
expect(entry.isCoarsePointer).toBe(pointer.isCoarsePointer);
expect(entry.useFingerScroll).toBe(fingerScroll.useFingerScroll);
for (const name of [
'getGestureHost',
'isCoarsePointer',
'useFingerScroll',
]) {
expect(typeof entry[name], name).toBe('function');
}
});

it('attaches no window or document listeners when it loads', async () => {
vi.resetModules();
const onWindow = vi.spyOn(window, 'addEventListener');
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/internal/touch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,10 @@ export {useInteractionModalityTracking} from '../utils/interactionModality';
// scroll is a finger's, and act when that scroll ends.
export {useFingerScroll} from '../gestures/useFingerScroll';
export type {UseFingerScrollOptions} from '../gestures/useFingerScroll';

// Lab's NavigationStack scroll edge effect reads the finger-scroll hook
// above, and drops the veil's compositing layer when a finger's scroll ends.
// It reads the gesture host for a finger's landing. The stack's bars read the
// coarse-pointer check.
export {getGestureHost} from '../gestures/GestureHost';
export {isCoarsePointer} from '../utils/coarsePointer';
2 changes: 1 addition & 1 deletion packages/lab/src/NavigationStack/NavigationStack.doc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const docs = {
name: 'NavigationStack',
displayName: 'Navigation Stack',
description:
"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.",
"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.",
props: [
{
name: 'root',
Expand Down
35 changes: 35 additions & 0 deletions packages/lab/src/NavigationStack/NavigationStack.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@ describe('NavigationStack', () => {
);
});

it('puts the scroll edge sentinel right after the large title', () => {
render(<LargeHarness />);
const scroller = screenCard('Settings')?.firstElementChild;
const content = scroller?.firstElementChild;
const [title, sentinel] = Array.from(content?.children ?? []);
expect(title).toBe(
screen.getByRole('heading', {level: 1, name: 'Settings'}),
);
// It ends where the large title ends, so the veil comes on as the
// bar's title takes over. The scroller holds no other sentinel.
expect(sentinel).toHaveAttribute('data-navigation-scroll-edge-sentinel');
expect(sentinel).toHaveAttribute('aria-hidden', 'true');
expect(
scroller?.querySelectorAll('[data-navigation-scroll-edge-sentinel]'),
).toHaveLength(1);
});

it('moves focus to the pushed screen’s large title', async () => {
render(<LargeHarness />);
const general = screen.getByRole('button', {name: 'General'});
Expand All @@ -234,6 +251,24 @@ describe('NavigationStack', () => {
});
});

it('marks the top of an inline screen’s content with the scroll edge sentinel, under its veil', () => {
render(<Harness />);
const card = screenCard('Settings');
const [sentinel, content] = Array.from(
card?.firstElementChild?.children ?? [],
);
// The sentinel sits just above the content, at its static position in
// the scroller. The screen's first element stays the content's first.
expect(sentinel).toHaveAttribute('data-navigation-scroll-edge-sentinel');
expect(
content?.querySelector('[data-navigation-scroll-edge-sentinel]'),
).toBeNull();
// The veil is the card's own child, over the scroller, hidden from
// assistive technology.
const veil = card?.querySelector(':scope > [data-navigation-scroll-edge]');
expect(veil).toHaveAttribute('aria-hidden', 'true');
});

it('shows a screen’s end content in its bar, out of reach once a screen covers it', async () => {
render(<Harness rootEndContent={<button type="button">Edit</button>} />);
const edit = screen.getByRole('button', {name: 'Edit'});
Expand Down
Loading
Loading