Skip to content

Commit

Permalink
adapting facebook#26444 to solve issue facebook#30373
Browse files Browse the repository at this point in the history
- Import improvements from PR facebook#26444 _maybeCallOnEndReached:
https://github.com/facebook/react-native/pull/26444/files#diff-7481ec8ed5532798b075df637e805a8e439807aa2ce671208c24068c286361e8L1374-R1413
https://github.com/facebook/react-native/blob/2d3f6ca9801ef92b446458a2efc795db4ec17021/Libraries/Lists/VirtualizedList.js#L1372-L1414
- Additional check _hasDoneFirstScroll for maybeCallOnEndReached (added in onScroll callback)
- Add improved logic start/endPositionReached and isScrollingForward
- Add threeshold instead of 2
- Use default threeshold 30 for iOS
- Add other improvements from method _maybeCallOnEndReached
  • Loading branch information
fabOnReact committed Sep 26, 2022
1 parent 82768f7 commit 3242de0
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const ViewabilityHelper = require('./ViewabilityHelper');
const invariant = require('invariant');

const ON_END_REACHED_EPSILON = 0.001;
const MIN_START_POSITION_THRESHOLD = 2;

let _usedIndexForKey = false;
let _keylessItemComponentName: string = '';
Expand Down Expand Up @@ -1329,22 +1330,19 @@ class VirtualizedList extends React.PureComponent<Props, State> {
inverted &&
enabledTalkbackCompatibleInvertedList;
let distanceFromEnd;
let endPositionReached;
let startPositionReached;
let isScrollingForward = dOffset < 0;
const threeshold = onEndReachedThresholdOrDefault(onEndReachedThreshold);
// in case of inverted flatlist with talkback enabled
// replace 2 with threeshold
const THRESHOLD = Platform.OS === 'android' ? 2 : 30;
if (talkbackCompatibility && this._hasTriggeredInitialScrollToIndex) {
distanceFromEnd = offset;
startPositionReached =
Math.abs(visibleLength + offset - contentLength) < THRESHOLD;
endPositionReached = Math.abs(offset) < THRESHOLD;
Math.abs(visibleLength + offset - contentLength) <
MIN_START_POSITION_THRESHOLD;
} else {
distanceFromEnd = contentLength - visibleLength - offset;
endPositionReached =
Math.abs(visibleLength + offset - contentLength) < THRESHOLD;
startPositionReached = Math.abs(offset) < THRESHOLD;
startPositionReached = Math.abs(offset) < MIN_START_POSITION_THRESHOLD;
}

if (
Expand All @@ -1370,9 +1368,8 @@ class VirtualizedList extends React.PureComponent<Props, State> {
return;
}

// $FlowFixMe
const minimumDistanceFromEnd = onEndReachedThreshold * visibleLength;
if (distanceFromEnd >= minimumDistanceFromEnd) {
const minimumDistanceFromEnd = threeshold * visibleLength;
if (distanceFromEnd > minimumDistanceFromEnd) {
return;
}

Expand All @@ -1399,9 +1396,11 @@ class VirtualizedList extends React.PureComponent<Props, State> {
inverted &&
enabledTalkbackCompatibleInvertedList
) {
/*
console.error(
'The prop enabledTalkbackCompatibleInvertedList can not be used with initialScrollIndex.',
);
*/
}
if (
width > 0 &&
Expand Down

0 comments on commit 3242de0

Please sign in to comment.