From 564e52ce7b6de52c93cfc6c70b628e5c79ba01ae Mon Sep 17 00:00:00 2001 From: Yen-Wei Liu Date: Wed, 20 Mar 2024 19:17:02 +0000 Subject: [PATCH] [masonry] Revert splitIndex change --- .../Masonry/defaultTwoColumnModuleLayout.js | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/packages/gestalt/src/Masonry/defaultTwoColumnModuleLayout.js b/packages/gestalt/src/Masonry/defaultTwoColumnModuleLayout.js index d04b47e8de..d589ebcddb 100644 --- a/packages/gestalt/src/Masonry/defaultTwoColumnModuleLayout.js +++ b/packages/gestalt/src/Masonry/defaultTwoColumnModuleLayout.js @@ -40,23 +40,6 @@ function calculateTwoColumnModuleWidth(columnWidth: number, gutter: number): num return columnWidth * 2 + gutter; } -function calculateSplitIndex( - itemsWithoutPositions: $ReadOnlyArray, -): number { - // Currently we only support one two column item at the same time, more items will be supporped soon - const twoColumnIndex = itemsWithoutPositions.findIndex((item) => item.columnSpan === 2); - - if (twoColumnIndex < TWO_COL_ITEMS_MEASURE_BATCH_SIZE) { - return 0; - } - - if (twoColumnIndex + TWO_COL_ITEMS_MEASURE_BATCH_SIZE > itemsWithoutPositions.length) { - return itemsWithoutPositions.length - TWO_COL_ITEMS_MEASURE_BATCH_SIZE; - } - - return twoColumnIndex; -} - function initializeHeightsArray({ centerOffset, columnCount, @@ -302,8 +285,16 @@ const defaultTwoColumnModuleLayout = ({ if (hasTwoColumnItems) { // If the number of items to position is greater that the batch size // we identify the batch with the two column item and apply the graph only to those items - const splitIndex = calculateSplitIndex(itemsWithoutPositions); + // Currently we only support one two column item at the same time, more items will be supporped soon + const twoColumnIndex = itemsWithoutPositions.indexOf(twoColumnItems[0]); + + // If the number of items to position is greater that the batch size + // we identify the batch with the two column item and apply the graph only to those items const shouldBatchItems = itemsWithoutPositions.length > TWO_COL_ITEMS_MEASURE_BATCH_SIZE; + const splitIndex = + twoColumnIndex + TWO_COL_ITEMS_MEASURE_BATCH_SIZE > itemsWithoutPositions.length + ? itemsWithoutPositions.length - TWO_COL_ITEMS_MEASURE_BATCH_SIZE + : twoColumnIndex; const pre = shouldBatchItems ? itemsWithoutPositions.slice(0, splitIndex) : []; const batchWithTwoColumnItems = shouldBatchItems ? itemsWithoutPositions.slice(splitIndex, splitIndex + TWO_COL_ITEMS_MEASURE_BATCH_SIZE)