Skip to content

Commit b869680

Browse files
Christian Ruinkfacebook-github-bot
Christian Ruink
authored andcommitted
Fixing onEndReachedThreshold === 0 not firing onEndReached function on Android.
Summary: Changelog: [Android][Fix] - When `onEndReachedThreshold` is set to 0 `onEndReached` function on `VirtualizedList` properly fires once the user scrolls to the bottom of the list. Reviewed By: genkikondo Differential Revision: D36488189 fbshipit-source-id: b95f3291f2957273280696d8840c1e000d669380
1 parent 21a4c1f commit b869680

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Libraries/Lists/VirtualizedList.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const FillRateHelper = require('./FillRateHelper');
4242
const ViewabilityHelper = require('./ViewabilityHelper');
4343
const invariant = require('invariant');
4444

45+
const ON_END_REACHED_EPSILON = 0.001;
46+
4547
type Item = any;
4648

4749
export type Separators = {
@@ -218,7 +220,8 @@ type OptionalProps = {|
218220
* How far from the end (in units of visible length of the list) the bottom edge of the
219221
* list must be from the end of the content to trigger the `onEndReached` callback.
220222
* Thus a value of 0.5 will trigger `onEndReached` when the end of the content is
221-
* within half the visible length of the list.
223+
* within half the visible length of the list. A value of 0 will not trigger until scrolling
224+
* to the very end of the list.
222225
*/
223226
onEndReachedThreshold?: ?number,
224227
/**
@@ -1516,13 +1519,22 @@ class VirtualizedList extends React.PureComponent<Props, State> {
15161519
const {data, getItemCount, onEndReached, onEndReachedThreshold} =
15171520
this.props;
15181521
const {contentLength, visibleLength, offset} = this._scrollMetrics;
1519-
const distanceFromEnd = contentLength - visibleLength - offset;
1522+
let distanceFromEnd = contentLength - visibleLength - offset;
1523+
1524+
// Especially when oERT is zero it's necessary to 'floor' very small distanceFromEnd values to be 0
1525+
// since debouncing causes us to not fire this event for every single "pixel" we scroll and can thus
1526+
// be at the "end" of the list with a distanceFromEnd approximating 0 but not quite there.
1527+
if (distanceFromEnd < ON_END_REACHED_EPSILON) {
1528+
distanceFromEnd = 0;
1529+
}
1530+
1531+
// TODO: T121172172 Look into why we're "defaulting" to a threshold of 2 when oERT is not present
15201532
const threshold =
15211533
onEndReachedThreshold != null ? onEndReachedThreshold * visibleLength : 2;
15221534
if (
15231535
onEndReached &&
15241536
this.state.last === getItemCount(data) - 1 &&
1525-
distanceFromEnd < threshold &&
1537+
distanceFromEnd <= threshold &&
15261538
this._scrollMetrics.contentLength !== this._sentEndForContentLength
15271539
) {
15281540
// Only call onEndReached once for a given content length

0 commit comments

Comments
 (0)