Skip to content

Commit

Permalink
fix(InfiniteGrid): fix attached scroll and no request append event (#229
Browse files Browse the repository at this point in the history
)

* fix(InfiniteGrid): fix no children and request append event
* fix(InfiniteGrid): fix attached scroll
Close #227 
Close #228
  • Loading branch information
daybrush authored Oct 12, 2018
1 parent 514ce55 commit e8e1f42
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
20 changes: 13 additions & 7 deletions src/InfiniteGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,14 @@ class InfiniteGrid extends Component {
}
}
// check childElement
if (!size) {
this._insert(toArray(renderer.container.children), true);
return this;
}
if (!items.length) {
if (!size || !items.length) {
const children = toArray(renderer.container.children);

if (children.length) {
this._insert(children, true);
} else {
this._requestAppend({});
}
return this;
}
// layout datas
Expand Down Expand Up @@ -885,7 +888,7 @@ ig.on("imageError", e => {
*/
this.trigger("append", {
isTrusted: TRUSTED,
groupKey: this.getGroupKeys().pop(),
groupKey: this.getGroupKeys().pop() || "",
startLoading: userStyle => {
this.startLoading(true, userStyle);
},
Expand Down Expand Up @@ -974,7 +977,10 @@ ig.on("imageError", e => {

const size = this._getEdgeValue("end");

isAppend && this._setContainerSize(size + this._status.loadingSize || 0);
if (isAppend) {
this._setContainerSize(size + this._status.loadingSize || 0);
this._scrollTo(scrollPos);
}
!isLayout && this._process(PROCESSING, false);

/**
Expand Down
44 changes: 42 additions & 2 deletions test/unit/InfiniteGrid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,19 @@ describe("InfiniteGrid Test", function () {
outlines.forEach(outline => {
expect(outline).to.be.equals(outlines[0]);
});


});
it(`should check no children and call 'append' event`, async() => {
// Given
const waitAppend = waitEvent(this.inst, "append");

// When
this.inst.layout();

const rv = await waitAppend;

// Then
expect(rv.groupKey).to.be.equals("");
})
it(`should check getStatus(startCursor, endCursor)`, async () => {
// Given
await waitInsert(this.inst, true, 10, 10);
Expand Down Expand Up @@ -435,6 +445,36 @@ describe("InfiniteGrid Test", function () {
});
});
});
describe(`When scroll is attached to the Bottom`, function () {
beforeEach(() => {
this.el = sandbox();
this.el.innerHTML = `<div id='infinite'></div><div id="footer" style="position:relative;width: 100%; height: ${window.innerHeight * 3}px;"></div>`;
this.inst = new InfiniteGrid("#infinite", {
margin: 5,
});
this.inst.setLayout(GridLayout);
});
afterEach(() => {
if (this.inst) {
this.inst.destroy();
this.inst = null;
}
cleanup();
});
it (`should check attached scroll`, async () => {
// Given
const scrollPos = document.body.offsetHeight - window.innerHeight;

// When
window.scrollTo(0, scrollPos);
await wait(100);
await waitInsert(this.inst, true, 10, 4);

// Then
expect(Math.max(document.body.scrollTop, document.documentElement.scrollTop)).to.be.equals(scrollPos);

});
});
describe(`When appending, image test`, function () {
beforeEach(() => {
this.el = sandbox();
Expand Down

0 comments on commit e8e1f42

Please sign in to comment.