Skip to content

Commit 510eb60

Browse files
committed
fix(scroll): ask the edge question of the scroller under the swipe
The rest requirement resolved the edge state without the swipe point, so a nested screen could answer for a scroller the gesture never ran in. The baseline check now passes the swipe midpoint through readScrollEdgeState, the same selection the edge verdict uses, and the poll loop doc names the edge exception.
1 parent 7ee92d1 commit 510eb60

3 files changed

Lines changed: 61 additions & 4 deletions

File tree

‎packages/capture-kit/src/snapshot/scroll-edge-state.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ export async function captureScrollEdgeState(params: {
8181
export async function readScrollEdgeState(
8282
nodes: readonly (RawSnapshotNode | SnapshotNode)[],
8383
edge: ScrollEdge,
84+
target: ScrollEdgeTarget = {},
8485
): Promise<ScrollEdgeState> {
8586
const { analyzeScrollEdgeState } = await import('./scroll-edge-state/selection.ts');
86-
return analyzeScrollEdgeState(nodes, edge);
87+
return analyzeScrollEdgeState(nodes, edge, target);
8788
}
8889

8990
/**

‎src/daemon/__tests__/scroll-movement.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,57 @@ test('a bounce past the edge that springs back is at-edge, not moved', async ()
192192
assert.equal(spy.calls(), 3);
193193
});
194194

195+
/**
196+
* The edge question is asked of the scroller under the swipe, through the same selection the edge
197+
* verdict uses: among the containers holding the point, the one that still hides content in that
198+
* direction. An inner list at its end inside an outer list with more below hands the swipe to the
199+
* outer list (that is what the platform does with the gesture), so the rest requirement does not
200+
* engage and the first differing read is the movement it produced.
201+
*/
202+
test('an inner list at its end inside an outer list with hidden content hands the swipe on', async () => {
203+
const outer = {
204+
type: 'ScrollView',
205+
identifier: 'outer',
206+
rect: { x: 0, y: 100, width: 402, height: 760 },
207+
hiddenContentBelow: true,
208+
} as SnapshotNode;
209+
const inner = (rowOffset: number) => [
210+
outer,
211+
...screen(rowOffset, false).map((node) =>
212+
node.type === 'ScrollView' ? ({ ...node, identifier: 'inner' } as SnapshotNode) : node,
213+
),
214+
];
215+
const { observation, spy } = observe({
216+
baseline: baselineOf(inner(0)),
217+
screens: [inner(-300)],
218+
});
219+
220+
assert.equal(await observation, 'moved');
221+
assert.equal(spy.calls(), 1);
222+
});
223+
224+
/** With no outer list left to take it, the swipe point resolves the inner list and its edge gates the claim. */
225+
test('an inner list at its end with no outer list left to scroll is gated on rest', async () => {
226+
const outerAtEnd = {
227+
type: 'ScrollView',
228+
identifier: 'outer',
229+
rect: { x: 0, y: 100, width: 402, height: 760 },
230+
} as SnapshotNode;
231+
const inner = (rowOffset: number) => [
232+
outerAtEnd,
233+
...screen(rowOffset, false).map((node) =>
234+
node.type === 'ScrollView' ? ({ ...node, identifier: 'inner' } as SnapshotNode) : node,
235+
),
236+
];
237+
const { observation, spy } = observe({
238+
baseline: baselineOf(inner(0)),
239+
screens: [inner(-14), inner(0), inner(0)],
240+
});
241+
242+
assert.equal(await observation, 'at-edge');
243+
assert.equal(spy.calls(), 3);
244+
});
245+
195246
test('content that changes at the edge and holds still is still moved', async () => {
196247
const { observation, spy } = observe({
197248
baseline: baselineOf(screen(0, false)),

‎src/daemon/scroll-movement.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ function surfacePairDrift(
239239

240240
/**
241241
* Polls until an untouched surface proves itself. A surface that differs from the baseline is a
242-
* verdict on the first capture, so a scroll that worked pays for one read. One that looks untouched
242+
* verdict on the first capture, so a scroll that worked pays for one read, unless the baseline
243+
* already ended in the scrolled direction, where the change must hold still first
244+
* (`baselineEndsInDirection`). One that looks untouched
243245
* needs a quiet pair, because a gesture still in flight and a gesture that did nothing answer a
244246
* single read identically. A surface that never holds still expires as `surface-unsettled` rather
245247
* than being called a no-op — and that answer is worth a warning the others are not, since it spent
@@ -266,7 +268,7 @@ async function pollForSurfaceVerdict(
266268
attempts += 1;
267269
if (reading.kind === 'blind') return { kind: 'blind', reason: reading.reason };
268270
if (reading.kind === 'changed') {
269-
changeNeedsRest ??= await baselineEndsInDirection(baseline, params.direction);
271+
changeNeedsRest ??= await baselineEndsInDirection(baseline, params.direction, params.swipe);
270272
}
271273
const verdict = settledVerdict(reading, {
272274
previous,
@@ -324,10 +326,13 @@ function settledVerdict(
324326
async function baselineEndsInDirection(
325327
baseline: ScrollSurfaceBaseline,
326328
direction: ScrollDirection,
329+
swipe: ScrollSwipeEvidence,
327330
): Promise<boolean> {
328331
const edge = verticalEdgeFor(direction);
329332
if (!edge) return false;
330-
const state = await readScrollEdgeState(baseline.nodes, edge);
333+
// The question is asked of the scroller the swipe ran in: an inner list at its end inside an
334+
// outer list that still hides content is the inner list's edge, not the outer list's middle.
335+
const state = await readScrollEdgeState(baseline.nodes, edge, { point: swipe.midpoint });
331336
const ends = state.containerRect !== undefined && !state.canScroll;
332337
if (ends) {
333338
emitDiagnostic({

0 commit comments

Comments
 (0)