@@ -64,8 +64,11 @@ function selectScrollContainer(
6464 target : ScrollEdgeTarget ,
6565) : SnapshotNode | null {
6666 const visibility = createSnapshotVisibility ( nodes ) ;
67+ const reportsVerticalEdge = ( node : SnapshotNode ) : boolean =>
68+ hasHiddenContentAtEdge ( node , hiddenHints . get ( node . index ) , 'top' ) ||
69+ hasHiddenContentAtEdge ( node , hiddenHints . get ( node . index ) , 'bottom' ) ;
6770 const edgeContainer = ( node : SnapshotNode ) : SnapshotNode =>
68- sameRectScrollableAncestor ( node , visibility . nodeByIndex ) ?? node ;
71+ sameRectScrollableAncestor ( node , visibility . nodeByIndex , reportsVerticalEdge ) ?? node ;
6972 const scrollables = [
7073 ...new Set (
7174 nodes
@@ -168,20 +171,23 @@ function hasHiddenContentAtEdge(
168171}
169172
170173/**
171- * The outermost scrollable in an unbroken chain of same-rect scrollable ancestors, or undefined when
172- * the nearest scrollable ancestor frames different pixels. Scroll edge selection stands that
173- * ancestor in for the nested scroller: Android's Settings RecyclerView offers scroll-backward even at
174- * the top, while the ScrollView framing the same pixels reports the real position (#3737). Choosing
175- * the ancestor also keeps the nested scroller inside the scoped recapture. Visited indexes stop a
176- * cyclic `parentIndex` chain in a malformed tree.
174+ * The outermost scrollable in an unbroken chain of same-rect, vertically scrolling ancestors, or
175+ * undefined when the nearest scrollable ancestor frames different pixels or reports no vertical edge.
176+ * Scroll edge selection stands that ancestor in for the nested scroller: Android's Settings
177+ * RecyclerView offers scroll-backward even at the top, while the ScrollView framing the same pixels
178+ * reports the real position (#3737). Choosing the ancestor also keeps the nested scroller inside the
179+ * scoped recapture. Visited indexes stop a cyclic `parentIndex` chain in a malformed tree.
177180 *
178- * This is a geometric heuristic: an identical rect is taken to mean the two scrollers move the same
179- * content. It ignores scroll axis, so a horizontal scroller framing exactly the same pixels as a
180- * vertical list nested in it would stand in for that list. No known screen has that shape.
181+ * An identical rect is a geometric heuristic for "these two scrollers move the same content", and
182+ * geometry carries no scroll axis. Requiring the ancestor to report a vertical edge hint keeps a
183+ * horizontal pager whose page holds a vertical list from standing in for that list; the snapshot
184+ * emits vertical edge hints only for vertical scrollers. A vertical ancestor whose content fits in
185+ * both directions reports no edge either, and leaves the nested scroller to answer for itself.
181186 */
182187function sameRectScrollableAncestor (
183188 node : SnapshotNode ,
184189 byIndex : ReadonlyMap < number , SnapshotNode > ,
190+ reportsVerticalEdge : ( candidate : SnapshotNode ) => boolean ,
185191) : SnapshotNode | undefined {
186192 const visited = new Set < number > ( [ node . index ] ) ;
187193 let owner : SnapshotNode | undefined ;
@@ -190,7 +196,7 @@ function sameRectScrollableAncestor(
190196 while ( parent && ! visited . has ( parent . index ) ) {
191197 visited . add ( parent . index ) ;
192198 if ( isScrollableNodeLike ( parent ) && isUsableRect ( parent . rect ) ) {
193- if ( ! sameRect ( parent . rect , current . rect ) ) return owner ;
199+ if ( ! sameRect ( parent . rect , current . rect ) || ! reportsVerticalEdge ( parent ) ) return owner ;
194200 owner = parent ;
195201 current = parent ;
196202 }
0 commit comments