Skip to content

Commit

Permalink
fix(array-virtual-repeat-strategy): add new items to the distance to …
Browse files Browse the repository at this point in the history
…bottom view port
  • Loading branch information
martingust committed Mar 27, 2016
1 parent d8d0a24 commit 6038310
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/array-virtual-repeat-strategy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ArrayRepeatStrategy} from 'aurelia-templating-resources/array-repeat-strategy';
import {createFullOverrideContext} from 'aurelia-templating-resources/repeat-utilities';
import {updateVirtualOverrideContexts, rebindAndMoveView} from './utilities';
import {updateVirtualOverrideContexts, rebindAndMoveView, getElementDistanceToBottomViewPort} from './utilities';

/**
* A strategy for repeating a template over an array.
Expand Down Expand Up @@ -204,30 +204,32 @@ export class ArrayVirtualRepeatStrategy extends ArrayRepeatStrategy {
_handleAddedSplices(repeat, array, splices) {
let arrayLength = array.length;
let viewSlot = repeat.viewSlot;
let viewCount = repeat.viewCount();
for (let i = 0, ii = splices.length; i < ii; ++i) {
let splice = splices[i];
let addIndex = splice.index;
let end = splice.index + splice.addedCount;

for (; addIndex < end; ++addIndex) {
if (viewCount === 0 || !this._isIndexBeforeViewSlot(repeat, viewSlot, addIndex) && !this._isIndexAfterViewSlot(repeat, viewSlot, addIndex)) {
let hasDistanceToBottomViewPort = getElementDistanceToBottomViewPort(repeat.bottomBuffer.previousElementSibling) > 0;
if (repeat.viewCount() === 0 || (!this._isIndexBeforeViewSlot(repeat, viewSlot, addIndex) && !this._isIndexAfterViewSlot(repeat, viewSlot, addIndex)) || hasDistanceToBottomViewPort) {
let overrideContext = createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength);
repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext);
if (!repeat._hasCalculatedSizes) {
repeat._calcInitialHeights(1);
} else if (viewCount > repeat._viewsLength) {
repeat.removeView(viewCount - 1, true, true);
repeat._bottomBufferHeight = repeat._bottomBufferHeight + repeat.itemHeight;
} else if (repeat.viewCount() > repeat._viewsLength) {
if (hasDistanceToBottomViewPort) {
repeat.removeView(0, true, true);
repeat._topBufferHeight = repeat._topBufferHeight + repeat.itemHeight;
repeat._adjustBufferHeights();
} else {
repeat.removeView(repeat.viewCount() - 1, true, true);
repeat._bottomBufferHeight = repeat._bottomBufferHeight + repeat.itemHeight;
}
}
} else if (this._isIndexBeforeViewSlot(repeat, viewSlot, addIndex)) {
repeat._topBufferHeight = repeat._topBufferHeight + repeat.itemHeight;
} else if (this._isIndexAfterViewSlot(repeat, viewSlot, addIndex)) {
repeat._bottomBufferHeight = repeat._bottomBufferHeight + repeat.itemHeight;
repeat.isLastIndex = false;
if (repeat._lastRebind > repeat.elementsInView) {
repeat._lastRebind--;
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ export function getStyleValue(element, style) {
styleValue = parseInt(currentStyle[style], 10);
return Number.isNaN(styleValue) ? 0 : styleValue;
}

export function getElementDistanceToBottomViewPort(element) {
return document.documentElement.clientHeight - element.getBoundingClientRect().bottom;
}

0 comments on commit 6038310

Please sign in to comment.