Skip to content

Commit

Permalink
Merge pull request #32843 from margelo/perunt/fix-last-spacer
Browse files Browse the repository at this point in the history
Fix last spacer
  • Loading branch information
roryabraham authored Jan 10, 2024
2 parents aaba81f + 8aca887 commit ce67e8a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
34 changes: 34 additions & 0 deletions patches/@react-native+virtualized-lists+0.72.8.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
diff --git a/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.js b/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.js
index ef5a3f0..2590edd 100644
--- a/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.js
+++ b/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.js
@@ -125,19 +125,6 @@ function windowSizeOrDefault(windowSize: ?number) {
return windowSize ?? 21;
}

-function findLastWhere<T>(
- arr: $ReadOnlyArray<T>,
- predicate: (element: T) => boolean,
-): T | null {
- for (let i = arr.length - 1; i >= 0; i--) {
- if (predicate(arr[i])) {
- return arr[i];
- }
- }
-
- return null;
-}
-
/**
* Base implementation for the more convenient [`<FlatList>`](https://reactnative.dev/docs/flatlist)
* and [`<SectionList>`](https://reactnative.dev/docs/sectionlist) components, which are also better
@@ -1019,7 +1006,8 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
const spacerKey = this._getSpacerKey(!horizontal);

const renderRegions = this.state.renderMask.enumerateRegions();
- const lastSpacer = findLastWhere(renderRegions, r => r.isSpacer);
+ const lastRegion = renderRegions[renderRegions.length - 1];
+ const lastSpacer = lastRegion?.isSpacer ? lastRegion : null;

for (const section of renderRegions) {
if (section.isSpacer) {
29 changes: 29 additions & 0 deletions patches/react-native-web+0.19.9+004+fixLastSpacer.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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 faeb323..68d740a 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
@@ -78,14 +78,6 @@ function scrollEventThrottleOrDefault(scrollEventThrottle) {
function windowSizeOrDefault(windowSize) {
return windowSize !== null && windowSize !== void 0 ? windowSize : 21;
}
-function findLastWhere(arr, predicate) {
- for (var i = arr.length - 1; i >= 0; i--) {
- if (predicate(arr[i])) {
- return arr[i];
- }
- }
- return null;
-}

/**
* Base implementation for the more convenient [`<FlatList>`](https://reactnative.dev/docs/flatlist)
@@ -1119,7 +1111,8 @@ class VirtualizedList extends StateSafePureComponent {
_keylessItemComponentName = '';
var spacerKey = this._getSpacerKey(!horizontal);
var renderRegions = this.state.renderMask.enumerateRegions();
- var lastSpacer = findLastWhere(renderRegions, r => r.isSpacer);
+ var lastRegion = renderRegions[renderRegions.length - 1];
+ var lastSpacer = lastRegion?.isSpacer ? lastRegion : null;
for (var _iterator = _createForOfIteratorHelperLoose(renderRegions), _step; !(_step = _iterator()).done;) {
var section = _step.value;
if (section.isSpacer) {

0 comments on commit ce67e8a

Please sign in to comment.