Skip to content

Commit 740d13a

Browse files
committed
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.
1 parent 389f78c commit 740d13a

4 files changed

Lines changed: 95 additions & 49 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,10 @@ describe('NavigationStack', () => {
209209
render(<LargeHarness />);
210210
const large = screen.getByRole('heading', {level: 1, name: 'Settings'});
211211
// First in the screen's scrolling content.
212-
expect(screenCard('Settings')?.firstElementChild?.firstElementChild).toBe(
213-
large,
214-
);
212+
expect(
213+
screenCard('Settings')?.firstElementChild?.firstElementChild
214+
?.firstElementChild,
215+
).toBe(large);
215216
// The bar's copy of the title is hidden while the large one shows.
216217
expect(screen.getAllByRole('heading', {name: 'Settings'})).toHaveLength(
217218
1,

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ function CardLayer({
382382
const entry = registry.get(model.key) ?? {};
383383
entry.largeTitleElement = title;
384384
registry.set(model.key, entry);
385-
const scroller = title?.parentElement ?? null;
385+
// The title is first in the scroll content, so a change of its height
386+
// reaches the scroll area's measure. The scroller holds that content.
387+
const scroller = title?.parentElement?.parentElement ?? null;
386388
if (title == null || scroller == null) {
387389
return undefined;
388390
}
@@ -442,18 +444,20 @@ function CardLayer({
442444
{...getViewportProps<HTMLDivElement>({
443445
xstyle: [focusOutlineStyles.focusVisible, styles.scroller],
444446
})}>
445-
{isLarge ? (
446-
<h1
447-
ref={largeTitleCallback}
448-
tabIndex={-1}
449-
{...stylex.props(
450-
focusOutlineStyles.focusVisible,
451-
styles.largeTitle,
452-
)}>
453-
{props.title}
454-
</h1>
455-
) : null}
456-
<div {...getContentProps<HTMLDivElement>({})}>{props.children}</div>
447+
<div {...getContentProps<HTMLDivElement>({})}>
448+
{isLarge ? (
449+
<h1
450+
ref={largeTitleCallback}
451+
tabIndex={-1}
452+
{...stylex.props(
453+
focusOutlineStyles.focusVisible,
454+
styles.largeTitle,
455+
)}>
456+
{props.title}
457+
</h1>
458+
) : null}
459+
{props.children}
460+
</div>
457461
</div>
458462
<div
459463
ref={dim.ref}

‎packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts‎

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,11 @@
66
* touch input (Chromium CDP / WebKit's input command) and the interaction
77
* harness
88
* @output Proofs that NavigationStack moves like UINavigationController on
9-
* iOS 26.2. A push follows UIKit's push spring (critically damped, 0.3 s,
10-
* starting at 8.773 widths/s) to within half a pixel. The card underneath
11-
* moves at 0.3 of its speed. The back swipe tracks the finger 1:1 from the
12-
* leading edge and from the content. It finishes or springs back by UIKit's
13-
* release rule, and a flick finishes from near the edge. A push keeps
14-
* advancing every frame through a blocked main thread and does no Layout
15-
* or Paint. Reduce Motion cross-fades. The spec also writes storyboards of
16-
* a push and of a released swipe.
9+
* iOS 26.2. They cover the push spring, the parallax, both back swipes and
10+
* their release, and a blocked main thread. They also cover Reduce Motion,
11+
* and write storyboards of a push and of a released swipe.
1712
* @position Interaction proof for lab NavigationStack (NavigationStack.tsx,
18-
* navigationTransition.ts); shape copied from the harness exemplar,
19-
* BottomSheetDetent.interaction.browser.spec.ts
13+
* navigationTransition.ts)
2014
*/
2115

2216
import {
@@ -1387,6 +1381,58 @@ test.describe('edge cases', () => {
13871381
await page.setViewportSize({width: 400, height: 200});
13881382
await expect.poll(contain).toBe('contain');
13891383
});
1384+
1385+
test('a large title that grows re-measures its screen', async ({page}) => {
1386+
await openStack(page, 'large-title');
1387+
const root = card(page, 'root');
1388+
const contain = async () =>
1389+
root.evaluate(
1390+
element =>
1391+
getComputedStyle(element.firstElementChild ?? element)
1392+
.overscrollBehaviorY,
1393+
);
1394+
// A viewport just taller than the screen's content: nothing to scroll.
1395+
const contentHeight = await root.evaluate(
1396+
element => (element.firstElementChild as HTMLElement).scrollHeight,
1397+
);
1398+
await page.setViewportSize({width: 400, height: contentHeight + 40});
1399+
await expect.poll(contain).toBe('auto');
1400+
// A font load, the resize and the stack's release of its motion hints
1401+
// each start a measurement of their own. Let them end first, so that only
1402+
// the title can start the next one.
1403+
await page.evaluate(async () => {
1404+
await document.fonts.ready;
1405+
});
1406+
await expect
1407+
.poll(() =>
1408+
page.evaluate(
1409+
() => document.querySelector('[style*="will-change"]') == null,
1410+
),
1411+
)
1412+
.toBe(true);
1413+
await page.evaluate(
1414+
() =>
1415+
new Promise<void>(resolve => {
1416+
let frames = 5;
1417+
const tick = () => {
1418+
frames -= 1;
1419+
if (frames === 0) {
1420+
resolve();
1421+
} else {
1422+
requestAnimationFrame(tick);
1423+
}
1424+
};
1425+
requestAnimationFrame(tick);
1426+
}),
1427+
);
1428+
expect(await contain()).toBe('auto');
1429+
// A taller line makes the title taller, with no font to load. No box but
1430+
// the title's own changes size, and the screen now overflows.
1431+
await root
1432+
.locator('h1')
1433+
.evaluate(title => title.style.setProperty('line-height', '400px'));
1434+
await expect.poll(contain).toBe('contain');
1435+
});
13901436
});
13911437

13921438
test('a push does no Layout or Paint per frame', async ({

‎packages/lab/src/NavigationStack/navigationTransition.ts‎

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@
44
* @file navigationTransition.ts
55
* @input The navigation table (navigationMotion.ts) and Core's rubber band
66
* (its internal touch entry)
7-
* @output Pure math for NavigationStack's push/pop transition: the layers'
8-
* values at a progress (`layersAt`) and their velocities for a progress
9-
* velocity (`layerVelocities`). It also gives the interactive pop's release
10-
* rule (`shouldFinishPop`), progress from a finger's travel
11-
* (`progressFromTravel`) and the progress a caught screen resumes from
12-
* (`progressFromScreen`).
7+
* @output Pure math for NavigationStack's transition: layer values and
8+
* velocities at a progress (`layersAt`, `layerVelocities`). Also the pop's
9+
* release rule (`shouldFinishPop`) and progress from travel or a caught
10+
* screen (`progressFromTravel`, `progressFromScreen`).
1311
* @position Lab NavigationStack internals; no DOM, no React. The component
1412
* hands these numbers to the compositor animator.
1513
*
16-
* One number describes a transition: progress `p`, the share of the width
17-
* the top card has uncovered. `p = 0`: the top card covers the screen (a
18-
* push has landed). `p = 1`: it has left and the card under it is back (a
19-
* pop has landed). A push runs p 1 → 0 and a pop runs p 0 → 1. An
20-
* interactive pop scrubs p with the finger (UIKit: `percentComplete` =
21-
* translation / width).
22-
*
14+
* SYNC: When modified, update navigationTransition.test.ts.
15+
*/
16+
17+
import {rubberBand, rubberBandInverse} from '@astryxdesign/core/internal/touch';
18+
19+
import {navigation} from './navigationMotion';
20+
21+
/**
2322
* The layers, as UIKit moves them on iOS 26.2 (measured):
2423
* - top card: x = p · W;
2524
* - card under it: x = parallax · W · (1 − p), so from −0.3 W to 0;
@@ -29,14 +28,7 @@
2928
*
3029
* Every layer is linear in p, so one spring run on all of them with
3130
* velocities scaled the same way keeps them on one trajectory.
32-
*
33-
* SYNC: When modified, update navigationTransition.test.ts.
3431
*/
35-
36-
import {rubberBand, rubberBandInverse} from '@astryxdesign/core/internal/touch';
37-
38-
import {navigation} from './navigationMotion';
39-
4032
export interface TransitionLayers {
4133
/** The top card's translateX, px. */
4234
readonly topX: number;
@@ -49,9 +41,12 @@ export interface TransitionLayers {
4941
const clamp01 = (value: number) => Math.min(1, Math.max(0, value));
5042

5143
/**
52-
* The layers at progress `p` for a container `width` px wide. `direction`
53-
* is the writing direction: under RTL cards enter from the left, so every x
54-
* flips.
44+
* The layers at progress `p` for a container `width` px wide. `p` is the
45+
* share of the width the top card has uncovered: 0 when a push has landed,
46+
* 1 when a pop has landed. A push runs p 1 → 0 and a pop runs p 0 → 1. An
47+
* interactive pop scrubs p with the finger (UIKit's `percentComplete`).
48+
* `direction` is the writing direction: under RTL cards enter from the left,
49+
* so every x flips.
5550
*/
5651
export function layersAt(
5752
p: number,

0 commit comments

Comments
 (0)