From d376a444e318beabd8ebe9ccb41ffc300e12ea76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20B=C3=BCrger?= Date: Tue, 7 May 2019 08:22:44 -0700 Subject: [PATCH] Adjust scrollToLocation when using sticky section headers (#24735) Summary: When using `scrollToLocation` together with `stickySectionHeadersEnabled` in a `SectionList`, the length of the section header is not accounted for when scrolling to any item except the header. [General] [Fixed] - Adjust scrollToLocation when using sticky section headers Pull Request resolved: https://github.com/facebook/react-native/pull/24735 Differential Revision: D15240953 Pulled By: cpojer fbshipit-source-id: fd7121d990c5b01533e456bdfa39bebf6245fa80 --- Libraries/Lists/VirtualizedSectionList.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Libraries/Lists/VirtualizedSectionList.js b/Libraries/Lists/VirtualizedSectionList.js index 90e560c60..ceb039ba2 100644 --- a/Libraries/Lists/VirtualizedSectionList.js +++ b/Libraries/Lists/VirtualizedSectionList.js @@ -149,8 +149,16 @@ class VirtualizedSectionList< for (let i = 0; i < params.sectionIndex; i++) { index += this.props.getItemCount(this.props.sections[i].data) + 2; } + let viewOffset = 0; + if (params.itemIndex > 0 && this.props.stickySectionHeadersEnabled) { + const frame = this._listRef._getFrameMetricsApprox( + index - params.itemIndex, + ); + viewOffset = frame.length; + } const toIndexParams = { ...params, + viewOffset, index, }; this._listRef.scrollToIndex(toIndexParams);