Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix last spacer #32843

Merged
merged 8 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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+005+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) {
Loading