From e9edd4d551f83ab71272dbd995e75129d8297a98 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Tue, 9 Oct 2018 14:48:00 +0300 Subject: [PATCH] Fix avgRowHeight correcting bug --- DynamicVirtualScroll.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/DynamicVirtualScroll.js b/DynamicVirtualScroll.js index 2bf7f12..bb5960e 100644 --- a/DynamicVirtualScroll.js +++ b/DynamicVirtualScroll.js @@ -111,10 +111,10 @@ export function virtualScrollDriver(props, oldState, getRenderedItemHeight) } sum += itemSize; } - if (sum + newState.lastItemsTotalHeight + newState.topPlaceholderHeight > newState.targetHeight) + const correctedAvg = (sum + newState.lastItemsTotalHeight) / (count + newState.viewportItemCount); + if (correctedAvg > newState.avgRowHeight) { - // avgRowHeight should be corrected - newState.avgRowHeight = (sum + newState.lastItemsTotalHeight) / (count + newState.viewportItemCount); + newState.avgRowHeight = correctedAvg; } } else @@ -133,10 +133,10 @@ export function virtualScrollDriver(props, oldState, getRenderedItemHeight) sum += itemSize; } newState.middlePlaceholderHeight = newState.targetHeight - sum - newState.lastItemsTotalHeight - newState.topPlaceholderHeight; - if (newState.middlePlaceholderHeight < 0) + const correctedAvg = (sum + newState.lastItemsTotalHeight) / (newState.middleItemCount + newState.viewportItemCount); + if (correctedAvg > newState.avgRowHeight) { - // avgRowHeight should be corrected - newState.avgRowHeight = (sum + newState.lastItemsTotalHeight) / (newState.middleItemCount + newState.viewportItemCount); + newState.avgRowHeight = correctedAvg; } } return newState;