Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve heuristic that triggers onStartReached #44287

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/virtualized-lists/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
zoomScale: 1,
};
_scrollRef: ?React.ElementRef<any> = null;
_sentStartForContentLength = 0;
_sentStartForFirstVisibleItemKey: ?string = null;
_sentEndForContentLength = 0;
_updateCellsToRenderBatcher: Batchinator;
_viewabilityTuples: Array<ViewabilityHelperCallbackTuple> = [];
Expand Down Expand Up @@ -1546,22 +1546,21 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
}

// Next check if the user just scrolled within the start threshold
// and call onStartReached only once for a given content length,
// and only if onEndReached is not being executed
// and call onStartReached only once for a given first visible item
if (
onStartReached != null &&
this.state.cellsAroundViewport.first === 0 &&
isWithinStartThreshold &&
this._listMetrics.getContentLength() !== this._sentStartForContentLength
this.state.firstVisibleItemKey !== this._sentStartForFirstVisibleItemKey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment above is now out of date it looks like

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, and only if onEndReached is not being executed that part was also out of date from a previous change.

) {
this._sentStartForContentLength = this._listMetrics.getContentLength();
this._sentStartForFirstVisibleItemKey = this.state.firstVisibleItemKey;
onStartReached({distanceFromStart});
}

// If the user scrolls away from the start or end and back again,
// cause onStartReached or onEndReached to be triggered again
if (!isWithinStartThreshold) {
this._sentStartForContentLength = 0;
this._sentStartForFirstVisibleItemKey = null;
}
if (!isWithinEndThreshold) {
this._sentEndForContentLength = 0;
Expand Down