Skip to content

Commit

Permalink
Fix onStartReached not called in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Jul 26, 2024
1 parent 904e950 commit 56c1a6a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
diff --git a/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.js b/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.js
index e338d90..70a59bf 100644
index e338d90..8620842 100644
--- a/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.js
+++ b/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.js
@@ -1219,7 +1219,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
@@ -698,19 +698,13 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
}

static getDerivedStateFromProps(newProps: Props, prevState: State): State {
- // first and last could be stale (e.g. if a new, shorter items props is passed in), so we make
- // sure we're rendering a reasonable range here.
const itemCount = newProps.getItemCount(newProps.data);
- if (itemCount === prevState.renderMask.numCells()) {
- return prevState;
- }
-
let maintainVisibleContentPositionAdjustment: ?number = null;
const prevFirstVisibleItemKey = prevState.firstVisibleItemKey;
const minIndexForVisible =
newProps.maintainVisibleContentPosition?.minIndexForVisible ?? 0;
const newFirstVisibleItemKey =
- newProps.getItemCount(newProps.data) > minIndexForVisible
+ itemCount > minIndexForVisible
? VirtualizedList._getItemKey(newProps, minIndexForVisible)
: null;
if (
@@ -1219,7 +1213,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
zoomScale: 1,
};
_scrollRef: ?React.ElementRef<any> = null;
Expand All @@ -11,7 +32,7 @@ index e338d90..70a59bf 100644
_sentEndForContentLength = 0;
_updateCellsToRenderBatcher: Batchinator;
_viewabilityTuples: Array<ViewabilityHelperCallbackTuple> = [];
@@ -1550,16 +1550,16 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
@@ -1550,16 +1544,16 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
onStartReached != null &&
this.state.cellsAroundViewport.first === 0 &&
isWithinStartThreshold &&
Expand Down
51 changes: 45 additions & 6 deletions patches/react-native-web+0.19.12+005+osr-improvement.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/node_modules/react-native-web/dist/vendor/react-native/VirtualizedList/index.js b/node_modules/react-native-web/dist/vendor/react-native/VirtualizedList/index.js
index b05da08..80aea85 100644
index bede95b..f91fa3d 100644
--- a/node_modules/react-native-web/dist/vendor/react-native/VirtualizedList/index.js
+++ b/node_modules/react-native-web/dist/vendor/react-native/VirtualizedList/index.js
@@ -332,7 +332,7 @@ class VirtualizedList extends StateSafePureComponent {
Expand All @@ -11,7 +11,25 @@ index b05da08..80aea85 100644
this._sentEndForContentLength = 0;
this._totalCellLength = 0;
this._totalCellsMeasured = 0;
@@ -1397,8 +1397,8 @@ class VirtualizedList extends StateSafePureComponent {
@@ -916,16 +916,11 @@ class VirtualizedList extends StateSafePureComponent {
}
static getDerivedStateFromProps(newProps, prevState) {
var _newProps$maintainVis, _newProps$maintainVis2;
- // first and last could be stale (e.g. if a new, shorter items props is passed in), so we make
- // sure we're rendering a reasonable range here.
var itemCount = newProps.getItemCount(newProps.data);
- if (itemCount === prevState.renderMask.numCells()) {
- return prevState;
- }
var maintainVisibleContentPositionAdjustment = null;
var prevFirstVisibleItemKey = prevState.firstVisibleItemKey;
var minIndexForVisible = (_newProps$maintainVis = (_newProps$maintainVis2 = newProps.maintainVisibleContentPosition) == null ? void 0 : _newProps$maintainVis2.minIndexForVisible) !== null && _newProps$maintainVis !== void 0 ? _newProps$maintainVis : 0;
- var newFirstVisibleItemKey = newProps.getItemCount(newProps.data) > minIndexForVisible ? VirtualizedList._getItemKey(newProps, minIndexForVisible) : null;
+ var newFirstVisibleItemKey = itemCount > minIndexForVisible ? VirtualizedList._getItemKey(newProps, minIndexForVisible) : null;
if (newProps.maintainVisibleContentPosition != null && prevFirstVisibleItemKey != null && newFirstVisibleItemKey != null) {
if (newFirstVisibleItemKey !== prevFirstVisibleItemKey) {
// Fast path if items were added at the start of the list.
@@ -1407,8 +1402,8 @@ class VirtualizedList extends StateSafePureComponent {
// 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
Expand All @@ -22,7 +40,7 @@ index b05da08..80aea85 100644
onStartReached({
distanceFromStart
});
@@ -1407,7 +1407,7 @@ class VirtualizedList extends StateSafePureComponent {
@@ -1417,7 +1412,7 @@ class VirtualizedList extends StateSafePureComponent {
// If the user scrolls away from the start or end and back again,
// cause onStartReached or onEndReached to be triggered again
else {
Expand All @@ -32,10 +50,31 @@ index b05da08..80aea85 100644
}
}
diff --git a/node_modules/react-native-web/src/vendor/react-native/VirtualizedList/index.js b/node_modules/react-native-web/src/vendor/react-native/VirtualizedList/index.js
index 459f017..799a6ee 100644
index 459f017..bc3ddf4 100644
--- a/node_modules/react-native-web/src/vendor/react-native/VirtualizedList/index.js
+++ b/node_modules/react-native-web/src/vendor/react-native/VirtualizedList/index.js
@@ -1325,7 +1325,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
@@ -806,19 +806,13 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
}

static getDerivedStateFromProps(newProps: Props, prevState: State): State {
- // first and last could be stale (e.g. if a new, shorter items props is passed in), so we make
- // sure we're rendering a reasonable range here.
const itemCount = newProps.getItemCount(newProps.data);
- if (itemCount === prevState.renderMask.numCells()) {
- return prevState;
- }
-
let maintainVisibleContentPositionAdjustment: ?number = null;
const prevFirstVisibleItemKey = prevState.firstVisibleItemKey;
const minIndexForVisible =
newProps.maintainVisibleContentPosition?.minIndexForVisible ?? 0;
const newFirstVisibleItemKey =
- newProps.getItemCount(newProps.data) > minIndexForVisible
+ itemCount > minIndexForVisible
? VirtualizedList._getItemKey(newProps, minIndexForVisible)
: null;
if (
@@ -1325,7 +1319,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
zoomScale: 1,
};
_scrollRef: ?React.ElementRef<any> = null;
Expand All @@ -44,7 +83,7 @@ index 459f017..799a6ee 100644
_sentEndForContentLength = 0;
_totalCellLength = 0;
_totalCellsMeasured = 0;
@@ -1675,18 +1675,18 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
@@ -1675,18 +1669,18 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
onStartReached != null &&
this.state.cellsAroundViewport.first === 0 &&
isWithinStartThreshold &&
Expand Down

0 comments on commit 56c1a6a

Please sign in to comment.