-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Improve heuristic that triggers onStartReached #44287
Conversation
@@ -1552,16 +1552,16 @@ class VirtualizedList extends StateSafePureComponent<Props, State> { | |||
onStartReached != null && | |||
this.state.cellsAroundViewport.first === 0 && | |||
isWithinStartThreshold && | |||
this._listMetrics.getContentLength() !== this._sentStartForContentLength | |||
this.state.firstVisibleItemKey !== this._sentStartForFirstVisibleItemKey |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This PR was closed because it has been stalled for 7 days with no activity. |
Summary:
onStartReached
is called more than it should be since our heuristic to not re-trigger it is based on the list content size. This has worked fine foronEndReached
, but foronStartReached
it causes some issues.On initial mount we receive different content size updates. I assume this is normal because of virtualization and the need to measure content. However for
onStartReached
since we usually start at scroll position 0 we are already in the threshold so any change to content size causes us to trigger aonStartReached
event.For example using this code we get 2
onStartReached
calls on mount. On top of this every time we add items at the end of the listonStartReached
is called another time.To improve this I suggest using
firstVisibleItemKey
that we use formaintainVisibleContentPosition
to track if we should re-triggeronStartReached
. This means that it will be only re-triggered if new items are added at the start of the list or if we leave the threshold.Changelog:
[GENERAL] [FIXED] - Improve heuristic that triggers onStartReached
Test Plan:
Tested using this code. See that
onStartReached
is only called once on mount and then again only if leaving the threshold or adding new items at the start of the list. Adding items at the end of the list should also not triggeronStartReached
.