Skip to content

Commit

Permalink
fix(InfiniteGrid): prevent code for prepend after append
Browse files Browse the repository at this point in the history
  • Loading branch information
sculove committed Nov 27, 2017
1 parent f3c4c17 commit 7400662
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 7,956 deletions.
2 changes: 1 addition & 1 deletion dist/infinitegrid.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/infinitegrid.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/infinitegrid.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/infinitegrid.min.js.map

Large diffs are not rendered by default.

3,967 changes: 0 additions & 3,967 deletions dist/infinitegrid.pkgd.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/infinitegrid.pkgd.js.map

This file was deleted.

3,967 changes: 0 additions & 3,967 deletions dist/infinitegrid.pkgd.min.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/infinitegrid.pkgd.min.js.map

This file was deleted.

29 changes: 14 additions & 15 deletions src/InfiniteGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ class InfiniteGrid extends Component {
return this._items.pluck("items", 0, this._items.size());
}
_getVisibleItems() {
console.log("visible", this._status.startCursor, "~", this._status.endCursor);
return this._items.pluck("items", this._status.startCursor, this._status.endCursor);
}
_updateEdge() {
Expand Down Expand Up @@ -230,29 +229,28 @@ class InfiniteGrid extends Component {
this._fit = () => 0;
return 0;
}

if (this._layout) {
const base = this._getEdgeValue("start");

if (base !== 0) {
this._status.isProcessing = true;
if (scrollCycle === "before") {
console.trace("fit....before");
this._renderer.scrollBy(-Math.abs(base));
this._watcher.setScrollPos();
}
console.trace("fit....", base, JSON.stringify(this._items._data[this._status.endCursor].outlines));
this._items.fit(base, this._isVertical);
DOMRenderer.renderItems(this._getVisibleItems());
console.log("fit 이후", JSON.stringify(this._items._data[this._status.endCursor].outlines));
const height = this._getEdgeValue("end");
this._renderer.setContainerSize(height);
console.log("height 조절", height);
this._renderer.setContainerSize(this._getEdgeValue("end"));
if (scrollCycle === "after") {
console.trace("fit....after");
this._renderer.scrollBy(Math.abs(base));
this._watcher.setScrollPos();
}
this._status.isProcessing = false;
}
return base;
} else {
return 0;
}
}
_getEdgeValue(cursor) {
Expand Down Expand Up @@ -431,8 +429,10 @@ class InfiniteGrid extends Component {
_recycle(isAppend) {
const remove = [];

for (let i = this._status.startCursor; i <= this._status.endCursor; i++) {
remove.push(this._isVisible(i));
if (this._status.startCursor !== this._status.endCursor) {
for (let i = this._status.startCursor; i <= this._status.endCursor; i++) {
remove.push(this._isVisible(i));
}
}
let start = remove.indexOf(isAppend ? 1 : -1);
let end = remove.lastIndexOf(isAppend ? 1 : -1);
Expand All @@ -451,7 +451,6 @@ class InfiniteGrid extends Component {

_postLayout(fromCache, items, isAppend, isTrusted) {
if (fromCache) {
console.log("캐시....");
this._renderer.createAndInsert(items, isAppend);
this._updateCursor(isAppend);
this.options.useRecycle && this._recycle(isAppend);
Expand Down Expand Up @@ -515,7 +514,6 @@ class InfiniteGrid extends Component {
}
// called by visible
_requestAppend() {
console.log("requestAppend");
const items = this._getNextItems(APPEND);

if (items.length) {
Expand Down Expand Up @@ -624,7 +622,8 @@ class InfiniteGrid extends Component {
orgScrollPos: this._watcher.getOrgScrollPos(),
size,
});
console.warn("_onLayoutComplete [", this._status.startCursor, this._status.endCursor, "]");
this._watcher.ignoreCheckOnce();
// console.warn("_onLayoutComplete [", this._status.startCursor, this._status.endCursor, "]");
}
_reset() {
this._status = {
Expand Down
7 changes: 6 additions & 1 deletion src/Watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,19 @@ export default class Watcher {
getOrgScrollPos() {
return scroll(this._renderer.view, this._renderer.options.isVertical);
}
ignoreCheckOnce() {
// scroll position is not changed on iOS
this._prevPos = null;
}
_onCheck() {
const orgScrollPos = this.getOrgScrollPos();
const prevPos = this.getScrollPos();

this.setScrollPos(orgScrollPos);
const scrollPos = this.getScrollPos();

if ((IS_IOS && orgScrollPos === 0) || prevPos === scrollPos) {
// ignore check event when ignoreCheckOnce method is called.
if ((IS_IOS && orgScrollPos === 0) || prevPos === scrollPos || prevPos === null) {
return;
}
this._callback.check && this._callback.check({
Expand Down

0 comments on commit 7400662

Please sign in to comment.