From d81c67b6cf02b77611834b3064ad03c5388dae10 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Thu, 7 Dec 2023 17:36:53 -0500 Subject: [PATCH] Fix last spacer constrain logic --- .../virtualized-lists/Lists/VirtualizedList.js | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/packages/virtualized-lists/Lists/VirtualizedList.js b/packages/virtualized-lists/Lists/VirtualizedList.js index 4efaf669e3d875..33e84cd66d833b 100644 --- a/packages/virtualized-lists/Lists/VirtualizedList.js +++ b/packages/virtualized-lists/Lists/VirtualizedList.js @@ -90,19 +90,6 @@ type State = { pendingScrollUpdateCount: number, }; -function findLastWhere( - arr: $ReadOnlyArray, - predicate: (element: T) => boolean, -): T | null { - for (let i = arr.length - 1; i >= 0; i--) { - if (predicate(arr[i])) { - return arr[i]; - } - } - - return null; -} - function getScrollingThreshold(threshold: number, visibleLength: number) { return (threshold * visibleLength) / 2; } @@ -987,7 +974,8 @@ class VirtualizedList extends StateSafePureComponent { 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) {