Skip to content

Commit

Permalink
improvements to amp-list load-more (ampproject#30851)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouyx authored and ed-bird committed Dec 10, 2020
1 parent ee2f6fd commit 718f7ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 7 additions & 3 deletions extensions/amp-list/0.1/amp-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -1556,8 +1556,9 @@ export class AmpList extends AMP.BaseElement {
}

/**
* If the bottom of the list is within three viewports of the current
* viewport, then load more items.
* If the bottom of the list is visible and
* within three viewports of the current viewport,
* then load more items.
* @private
*/
maybeLoadMoreItems_() {
Expand All @@ -1570,7 +1571,10 @@ export class AmpList extends AMP.BaseElement {
.getClientRectAsync(dev().assertElement(endoOfListMarker))
.then((positionRect) => {
const viewportHeight = this.viewport_.getHeight();
if (3 * viewportHeight > positionRect.bottom) {
if (
positionRect.bottom > 0 &&
3 * viewportHeight > positionRect.bottom
) {
return this.loadMoreCallback_();
}
});
Expand Down
11 changes: 6 additions & 5 deletions extensions/amp-list/0.1/test/test-amp-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,13 @@ describes.repeated(
});
});

it('should resize with viewport', () => {
it('should resize with viewport', async () => {
const resize = env.sandbox.spy(list, 'attemptToFit_');
list.layoutCallback().then(() => {
list.viewport_.resize_();
expect(resize).to.have.been.called;
});
const itemElement = doc.createElement('div');
expectFetchAndRender(DEFAULT_FETCHED_DATA, [itemElement]);
await list.layoutCallback();
list.viewport_.resize_();
expect(resize).to.be.calledOnce;
});

// TODO(choumx, #14772): Flaky.
Expand Down

0 comments on commit 718f7ce

Please sign in to comment.