Skip to content

Commit

Permalink
Allow out-of-range initialScrollIndex after first scroll
Browse files Browse the repository at this point in the history
Summary:
The contract here is that `initialScrollIndex` only applies once, right after the components mount. There is other code still relying on live `initialScrollIndex`, which is allowed to become stale. E.g. after removing items.

I looked at a larger change of only ever using `initialScrollIndex` in the start, so we have a consistent value. We also ideally should fix up the logic relying on it for the scroll to top optimization.

That series of changes is more involved than I want to spend time on, so this just avoids the check once we have triggered a scroll, where the rest of the code is UT'd to be permissive if it drifts out of allowed.

Changelog:
[General][Fixed] - Allow out-of-range initialScrollIndex after first scroll

Reviewed By: yungsters

Differential Revision: D43926656

fbshipit-source-id: bd09bd9a9aa6b3b5f07209dac8652c9374a762c4
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Mar 14, 2023
1 parent d8b4737 commit d595fbc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/virtualized-lists/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {

constructor(props: Props) {
super(props);
this.checkProps(props);
this._checkProps(props);

this._fillRateHelper = new FillRateHelper(this._getFrameMetrics);
this._updateCellsToRenderBatcher = new Batchinator(
Expand Down Expand Up @@ -454,7 +454,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
};
}

checkProps(props: Props) {
_checkProps(props: Props) {
const {onScroll, windowSize, getItemCount, data, initialScrollIndex} =
props;

Expand All @@ -478,6 +478,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {

if (
initialScrollIndex != null &&
!this._hasTriggeredInitialScrollToIndex &&
(initialScrollIndex < 0 ||
(itemCount > 0 && initialScrollIndex >= itemCount)) &&
!this._hasWarned.initialScrollIndex
Expand Down Expand Up @@ -842,7 +843,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
}

render(): React.Node {
this.checkProps(this.props);
this._checkProps(this.props);
const {ListEmptyComponent, ListFooterComponent, ListHeaderComponent} =
this.props;
const {data, horizontal} = this.props;
Expand Down

0 comments on commit d595fbc

Please sign in to comment.