Skip to content

Commit cb135a2

Browse files
committed
fix(virtual-repeat): make infinite scroll work with initial small page size
If the initial page size is too small, where there are no views to move into the DOM, then the `getMore` function won’t be fired correctly, resulting in no additional pages being retrieved. By reacting to an initial, we can catch this event and force the `getMore` function to be called.
1 parent b73caea commit cb135a2

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/virtual-repeat.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ export class VirtualRepeat extends AbstractRepeater {
241241
}
242242
} else if (this._scrollingUp) {
243243
let viewsToMove = this._lastRebind - this._first;
244+
let initialScrollState = this.isLastIndex === undefined; //Use for catching initial scroll state where a small page size might cause _getMore not to fire.
244245
if (this._switchedDirection) {
245246
if (this.isLastIndex) {
246247
viewsToMove = this.items.length - this._first - this.elementsInView;
@@ -254,7 +255,8 @@ export class VirtualRepeat extends AbstractRepeater {
254255
this.movedViewsCount = movedViewsCount;
255256
let adjustHeight = movedViewsCount < viewsToMove ? this._topBufferHeight : itemHeight * movedViewsCount;
256257
if (viewsToMove > 0) {
257-
this._getMore();
258+
let force = this.movedViewsCount === 0 && initialScrollState && this._first <= 0 ? true : false;
259+
this._getMore(force);
258260
}
259261
this._switchedDirection = false;
260262
this._topBufferHeight = this._topBufferHeight - adjustHeight;
@@ -268,8 +270,8 @@ export class VirtualRepeat extends AbstractRepeater {
268270
this._ticking = false;
269271
}
270272

271-
_getMore(): void {
272-
if (this.isLastIndex || this._first === 0) {
273+
_getMore(force): void {
274+
if (this.isLastIndex || this._first === 0 || force) {
273275
if (!this._calledGetMore) {
274276
let executeGetMore = () => {
275277
this._calledGetMore = true;

test/virtual-repeat-integration.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,18 @@ describe('VirtualRepeat Integration', () => {
533533
}, 'scrollContainerPromise')
534534
});
535535
});
536+
it('handles getting next data set with small page size', done => {
537+
vm.items = [];
538+
for(let i = 0; i < 5; ++i) {
539+
vm.items.push('item' + i);
540+
}
541+
create.then(() => {
542+
validateScroll(virtualRepeat, viewModel, () => {
543+
expect(vm.getNextPage).toHaveBeenCalled();
544+
done();
545+
})
546+
});
547+
});
536548
it('passes the current index and location state', done => {
537549
create.then(() => {
538550
validateScroll(virtualRepeat, viewModel, () => {

0 commit comments

Comments
 (0)