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
This commit is contained in:
Danilo Bürger
2019-05-07 08:22:44 -07:00
committed by Facebook Github Bot
parent 509a07b207
commit d376a444e3

View File

@@ -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);