|
@@ -22,12 +22,17 @@ class ListViewAdapter {
|
|
|
console.log(this.scriptName);
|
|
|
let actualCount = this.dataList.length < this.spawnCount ? this.dataList.length : this.spawnCount;
|
|
|
// let actualCount = this.dataList.length;
|
|
|
+ if (this.itemHeight > 0) {
|
|
|
+ this.bufferZone = this.scrollView.node.height / 2 + this.content.height / 2;
|
|
|
+ this.content.height = (this.itemHeight + this.spacing) * this.dataList.length;
|
|
|
+ }
|
|
|
this.scriptItems = [];
|
|
|
this.content.removeAllChildren();
|
|
|
for (let i = 0; i < actualCount; i++) { // spawn items, we only need to do this once
|
|
|
let item = cc.instantiate(itemTemplate);
|
|
|
if (this.itemHeight === 0) {
|
|
|
this.itemHeight = item.height; // get total content height
|
|
|
+ this.bufferZone = this.scrollView.node.height / 2 + this.content.height / 2;
|
|
|
this.content.height = (this.itemHeight + this.spacing) * this.dataList.length;
|
|
|
}
|
|
|
this.content.addChild(item);
|
|
@@ -58,16 +63,16 @@ class ListViewAdapter {
|
|
|
let viewPos = this.getPositionInView(this.scriptItems[i].node);
|
|
|
if (isDown) {
|
|
|
// if away from buffer zone and not reaching top of content
|
|
|
- if (viewPos.y < -buffer && this.scriptItems[i].y + offset < 0) {
|
|
|
- this.scriptItems[i].node.y = this.scriptItems[i].y + offset;
|
|
|
+ if (viewPos.y < -buffer && this.scriptItems[i].node.y + offset < 0) {
|
|
|
+ this.scriptItems[i].node.y = this.scriptItems[i].node.y + offset;
|
|
|
let itemScript = this.scriptItems[i];
|
|
|
let itemId = itemScript._itemId - this.scriptItems.length;
|
|
|
itemScript.updateItem(this.dataList[itemId], itemId);
|
|
|
}
|
|
|
} else {
|
|
|
// if away from buffer zone and not reaching bottom of content
|
|
|
- if (viewPos.y > buffer && this.scriptItems[i].y - offset > -this.content.height) {
|
|
|
- this.scriptItems[i].node.y = this.scriptItems[i].y - offset;
|
|
|
+ if (viewPos.y > buffer && this.scriptItems[i].node.y - offset > -this.content.height) {
|
|
|
+ this.scriptItems[i].node.y = this.scriptItems[i].node.y - offset;
|
|
|
|
|
|
let itemScript = this.scriptItems[i];
|
|
|
let itemId = itemScript._itemId + scriptItems.length;
|