Skip to content

Commit c2b7554

Browse files
committed
fix(snapshot): stop iOS 27 floating-bar containers from covering content
On iOS 27 a `_UIFloatingBarContainerView` (type `Toolbar`) marks content covered in two shapes the sibling-sized and full-viewport exemptions miss. A tabbar/toolbar/navigationbar container whose rect matches its parent is exempt when a sibling branch encloses it. The runner prunes the same-size sibling the raw tree lists, so the container ends up beside the larger content branch instead. The full-viewport check accepts a container that matches the viewport's x, width and bottom edge and starts up to 4pt below its top. An app that draws a 2pt strip above its window content pushes the container to y=2. Fixes #3883
1 parent 1d28b51 commit c2b7554

3 files changed

Lines changed: 163 additions & 4 deletions

File tree

‎packages/capture-kit/src/snapshot-occlusion-sibling-sized-chrome.test.ts‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,3 +723,67 @@ test('a control the exempt toolbar host really hosts still covers the row it ove
723723

724724
assert.deepEqual(coveredLabels(nodes), ['Barless row 12']);
725725
});
726+
727+
/**
728+
* The iOS 27 runner shape from a React Native tab screen on an iPhone 18 Pro Max: the content branch
729+
* starts under the header at y=2, the layout container and its `_UIFloatingBarContainerView` start
730+
* at y=64, and the wrapper that matched the container in the raw tree has been pruned.
731+
*/
732+
function parentSizedTree(deltas: { branchRect?: Rect; chromeRect?: Rect } = {}): RawSnapshotNode[] {
733+
const viewport: Rect = { x: 0, y: 0, width: 440, height: 956 };
734+
const layout: Rect = { x: 0, y: 64, width: 440, height: 892 };
735+
return [
736+
node({ index: 0, depth: 0, type: 'Application', rect: viewport }),
737+
node({ index: 1, parentIndex: 0, depth: 1, type: 'Window', rect: viewport, hittable: true }),
738+
node({ index: 2, parentIndex: 1, depth: 2, type: 'Other', rect: layout, hittable: true }),
739+
node({
740+
index: 3,
741+
parentIndex: 2,
742+
depth: 3,
743+
type: 'Other',
744+
rect: deltas.branchRect ?? { x: 0, y: 2, width: 440, height: 954 },
745+
hittable: true,
746+
}),
747+
node({
748+
index: 4,
749+
parentIndex: 3,
750+
depth: 4,
751+
type: 'Other',
752+
label: 'Rooms',
753+
rect: { x: 16, y: 313, width: 408, height: 46 },
754+
hittable: true,
755+
}),
756+
node({
757+
index: 5,
758+
parentIndex: 2,
759+
depth: 3,
760+
type: 'Toolbar',
761+
label: 'Toolbar',
762+
rect: deltas.chromeRect ?? layout,
763+
hittable: true,
764+
}),
765+
];
766+
}
767+
768+
test('a chrome container sized to its parent beside a branch that encloses it does not cover that branch', () => {
769+
const target = targetVerdict(parentSizedTree());
770+
771+
assert.equal(target?.interactionBlocked, undefined);
772+
});
773+
774+
test('a parent-sized chrome container still covers when no sibling encloses it', () => {
775+
// A bar alone in a same-size wrapper, beside a branch shorter than the bar, keeps covering.
776+
const target = targetVerdict(
777+
parentSizedTree({ branchRect: { x: 0, y: 64, width: 440, height: 700 } }),
778+
);
779+
780+
assert.equal(target?.interactionBlocked, 'covered');
781+
});
782+
783+
test('a chrome container smaller than its parent still covers the branch beside it', () => {
784+
const target = targetVerdict(
785+
parentSizedTree({ chromeRect: { x: 0, y: 64, width: 440, height: 600 } }),
786+
);
787+
788+
assert.equal(target?.interactionBlocked, 'covered');
789+
});

‎packages/capture-kit/src/snapshot-occlusion.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,50 @@ test('a full-viewport toolbar container does not cover its application siblings'
671671
assert.equal(annotated[1]?.interactionBlocked, undefined);
672672
});
673673

674+
test.for([
675+
// #3883: on iOS 27 an app's 2pt top bar pushes the floating-bar container to y=2.
676+
{
677+
name: 'a toolbar container 2pt below the viewport top does not cover its application siblings',
678+
topInset: 2,
679+
expected: undefined,
680+
},
681+
{
682+
name: 'a toolbar container 4pt below the viewport top does not cover its application siblings',
683+
topInset: 4,
684+
expected: undefined,
685+
},
686+
{
687+
name: 'a toolbar container 5pt below the viewport top covers its application siblings',
688+
topInset: 5,
689+
expected: 'covered',
690+
},
691+
])('$name', ({ topInset, expected }) => {
692+
const application: RawSnapshotNode = {
693+
index: 0,
694+
type: 'application',
695+
rect: { x: 0, y: 0, width: 440, height: 956 },
696+
};
697+
const target: RawSnapshotNode = {
698+
index: 1,
699+
type: 'button',
700+
role: 'button',
701+
parentIndex: 0,
702+
label: 'Room',
703+
rect: { x: 16, y: 313, width: 408, height: 46 },
704+
};
705+
const toolbarContainer: RawSnapshotNode = {
706+
index: 2,
707+
type: 'toolbar',
708+
parentIndex: 0,
709+
label: 'Toolbar',
710+
rect: { x: 0, y: topInset, width: 440, height: 956 - topInset },
711+
};
712+
713+
const annotated = annotateCoveredSnapshotNodes([application, target, toolbarContainer]);
714+
715+
assert.equal(annotated[1]?.interactionBlocked, expected);
716+
});
717+
674718
test('the kind fields join with a separator, so adjacent fragments never accidentally concatenate into a match', () => {
675719
// type "tab" + role "bar" must read as "tab bar" (no match for the
676720
// 'tabbar' overlay fragment) — never "tabbar" via an unseparated join,

‎packages/capture-kit/src/snapshot-occlusion.ts‎

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ const OVERLAY_KIND_FRAGMENTS = [
2626
'menu',
2727
];
2828
const VIEWPORT_CHROME_KIND_FRAGMENTS = ['tabbar', 'toolbar', 'navigationbar'];
29+
/**
30+
* How far below the viewport top a full-viewport chrome container may start, before the 0.5pt rect
31+
* tolerance. On iOS 27 an app that draws a 2pt bar at the top gets a `_UIFloatingBarContainerView`
32+
* at y=2 (#3883). A container that starts below the status bar is tens of points down and gets no
33+
* exemption from this check.
34+
*/
35+
const VIEWPORT_CHROME_TOP_INSET_PT = 4;
2936
const TOOLBAR_HOST_KIND_FRAGMENTS = ['toolbar'];
3037
const SCROLL_INDICATOR_KIND_FRAGMENTS = ['scrollbar', 'scrollindicator'];
3138
const SEMANTIC_TOUCH_KIND_FRAGMENTS = [
@@ -361,9 +368,43 @@ function isSiblingSizedChromeContainer(
361368
const rect = positiveRect(node.rect);
362369
if (!rect) return false;
363370
const siblings = neighbourhood.childrenByParent.get(node.parentIndex) ?? [];
364-
return siblings.some(
365-
(sibling) => sibling.index !== node.index && areRectsApproximatelyEqual(rect, sibling.rect),
366-
);
371+
if (
372+
siblings.some(
373+
(sibling) => sibling.index !== node.index && areRectsApproximatelyEqual(rect, sibling.rect),
374+
)
375+
) {
376+
return true;
377+
}
378+
const parent = neighbourhood.byIndex.get(node.parentIndex);
379+
return Boolean(parent && isParentSizedBesideEnclosingBranch(node, rect, parent, siblings));
380+
}
381+
382+
/**
383+
* The same footprint after the runner has pruned the sibling that matched it. On iOS 27 a React
384+
* Native tab screen's content branch extends under the header (`0,2,440,954`) while its
385+
* `_UIFloatingBarContainerView` keeps the layout container's frame (`0,64,440,892`), and the
386+
* container-sized wrapper the raw tree lists beside it is dropped as an empty `Other`. The container
387+
* then matches its parent, and a sibling branch encloses it.
388+
*
389+
* Requiring the enclosing sibling keeps a bar that merely fills a same-size wrapper covering: a
390+
* navigation or tool bar wrapped on its own has no sibling at least as large as itself.
391+
*
392+
* Accepted limit: a bar that fills a bar-sized wrapper, beside a sibling that overflows that wrapper
393+
* (a backdrop larger than the bar), is exempt too, and stops covering content under it that the
394+
* sibling does not hold. No capture shows that shape.
395+
*/
396+
function isParentSizedBesideEnclosingBranch(
397+
node: RawSnapshotNode,
398+
rect: Rect,
399+
parent: RawSnapshotNode,
400+
siblings: readonly RawSnapshotNode[],
401+
): boolean {
402+
if (!areRectsApproximatelyEqual(rect, parent.rect)) return false;
403+
return siblings.some((sibling) => {
404+
if (sibling.index === node.index) return false;
405+
const siblingRect = positiveRect(sibling.rect);
406+
return Boolean(siblingRect && rectContains(siblingRect, rect));
407+
});
367408
}
368409

369410
/**
@@ -421,7 +462,7 @@ function isFullViewportChromeContainer(
421462
while (current && !visited.has(current.index)) {
422463
if (isViewportRootNode(current)) {
423464
const viewportRect = positiveRect(current.rect);
424-
return Boolean(viewportRect && areRectsApproximatelyEqual(rect, viewportRect));
465+
return Boolean(viewportRect && isViewportFootprint(rect, viewportRect));
425466
}
426467
visited.add(current.index);
427468
current =
@@ -531,3 +572,13 @@ function positiveRect(rect: RawSnapshotNode['rect']): Rect | null {
531572
function mergeCoveredHint(hints: string[] | undefined): string[] {
532573
return Array.from(new Set([...(hints ?? []), COVERED_PRESENTATION_HINT]));
533574
}
575+
576+
/** The viewport's frame, or the viewport below a strip of at most `VIEWPORT_CHROME_TOP_INSET_PT`. */
577+
function isViewportFootprint(rect: Rect, viewport: Rect): boolean {
578+
const topInset = Math.min(Math.max(rect.y - viewport.y, 0), VIEWPORT_CHROME_TOP_INSET_PT);
579+
return areRectsApproximatelyEqual(rect, {
580+
...viewport,
581+
y: viewport.y + topInset,
582+
height: viewport.height - topInset,
583+
});
584+
}

0 commit comments

Comments
 (0)