Skip to content

Commit

Permalink
fix: issues on performances using sections
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocesarato committed Jun 16, 2021
1 parent 2e28c93 commit f4413ef
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion lib/BigListProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,23 @@ export default class BigListProcessor {
}
};

/**
* Calculate spacer height.
*/
const getSpacerHeight = () => {
let itemsCounter = -1;
return items.reduce((totalHeight, item, i) => {
if (i !== items.length - 1) {
const fullRow = isFullRow(item);
itemsCounter = fullRow ? 0 : itemsCounter + 1;
if (fullRow || itemsCounter % this.numColumns === 0) {
return totalHeight + item.height;
}
}
return totalHeight;
}, 0);
};

// Header
const headerHeight = this.getHeaderHeight();
if (headerHeight > 0) {
Expand All @@ -228,9 +245,29 @@ export default class BigListProcessor {
const sectionHeaderHeight = this.getSectionHeaderHeight(section);
position = height;
height += sectionHeaderHeight;
if (
section > 1 &&
items.length > 0 &&
items[items.length - 1].type === BigListItemType.SECTION_HEADER
) {
// Top Spacer
const initialSpacerHeight = getSpacerHeight();
const prevSection = items[items.length - 1];
items.splice(0, items.length);
push(
{
type: BigListItemType.SPACER,
position: 0,
height: initialSpacerHeight,
section: prevSection.section,
index: 0,
},
prevSection,
);
}
pushItem({
type: BigListItemType.SECTION_HEADER,
position: section > 0 ? position - headerHeight : position,
position: position,
height: sectionHeaderHeight,
section: section,
});
Expand Down

0 comments on commit f4413ef

Please sign in to comment.