From a6ff12b3746e28b942da9b35d6d481b821c4f7b1 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Sun, 28 Apr 2024 17:23:59 -0400 Subject: [PATCH] Patch onStartReached improvement --- ...zed-lists+0.73.4+002+osr-improvement.patch | 33 +++++++++ ...ative-web+0.19.9+007+osr-improvement.patch | 70 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 patches/@react-native+virtualized-lists+0.73.4+002+osr-improvement.patch create mode 100644 patches/react-native-web+0.19.9+007+osr-improvement.patch diff --git a/patches/@react-native+virtualized-lists+0.73.4+002+osr-improvement.patch b/patches/@react-native+virtualized-lists+0.73.4+002+osr-improvement.patch new file mode 100644 index 000000000000..dc45a6758d5c --- /dev/null +++ b/patches/@react-native+virtualized-lists+0.73.4+002+osr-improvement.patch @@ -0,0 +1,33 @@ +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 +--- 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 { + zoomScale: 1, + }; + _scrollRef: ?React.ElementRef = null; +- _sentStartForContentLength = 0; ++ _sentStartForFirstVisibleItemKey: ?string = null; + _sentEndForContentLength = 0; + _updateCellsToRenderBatcher: Batchinator; + _viewabilityTuples: Array = []; +@@ -1550,16 +1550,16 @@ class VirtualizedList extends StateSafePureComponent { + onStartReached != null && + this.state.cellsAroundViewport.first === 0 && + isWithinStartThreshold && +- this._listMetrics.getContentLength() !== this._sentStartForContentLength ++ this.state.firstVisibleItemKey !== this._sentStartForFirstVisibleItemKey + ) { +- 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; diff --git a/patches/react-native-web+0.19.9+007+osr-improvement.patch b/patches/react-native-web+0.19.9+007+osr-improvement.patch new file mode 100644 index 000000000000..074cac3d0e6f --- /dev/null +++ b/patches/react-native-web+0.19.9+007+osr-improvement.patch @@ -0,0 +1,70 @@ +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 +--- 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 { + zoomScale: 1 + }; + this._scrollRef = null; +- this._sentStartForContentLength = 0; ++ this._sentStartForFirstVisibleItemKey = null; + this._sentEndForContentLength = 0; + this._totalCellLength = 0; + this._totalCellsMeasured = 0; +@@ -1397,8 +1397,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 +- else if (onStartReached != null && this.state.cellsAroundViewport.first === 0 && isWithinStartThreshold && this._scrollMetrics.contentLength !== this._sentStartForContentLength) { +- this._sentStartForContentLength = this._scrollMetrics.contentLength; ++ else if (onStartReached != null && this.state.cellsAroundViewport.first === 0 && isWithinStartThreshold && this.state.firstVisibleItemKey !== this._sentStartForFirstVisibleItemKey) { ++ this._sentStartForFirstVisibleItemKey = this.state.firstVisibleItemKey; + onStartReached({ + distanceFromStart + }); +@@ -1407,7 +1407,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 { +- this._sentStartForContentLength = isWithinStartThreshold ? this._sentStartForContentLength : 0; ++ this._sentStartForFirstVisibleItemKey = isWithinStartThreshold ? this._sentStartForFirstVisibleItemKey : null; + this._sentEndForContentLength = isWithinEndThreshold ? this._sentEndForContentLength : 0; + } + } +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 +--- 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 { + zoomScale: 1, + }; + _scrollRef: ?React.ElementRef = null; +- _sentStartForContentLength = 0; ++ _sentStartForFirstVisibleItemKey: ?string = null; + _sentEndForContentLength = 0; + _totalCellLength = 0; + _totalCellsMeasured = 0; +@@ -1675,18 +1675,18 @@ class VirtualizedList extends StateSafePureComponent { + onStartReached != null && + this.state.cellsAroundViewport.first === 0 && + isWithinStartThreshold && +- this._scrollMetrics.contentLength !== this._sentStartForContentLength ++ this.state.firstVisibleItemKey !== this._sentStartForFirstVisibleItemKey + ) { +- this._sentStartForContentLength = this._scrollMetrics.contentLength; ++ 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 + else { +- this._sentStartForContentLength = isWithinStartThreshold +- ? this._sentStartForContentLength +- : 0; ++ this._sentStartForFirstVisibleItemKey = isWithinStartThreshold ++ ? this._sentStartForFirstVisibleItemKey ++ : null; + this._sentEndForContentLength = isWithinEndThreshold + ? this._sentEndForContentLength + : 0;