Skip to content

Commit 69206a9

Browse files
author
Amro Altahtamouni
committed
[RN] Fix VirtualizedSectionList.scrollToLocation off-by-one and sticky header offset
Summary: VirtualizedSectionList.scrollToLocation incorrectly mapped itemIndex to the underlying flat list index. It used itemIndex directly instead of itemIndex + 1 to skip the section header, so itemIndex: 0 landed on the header and every other item was one row too early. It also only added the sticky-header viewOffset compensation when itemIndex > 0, so the first item was rendered under the sticky header. This change adds the missing + 1 for the header row and makes the sticky-header offset unconditional, using the section header measured height (index - itemIndex - 1). This is a breaking behavioural fix with no type change. Thanks to Marc Rousavy (mrousavy) for the diagnosis: #50143 Changelog: [General][Breaking] - Fix SectionList and VirtualizedSectionList scrollToLocation to correctly account for section headers and sticky headers. Test Plan: - js1 test xplat/js/react-native-github/packages/virtualized-lists/Lists/__tests__/VirtualizedSectionList-test.js — 18 passed - arc lint clean Differential Revision: https://www.internalfb.com/intern/phabricator/D118547738
1 parent d44efb0 commit 69206a9

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎packages/virtualized-lists/Lists/VirtualizedSectionList.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class VirtualizedSectionList<
138138
State,
139139
> {
140140
scrollToLocation(params: ScrollToLocationParamsType) {
141-
let index = params.itemIndex;
141+
let index = params.itemIndex + 1;
142142
for (let i = 0; i < params.sectionIndex; i++) {
143143
index += this.props.getItemCount(this.props.sections[i].data) + 2;
144144
}
@@ -147,10 +147,10 @@ class VirtualizedSectionList<
147147
return;
148148
}
149149
const listRef = this._listRef;
150-
if (params.itemIndex > 0 && this.props.stickySectionHeadersEnabled) {
150+
if (this.props.stickySectionHeadersEnabled) {
151151
const frame = listRef
152152
.__getListMetrics()
153-
.getCellMetricsApprox(index - params.itemIndex, listRef.props);
153+
.getCellMetricsApprox(index - params.itemIndex - 1, listRef.props);
154154
viewOffset += frame.length;
155155
}
156156
const toIndexParams: {

0 commit comments

Comments
 (0)