From 3346ac7f96d2fd3f77dca5acb283b28e02ad21fa Mon Sep 17 00:00:00 2001 From: Mark Verlingieri Date: Thu, 11 Jun 2020 15:40:40 -0700 Subject: [PATCH] Don't scroll to initial item if ContentOffset is provided Summary: The initialScrollIndex in VirtualizedList contains a performance optimization to start rendering the list at the index provided. ContentOffset does not contain this optimization and there is currently no way to specify the first item in the list to start rendering without contentOffset being ignored. This change makes it so that if both initialScrollIndex and ContentOffset are provided, the list will start rendering at the initialScrollIndex but ContentOffset will still be used to set the scroll position. initialScrollIndex functionality will remain the same if ContentOffset is not provided. Changelog: [Changed] VirtualizedList will use contentOffset for scroll position instead of initialScrollIndex if both are provided Reviewed By: sahrens Differential Revision: D21980172 fbshipit-source-id: 36d2d2bc360845ef02329d2b95a2cf14b91c2b0b --- Libraries/Lists/VirtualizedList.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 9b107b2c2cb2ea..42935dabdac80f 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -1491,10 +1491,12 @@ class VirtualizedList extends React.PureComponent { this.props.initialScrollIndex > 0 && !this._hasDoneInitialScroll ) { - this.scrollToIndex({ - animated: false, - index: this.props.initialScrollIndex, - }); + if (this.props.contentOffset == null) { + this.scrollToIndex({ + animated: false, + index: this.props.initialScrollIndex, + }); + } this._hasDoneInitialScroll = true; } if (this.props.onContentSizeChange) {