From 9e3c18c47241179e05cf9aa4ef4ba5eb94b70586 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 23 Nov 2018 23:08:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=BD=AC=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TurntableDemo/assets/Script/TurntableMgr.js | 41 ++++++++++++--------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/TurntableDemo/assets/Script/TurntableMgr.js b/TurntableDemo/assets/Script/TurntableMgr.js index 28f4172..38f8245 100644 --- a/TurntableDemo/assets/Script/TurntableMgr.js +++ b/TurntableDemo/assets/Script/TurntableMgr.js @@ -3,10 +3,11 @@ cc.Class({ properties: { nodeBoxBg: cc.Node, - total: 6,//几项奖品 - section: 0,//一项奖品切多少份 - resultIdx: 0,//显示的结果id - delayTime: 0,//延期多少才开始显示结果 + total: 6, //几项奖品 + section: 0, //一项奖品切多少份 + // resultIdx: 0, //显示的结果id + delayTime: 0, //延期多少才开始显示结果 + isRandom: false, }, initProperties() { @@ -32,37 +33,43 @@ cc.Class({ } }, - onLoad() { - this.initProperties(); - this.initSection(); - }, - start() { - this.init(); + this.init({ + resultIdx: 2, + delayTime: 3, + }); }, /** * @param {*} data */ init(data) { + this.initProperties(); + this.resultIdx = (data.resultIdx - 1 + this.total) % this.total; + this.delayTime = data.delayTime; + this.onEnd = data.onFinish; + let totalIdx = this.total - 1; this.onAccelerate(); this.node.runAction(cc.sequence(cc.delayTime(1 + this.delayTime), cc.callFunc(() => { console.log('已经选择了'); - this.choiceIdx = (this.total - this.resultIdx) * this.section; - this.choiceIdx = this.randomChoiceIdx(this.choiceIdx); + this.choiceIdx = (totalIdx - this.resultIdx) * this.section; + if (this.isRandom) { + this.choiceIdx = this.randomChoiceIdx(this.choiceIdx); + } }))); }, onFinish() { console.log('结束了'); + this.onEnd && this.onEnd(); }, randomChoiceIdx(idx) { console.log('randomChoiceIdx'); let randomIdx = Math.floor(Math.random() * (this.section - 1)); - if (randomIdx == 0) {//不能是上边 + if (randomIdx == 0) { //不能是上边 randomIdx++; - } else if (randomIdx == this.section) {////不能是下边 + } else if (randomIdx == this.section) { ////不能是下边 randomIdx--; } let temp = Math.floor(this.section / 2); @@ -90,7 +97,6 @@ cc.Class({ console.log(rotation, this.rotationSpeed); this.showResult = true; } - console.log('rotation=', rotation, this.rotationSpeed, idx); if (this.rotationSpeed <= 0) { this.onFinish(); } @@ -151,6 +157,8 @@ cc.Class({ * @param {*} dt */ update(dt) { + // console.log('dt=', dt); + dt = 0.016; if (this.rotationSpeed >= 0) { this.nodeBoxBg.rotation += this.rotationSpeed * dt; } @@ -160,6 +168,5 @@ cc.Class({ /** * 统一回收组件 */ - onDestroy() { - } + onDestroy() { } }); \ No newline at end of file From 0e640eabbea0c794453c801ab3a66a8c3a53244b Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 25 Nov 2018 01:27:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9ListViewJsDemo=E4=B8=AD?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ListViewJsDemo/assets/Scene/helloworld.fire | 536 +++++++----------- ListViewJsDemo/assets/Script/HelloWorld.js | 5 +- ListViewJsDemo/assets/Script/ListAdapter.js | 48 +- .../assets/Script/ListAdapter.js.meta | 2 +- ListViewJsDemo/assets/Script/ListView.js | 304 ++++++++++ .../{ListView.ts.meta => ListView.js.meta} | 2 +- ListViewJsDemo/assets/Script/ListView.ts | 321 ----------- .../assets/Texture/HelloWorld.png.meta | 3 +- .../assets/Texture/singleColor.png.meta | 3 +- 9 files changed, 550 insertions(+), 674 deletions(-) create mode 100644 ListViewJsDemo/assets/Script/ListView.js rename ListViewJsDemo/assets/Script/{ListView.ts.meta => ListView.js.meta} (74%) delete mode 100644 ListViewJsDemo/assets/Script/ListView.ts diff --git a/ListViewJsDemo/assets/Scene/helloworld.fire b/ListViewJsDemo/assets/Scene/helloworld.fire index ff84f8f..66da3ac 100644 --- a/ListViewJsDemo/assets/Scene/helloworld.fire +++ b/ListViewJsDemo/assets/Scene/helloworld.fire @@ -3,7 +3,7 @@ "__type__": "cc.SceneAsset", "_name": "", "_objFlags": 0, - "_native": "", + "_rawFiles": null, "scene": { "__id__": 1 } @@ -17,10 +17,11 @@ "__id__": 2 } ], + "_tag": -1, "_active": true, - "_level": 0, "_components": [], "_prefab": null, + "_id": "2d2f792f-a40c-49bb-a189-ed176a246e49", "_opacity": 255, "_color": { "__type__": "cc.Color", @@ -29,33 +30,22 @@ "b": 255, "a": 255 }, - "_contentSize": { - "__type__": "cc.Size", - "width": 0, - "height": 0 - }, + "_cascadeOpacityEnabled": true, "_anchorPoint": { "__type__": "cc.Vec2", "x": 0, "y": 0 }, - "_scale": { - "__type__": "cc.Vec3", - "x": 0.3164691272424443, - "y": 0.3164691272424443, - "z": 1 + "_contentSize": { + "__type__": "cc.Size", + "width": 0, + "height": 0 }, - "_quat": { - "__type__": "cc.Quat", - "x": 0, - "y": 0, - "z": 0, - "w": 1 - }, - "_zIndex": 0, + "_localZOrder": 0, + "_globalZOrder": 0, + "_opacityModifyRGB": false, "groupIndex": 0, - "autoReleaseAssets": false, - "_id": "2d2f792f-a40c-49bb-a189-ed176a246e49" + "autoReleaseAssets": false }, { "__type__": "cc.Node", @@ -78,8 +68,8 @@ "__id__": 21 } ], + "_tag": -1, "_active": true, - "_level": 1, "_components": [ { "__id__": 23 @@ -89,6 +79,7 @@ } ], "_prefab": null, + "_id": "11wMPoqhJINqIuX6w96Z7P", "_opacity": 255, "_color": { "__type__": "cc.Color", @@ -97,42 +88,32 @@ "b": 255, "a": 255 }, - "_contentSize": { - "__type__": "cc.Size", - "width": 720, - "height": 1280 - }, + "_cascadeOpacityEnabled": true, "_anchorPoint": { "__type__": "cc.Vec2", "x": 0.5, "y": 0.5 }, - "_position": { - "__type__": "cc.Vec3", - "x": 360, - "y": 640, - "z": 0 - }, - "_scale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 + "_contentSize": { + "__type__": "cc.Size", + "width": 720, + "height": 1280 }, "_rotationX": 0, "_rotationY": 0, - "_quat": { - "__type__": "cc.Quat", - "x": 0, - "y": 0, - "z": 0, - "w": 1 + "_scaleX": 1, + "_scaleY": 1, + "_position": { + "__type__": "cc.Vec2", + "x": 360, + "y": 640 }, "_skewX": 0, "_skewY": 0, - "_zIndex": 0, - "groupIndex": 0, - "_id": "11wMPoqhJINqIuX6w96Z7P" + "_localZOrder": 0, + "_globalZOrder": 0, + "_opacityModifyRGB": false, + "groupIndex": 0 }, { "__type__": "cc.Node", @@ -142,14 +123,15 @@ "__id__": 2 }, "_children": [], + "_tag": -1, "_active": true, - "_level": 2, "_components": [ { "__id__": 4 } ], "_prefab": null, + "_id": "9da87m0elFIpzRq8FRD/e2", "_opacity": 255, "_color": { "__type__": "cc.Color", @@ -158,42 +140,32 @@ "b": 255, "a": 255 }, - "_contentSize": { - "__type__": "cc.Size", - "width": 0, - "height": 0 - }, + "_cascadeOpacityEnabled": true, "_anchorPoint": { "__type__": "cc.Vec2", "x": 0.5, "y": 0.5 }, - "_position": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - }, - "_scale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 + "_contentSize": { + "__type__": "cc.Size", + "width": 0, + "height": 0 }, "_rotationX": 0, "_rotationY": 0, - "_quat": { - "__type__": "cc.Quat", + "_scaleX": 1, + "_scaleY": 1, + "_position": { + "__type__": "cc.Vec2", "x": 0, - "y": 0, - "z": 0, - "w": 1 + "y": 0 }, "_skewX": 0, "_skewY": 0, - "_zIndex": 0, - "groupIndex": 0, - "_id": "9da87m0elFIpzRq8FRD/e2" + "_localZOrder": 0, + "_globalZOrder": 0, + "_opacityModifyRGB": false, + "groupIndex": 0 }, { "__type__": "cc.Camera", @@ -203,19 +175,8 @@ "__id__": 3 }, "_enabled": true, - "_cullingMask": 4294967295, - "_clearFlags": 7, - "_backgroundColor": { - "__type__": "cc.Color", - "r": 0, - "g": 0, - "b": 0, - "a": 255 - }, - "_depth": -1, - "_zoomRatio": 1, - "_targetTexture": null, - "_id": "99nUcrOqFDLLt3/3UDuE45" + "_targets": [], + "zoomRatio": 1 }, { "__type__": "cc.Node", @@ -225,8 +186,8 @@ "__id__": 2 }, "_children": [], + "_tag": -1, "_active": true, - "_level": 2, "_components": [ { "__id__": 6 @@ -236,6 +197,7 @@ } ], "_prefab": null, + "_id": "1aQ09HRqdARaEPgtSNfkss", "_opacity": 255, "_color": { "__type__": "cc.Color", @@ -244,42 +206,32 @@ "b": 114, "a": 255 }, - "_contentSize": { - "__type__": "cc.Size", - "width": 720, - "height": 1280 - }, + "_cascadeOpacityEnabled": true, "_anchorPoint": { "__type__": "cc.Vec2", "x": 0.5, "y": 0.5 }, - "_position": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - }, - "_scale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 + "_contentSize": { + "__type__": "cc.Size", + "width": 720, + "height": 1280 }, "_rotationX": 0, "_rotationY": 0, - "_quat": { - "__type__": "cc.Quat", + "_scaleX": 1, + "_scaleY": 1, + "_position": { + "__type__": "cc.Vec2", "x": 0, - "y": 0, - "z": 0, - "w": 1 + "y": 0 }, "_skewX": 0, "_skewY": 0, - "_zIndex": 0, - "groupIndex": 0, - "_id": "1aQ09HRqdARaEPgtSNfkss" + "_localZOrder": 0, + "_globalZOrder": 0, + "_opacityModifyRGB": false, + "groupIndex": 0 }, { "__type__": "cc.Sprite", @@ -289,8 +241,6 @@ "__id__": 5 }, "_enabled": true, - "_srcBlendFactor": 770, - "_dstBlendFactor": 771, "_spriteFrame": { "__uuid__": "a23235d1-15db-4b95-8439-a2e005bfff91" }, @@ -305,9 +255,9 @@ "_fillStart": 0, "_fillRange": 0, "_isTrimmedMode": true, - "_state": 0, - "_atlas": null, - "_id": "c5huKcZEBHGb1USJTTY8vL" + "_srcBlendFactor": 770, + "_dstBlendFactor": 771, + "_atlas": null }, { "__type__": "cc.Widget", @@ -317,7 +267,7 @@ "__id__": 5 }, "_enabled": true, - "alignMode": 1, + "isAlignOnce": true, "_target": null, "_alignFlags": 45, "_left": 0, @@ -333,8 +283,7 @@ "_isAbsHorizontalCenter": true, "_isAbsVerticalCenter": true, "_originalWidth": 100, - "_originalHeight": 100, - "_id": "33bkm/X/ZD64TH1CoTn+EC" + "_originalHeight": 100 }, { "__type__": "cc.Node", @@ -348,14 +297,15 @@ "__id__": 9 } ], + "_tag": -1, "_active": true, - "_level": 2, "_components": [ { "__id__": 20 } ], "_prefab": null, + "_id": "9c3kutx0dFaIOjULjZcGey", "_opacity": 255, "_color": { "__type__": "cc.Color", @@ -364,42 +314,32 @@ "b": 255, "a": 255 }, - "_contentSize": { - "__type__": "cc.Size", - "width": 0, - "height": 0 - }, + "_cascadeOpacityEnabled": true, "_anchorPoint": { "__type__": "cc.Vec2", "x": 0.5, "y": 0.5 }, - "_position": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - }, - "_scale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 + "_contentSize": { + "__type__": "cc.Size", + "width": 0, + "height": 0 }, "_rotationX": 0, "_rotationY": 0, - "_quat": { - "__type__": "cc.Quat", + "_scaleX": 1, + "_scaleY": 1, + "_position": { + "__type__": "cc.Vec2", "x": 0, - "y": 0, - "z": 0, - "w": 1 + "y": 0 }, "_skewX": 0, "_skewY": 0, - "_zIndex": 0, - "groupIndex": 0, - "_id": "9c3kutx0dFaIOjULjZcGey" + "_localZOrder": 0, + "_globalZOrder": 0, + "_opacityModifyRGB": false, + "groupIndex": 0 }, { "__type__": "cc.Node", @@ -416,14 +356,15 @@ "__id__": 13 } ], + "_tag": -1, "_active": true, - "_level": 3, "_components": [ { "__id__": 17 } ], "_prefab": null, + "_id": "7a1hs8UB9HO4+JV725mtgK", "_opacity": 255, "_color": { "__type__": "cc.Color", @@ -432,42 +373,32 @@ "b": 255, "a": 255 }, - "_contentSize": { - "__type__": "cc.Size", - "width": 500, - "height": 800 - }, + "_cascadeOpacityEnabled": true, "_anchorPoint": { "__type__": "cc.Vec2", "x": 0.5, "y": 0.5 }, - "_position": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - }, - "_scale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 + "_contentSize": { + "__type__": "cc.Size", + "width": 500, + "height": 800 }, "_rotationX": 0, "_rotationY": 0, - "_quat": { - "__type__": "cc.Quat", + "_scaleX": 1, + "_scaleY": 1, + "_position": { + "__type__": "cc.Vec2", "x": 0, - "y": 0, - "z": 0, - "w": 1 + "y": 0 }, "_skewX": 0, "_skewY": 0, - "_zIndex": 0, - "groupIndex": 0, - "_id": "7a1hs8UB9HO4+JV725mtgK" + "_localZOrder": 0, + "_globalZOrder": 0, + "_opacityModifyRGB": false, + "groupIndex": 0 }, { "__type__": "cc.Node", @@ -481,14 +412,15 @@ "__id__": 11 } ], + "_tag": -1, "_active": true, - "_level": 0, "_components": [ { "__id__": 12 } ], "_prefab": null, + "_id": "89DW7M+MBCar0ymvPGQdgg", "_opacity": 255, "_color": { "__type__": "cc.Color", @@ -497,42 +429,32 @@ "b": 255, "a": 255 }, - "_contentSize": { - "__type__": "cc.Size", - "width": 500, - "height": 800 - }, + "_cascadeOpacityEnabled": true, "_anchorPoint": { "__type__": "cc.Vec2", "x": 0.5, "y": 0.5 }, - "_position": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - }, - "_scale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 + "_contentSize": { + "__type__": "cc.Size", + "width": 500, + "height": 800 }, "_rotationX": 0, "_rotationY": 0, - "_quat": { - "__type__": "cc.Quat", + "_scaleX": 1, + "_scaleY": 1, + "_position": { + "__type__": "cc.Vec2", "x": 0, - "y": 0, - "z": 0, - "w": 1 + "y": 0 }, "_skewX": 0, "_skewY": 0, - "_zIndex": 0, - "groupIndex": 0, - "_id": "89DW7M+MBCar0ymvPGQdgg" + "_localZOrder": 0, + "_globalZOrder": 0, + "_opacityModifyRGB": false, + "groupIndex": 0 }, { "__type__": "cc.Node", @@ -542,10 +464,11 @@ "__id__": 10 }, "_children": [], + "_tag": -1, "_active": true, - "_level": 0, "_components": [], "_prefab": null, + "_id": "aazVaMb4tK4IQxSXbVsMnM", "_opacity": 255, "_color": { "__type__": "cc.Color", @@ -554,42 +477,32 @@ "b": 255, "a": 255 }, - "_contentSize": { - "__type__": "cc.Size", - "width": 500, - "height": 800 - }, + "_cascadeOpacityEnabled": true, "_anchorPoint": { "__type__": "cc.Vec2", "x": 0.5, "y": 1 }, - "_position": { - "__type__": "cc.Vec3", - "x": 0, - "y": 398, - "z": 0 - }, - "_scale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 + "_contentSize": { + "__type__": "cc.Size", + "width": 500, + "height": 800 }, "_rotationX": 0, "_rotationY": 0, - "_quat": { - "__type__": "cc.Quat", + "_scaleX": 1, + "_scaleY": 1, + "_position": { + "__type__": "cc.Vec2", "x": 0, - "y": 0, - "z": 0, - "w": 1 + "y": 398 }, "_skewX": 0, "_skewY": 0, - "_zIndex": 0, - "groupIndex": 0, - "_id": "aazVaMb4tK4IQxSXbVsMnM" + "_localZOrder": 0, + "_globalZOrder": 0, + "_opacityModifyRGB": false, + "groupIndex": 0 }, { "__type__": "cc.Mask", @@ -599,14 +512,11 @@ "__id__": 10 }, "_enabled": true, - "_srcBlendFactor": 770, - "_dstBlendFactor": 771, - "_spriteFrame": null, "_type": 0, - "_segments": 64, + "_segements": 64, + "_N$spriteFrame": null, "_N$alphaThreshold": 0, - "_N$inverted": false, - "_id": "28Yg8DM9hCpqDlBsyEejXu" + "_N$inverted": false }, { "__type__": "cc.Node", @@ -620,8 +530,8 @@ "__id__": 14 } ], + "_tag": -1, "_active": true, - "_level": 0, "_components": [ { "__id__": 16 @@ -634,6 +544,7 @@ } ], "_prefab": null, + "_id": "eaO+bWvW1KT6NJXHppda3/", "_opacity": 255, "_color": { "__type__": "cc.Color", @@ -642,42 +553,32 @@ "b": 255, "a": 255 }, - "_contentSize": { - "__type__": "cc.Size", - "width": 12, - "height": 800 - }, + "_cascadeOpacityEnabled": true, "_anchorPoint": { "__type__": "cc.Vec2", "x": 1, "y": 0.5 }, - "_position": { - "__type__": "cc.Vec3", - "x": 250, - "y": 0, - "z": 0 - }, - "_scale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 + "_contentSize": { + "__type__": "cc.Size", + "width": 12, + "height": 800 }, "_rotationX": 0, "_rotationY": 0, - "_quat": { - "__type__": "cc.Quat", - "x": 0, - "y": 0, - "z": 0, - "w": 1 + "_scaleX": 1, + "_scaleY": 1, + "_position": { + "__type__": "cc.Vec2", + "x": 250, + "y": 0 }, "_skewX": 0, "_skewY": 0, - "_zIndex": 0, - "groupIndex": 0, - "_id": "eaO+bWvW1KT6NJXHppda3/" + "_localZOrder": 0, + "_globalZOrder": 0, + "_opacityModifyRGB": false, + "groupIndex": 0 }, { "__type__": "cc.Node", @@ -687,14 +588,15 @@ "__id__": 13 }, "_children": [], + "_tag": -1, "_active": true, - "_level": 0, "_components": [ { "__id__": 15 } ], "_prefab": null, + "_id": "a4lj1XN7FDephodOieJShJ", "_opacity": 255, "_color": { "__type__": "cc.Color", @@ -703,42 +605,32 @@ "b": 255, "a": 255 }, - "_contentSize": { - "__type__": "cc.Size", - "width": 10, - "height": 30 - }, + "_cascadeOpacityEnabled": true, "_anchorPoint": { "__type__": "cc.Vec2", "x": 1, "y": 0 }, - "_position": { - "__type__": "cc.Vec3", - "x": -1, - "y": 0, - "z": 0 - }, - "_scale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 + "_contentSize": { + "__type__": "cc.Size", + "width": 10, + "height": 30 }, "_rotationX": 0, "_rotationY": 0, - "_quat": { - "__type__": "cc.Quat", - "x": 0, - "y": 0, - "z": 0, - "w": 1 + "_scaleX": 1, + "_scaleY": 1, + "_position": { + "__type__": "cc.Vec2", + "x": -1, + "y": 0 }, "_skewX": 0, "_skewY": 0, - "_zIndex": 0, - "groupIndex": 0, - "_id": "a4lj1XN7FDephodOieJShJ" + "_localZOrder": 0, + "_globalZOrder": 0, + "_opacityModifyRGB": false, + "groupIndex": 0 }, { "__type__": "cc.Sprite", @@ -748,8 +640,6 @@ "__id__": 14 }, "_enabled": true, - "_srcBlendFactor": 770, - "_dstBlendFactor": 771, "_spriteFrame": { "__uuid__": "5c3bb932-6c3c-468f-88a9-c8c61d458641" }, @@ -764,9 +654,9 @@ "_fillStart": 0, "_fillRange": 0, "_isTrimmedMode": true, - "_state": 0, - "_atlas": null, - "_id": "37yw60+ydMvIlEzBZ5L3L4" + "_srcBlendFactor": 770, + "_dstBlendFactor": 771, + "_atlas": null }, { "__type__": "cc.Scrollbar", @@ -786,8 +676,7 @@ "_N$handle": { "__id__": 15 }, - "_N$direction": 1, - "_id": "fdHfFqM3NEDIr2mK6pftGH" + "_N$direction": 1 }, { "__type__": "cc.ScrollView", @@ -811,8 +700,7 @@ "_N$horizontalScrollBar": null, "_N$verticalScrollBar": { "__id__": 16 - }, - "_id": "dfObPP8ohILYQjp0mbgF+D" + } }, { "__type__": "cc.Widget", @@ -822,7 +710,7 @@ "__id__": 13 }, "_enabled": true, - "alignMode": 0, + "isAlignOnce": true, "_target": null, "_alignFlags": 37, "_left": 350.07654921020657, @@ -838,8 +726,7 @@ "_isAbsHorizontalCenter": true, "_isAbsVerticalCenter": true, "_originalWidth": 0, - "_originalHeight": 237, - "_id": "b8HWMem/NGAKzrMuNRyoow" + "_originalHeight": 237 }, { "__type__": "cc.Sprite", @@ -849,8 +736,6 @@ "__id__": 13 }, "_enabled": true, - "_srcBlendFactor": 770, - "_dstBlendFactor": 771, "_spriteFrame": { "__uuid__": "5fe5dcaa-b513-4dc5-a166-573627b3a159" }, @@ -865,12 +750,12 @@ "_fillStart": 0, "_fillRange": 0, "_isTrimmedMode": true, - "_state": 0, - "_atlas": null, - "_id": "46RIP8i/VPM60/5c2q88Z/" + "_srcBlendFactor": 770, + "_dstBlendFactor": 771, + "_atlas": null }, { - "__type__": "8a20blSjf1FOKuo0wzCpV8A", + "__type__": "2a51dYQx7hLjKNhfL6VU6y5", "_name": "", "_objFlags": 0, "node": { @@ -880,12 +765,11 @@ "itemTemplate": { "__uuid__": "ee8a03a3-1f23-464b-abf1-1800df851e7e" }, - "spacing": 5, + "spacing": 1, "spawnCount": 2, "scrollView": { "__id__": 17 - }, - "_id": "20p8iQiRVBZr5epcRxWS/B" + } }, { "__type__": "cc.Node", @@ -895,14 +779,15 @@ "__id__": 2 }, "_children": [], + "_tag": -1, "_active": true, - "_level": 2, "_components": [ { "__id__": 22 } ], "_prefab": null, + "_id": "240Yj3vf1Ct4NUbczT47fQ", "_opacity": 255, "_color": { "__type__": "cc.Color", @@ -911,42 +796,32 @@ "b": 255, "a": 255 }, - "_contentSize": { - "__type__": "cc.Size", - "width": 0, - "height": 40 - }, + "_cascadeOpacityEnabled": true, "_anchorPoint": { "__type__": "cc.Vec2", "x": 0.5, "y": 0.5 }, - "_position": { - "__type__": "cc.Vec3", - "x": 0, - "y": -509, - "z": 0 - }, - "_scale": { - "__type__": "cc.Vec3", - "x": 1, - "y": 1, - "z": 1 + "_contentSize": { + "__type__": "cc.Size", + "width": 0, + "height": 40 }, "_rotationX": 0, "_rotationY": 0, - "_quat": { - "__type__": "cc.Quat", + "_scaleX": 1, + "_scaleY": 1, + "_position": { + "__type__": "cc.Vec2", "x": 0, - "y": 0, - "z": 0, - "w": 1 + "y": -509 }, "_skewX": 0, "_skewY": 0, - "_zIndex": 0, - "groupIndex": 0, - "_id": "240Yj3vf1Ct4NUbczT47fQ" + "_localZOrder": 0, + "_globalZOrder": 0, + "_opacityModifyRGB": false, + "groupIndex": 0 }, { "__type__": "cc.Label", @@ -956,22 +831,19 @@ "__id__": 21 }, "_enabled": true, - "_srcBlendFactor": 1, - "_dstBlendFactor": 771, "_useOriginalSize": false, - "_string": "", - "_N$string": "", + "_actualFontSize": 40, "_fontSize": 40, "_lineHeight": 40, "_enableWrapText": true, "_N$file": null, "_isSystemFontUsed": true, "_spacingX": 0, + "_N$string": "", "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", - "_N$overflow": 0, - "_id": "c0Y+AeoWtL3Jk9N1qw9neE" + "_N$overflow": 0 }, { "__type__": "cc.Canvas", @@ -987,8 +859,7 @@ "height": 1280 }, "_fitWidth": false, - "_fitHeight": true, - "_id": "becpQMleZK37N3DzbrU7bD" + "_fitHeight": true }, { "__type__": "280c3rsZJJKnZ9RqbALVwtK", @@ -1003,7 +874,6 @@ }, "tipLabel": { "__id__": 22 - }, - "_id": "f98aT2FEZJ76PlU13vSybi" + } } ] \ No newline at end of file diff --git a/ListViewJsDemo/assets/Script/HelloWorld.js b/ListViewJsDemo/assets/Script/HelloWorld.js index 723e2cd..7e4914b 100644 --- a/ListViewJsDemo/assets/Script/HelloWorld.js +++ b/ListViewJsDemo/assets/Script/HelloWorld.js @@ -1,6 +1,5 @@ -import ListView, {AbsAdapter} from "./ListView"; - -const ListAdapter = require('./ListAdapter'); +const ListView = require('ListView'); +const ListAdapter = require('ListAdapter'); cc.Class({ extends: cc.Component, diff --git a/ListViewJsDemo/assets/Script/ListAdapter.js b/ListViewJsDemo/assets/Script/ListAdapter.js index da680c5..3066334 100644 --- a/ListViewJsDemo/assets/Script/ListAdapter.js +++ b/ListViewJsDemo/assets/Script/ListAdapter.js @@ -1,13 +1,39 @@ -import {AbsAdapter} from "./ListView"; -const ListItem = require('./ListItem'); - -cc.Class({ - extends: AbsAdapter, - updateView(item, posIndex) { - let comp = item.getComponent(ListItem); - if (comp) { - comp.setData(this.getItem(posIndex)); - } +class AbsAdapter { + constructor() { + this.dataSet = []; + this.componentName = ''; } -}) \ No newline at end of file + + /** + * + * @param {*} data 数据 + * @param {*} componentName item的脚本名 + */ + setDataSet(data = [], componentName) { + this.dataSet = data; + this.componentName = componentName; + } + + getCount() { + return this.dataSet.length; + } + + getItem(posIndex) { + return this.dataSet[posIndex]; + } + + _getView(item, posIndex) { + this.updateView(item, posIndex); + return item; + } + + updateView(item, posIndex) { + let comp = item.getComponent(this.componentName); + if (comp) { + comp.setData(this.getItem(posIndex)); + } + } + } + + module.exports = AbsAdapter; \ No newline at end of file diff --git a/ListViewJsDemo/assets/Script/ListAdapter.js.meta b/ListViewJsDemo/assets/Script/ListAdapter.js.meta index 5b1f58d..b1030d1 100644 --- a/ListViewJsDemo/assets/Script/ListAdapter.js.meta +++ b/ListViewJsDemo/assets/Script/ListAdapter.js.meta @@ -1,6 +1,6 @@ { "ver": "1.0.5", - "uuid": "9ec2acad-d240-4e35-9106-069a09c2f73d", + "uuid": "1bb1a322-40fe-41bd-b935-8b7979d1974a", "isPlugin": false, "loadPluginInWeb": true, "loadPluginInNative": true, diff --git a/ListViewJsDemo/assets/Script/ListView.js b/ListViewJsDemo/assets/Script/ListView.js new file mode 100644 index 0000000..75837cc --- /dev/null +++ b/ListViewJsDemo/assets/Script/ListView.js @@ -0,0 +1,304 @@ +cc.Class({ + extends: cc.Component, + + properties: { + itemTemplate: cc.Prefab, + spacing: 1, + spawnCount: 2, + scrollView: cc.ScrollView, + }, + + initProperties() { + this.content = null; + this.adapter = null; + this._items = new cc.NodePool(); + // 记录当前填充在树上的索引. 用来快速查找哪些位置缺少item了. + this._filledIds = {}; + this.horizontal = false; + // 初始时即计算item的高度.因为布局时要用到. + this._itemHeight = 1; + this._itemWidth = 1; + this._itemsVisible = 1; + this.lastStartIndex = -1; + this.scrollTopNotifyed = false; + this.scrollBottomNotifyed = false; + this.pullDownCallback = () => {}; + this.pullUpCallback = () => {}; + }, + + onLoad() { + this.registerEvent(); + this.init(); + }, + + registerEvent() { + + }, + + init(data) { + this.initProperties(); + if (this.scrollView) { + this.content = this.scrollView.content; + this.horizontal = this.scrollView.horizontal; + if (this.horizontal) { + this.scrollView.vertical = false; + this.content.anchorX = 0; + this.content.x = this.content.parent.width * this.content.parent.anchorX; + } else { + this.scrollView.vertical = true; + this.content.anchorY = 1; + this.content.y = this.content.parent.height * this.content.parent.anchorY; + } + } else { + console.error('ListView need a scrollView for showing.'); + } + let itemOne = this._items.get() || cc.instantiate(this.itemTemplate); + this._items.put(itemOne); + this._itemHeight = itemOne.height || 10; + this._itemWidth = itemOne.width || 10; + + if (this.horizontal) { + this._itemsVisible = Math.ceil(this.content.parent.width / this._itemWidth); + } else { + this._itemsVisible = Math.ceil(this.content.parent.height / this._itemHeight); + } + console.log('可见区域的item数量为:', this._itemsVisible); + this.adjustEvent(); + }, + + setAdapter(adapter) { + this.adapter = adapter; + if (this.adapter == null) { + console.warn('adapter 为空.'); + return; + } + if (this.itemTemplate == null) { + console.error('Listview 未设置待显示的Item模板.'); + return; + } + this.clearState(); + this.notifyUpdate(); + }, + + clearState() { + this.content.removeAllChildren(); + this.scrollTopNotifyed = false; + this.scrollBottomNotifyed = false; + }, + + getItemIndex(height) { + return Math.floor(Math.abs(height / ((this._itemHeight + this.spacing)))); + }, + + getPositionInView(item) { + let worldPos = item.parent.convertToWorldSpaceAR(item.position); + let viewPos = this.scrollView.node.convertToNodeSpaceAR(worldPos); + return viewPos; + }, + + // 数据变更了需要进行更新UI显示, 可只更新某一条. + notifyUpdate(updateIndex) { + if (this.adapter == null) { + return; + } + if (updateIndex && updateIndex.length > 0) { + updateIndex.forEach(i => { + if (this._filledIds.hasOwnProperty(i)) { + delete this._filledIds[i]; + } + }); + } else { + Object.keys(this._filledIds).forEach(key => { + delete this._filledIds[key]; + }); + } + this.lastStartIndex = -1; + if (this.horizontal) { + this.content.width = this.adapter.getCount() * (this._itemWidth + this.spacing) + this.spacing; + } else { + this.content.height = this.adapter.getCount() * (this._itemHeight + this.spacing) + this.spacing; // get total content height + } + // this.content.removeAllChildren(); + + this.scrollView.scrollToTop(); + }, + scrollToTop(anim = false) { + this.scrollView.scrollToTop(anim ? 1 : 0); + }, + + scrollToBottom(anim = false) { + this.scrollView.scrollToBottom(anim ? 1 : 0); + }, + + scrollToLeft(anim = false) { + this.scrollView.scrollToLeft(anim ? 1 : 0); + }, + + scrollToRight(anim = false) { + this.scrollView.scrollToRight(anim ? 1 : 0); + }, + + // 下拉事件. + pullDown(callback, this$) { + this.pullDownCallback = callback.bind(this$); + }, + + // 上拉事件. + pullUp(callback, this$) { + this.pullUpCallback = callback.bind(this$); + }, + + update(dt) { + const startIndex = this.checkNeedUpdate(); + // console.log('startIdx=', startIndex); + if (startIndex >= 0) { + this.updateView(startIndex); + } + }, + + // 向某位置添加一个item. + _layoutVertical(child, posIndex) { + this.content.addChild(child); + // 增加一个tag 属性用来存储child的位置索引. + child['_tag'] = posIndex; + this._filledIds[posIndex] = posIndex; + child.setPosition(0, -child.height * (0.5 + posIndex) - this.spacing * (posIndex + 1)); + }, + + // 向某位置添加一个item. + _layoutHorizontal(child, posIndex) { + this.content.addChild(child); + // 增加一个tag 属性用来存储child的位置索引. + child['_tag'] = posIndex; + this._filledIds[posIndex] = posIndex; + child.setPosition(-child.width * (0.5 + posIndex) - this.spacing * (posIndex + 1), 0); + }, + + // 获取可回收item + getRecycleItems(beginIndex, endIndex) { + const children = this.content.children; + const recycles = []; + children.forEach(item => { + if (item['_tag'] < beginIndex || item['_tag'] > endIndex) { + recycles.push(item); + delete this._filledIds[item['_tag']]; + } + }); + return recycles; + }, + + // 填充View. + updateView(startIndex) { + let itemStartIndex = startIndex; + // 比实际元素多3个. + let itemEndIndex = itemStartIndex + this._itemsVisible + (this.spawnCount || 2); + const totalCount = this.adapter.getCount(); + if (itemStartIndex >= totalCount) { + return; + } + + if (itemEndIndex > totalCount) { + itemEndIndex = totalCount; + if (!this.scrollBottomNotifyed) { + this.notifyScrollToBottom(); + this.scrollBottomNotifyed = true; + } + } else { + this.scrollBottomNotifyed = false; + } + + // 回收需要回收的元素位置.向上少收一个.向下少收2两. + const recyles = this.getRecycleItems(itemStartIndex - (this.spawnCount || 2), itemEndIndex); + recyles.forEach(item => { + this._items.put(item); + }); + + // 查找需要更新的元素位置. + const updates = this.findUpdateIndex(itemStartIndex, itemEndIndex); + + // 更新相应位置. + for (let index of updates) { + let child = this.adapter._getView(this._items.get() || cc.instantiate(this.itemTemplate), index); + this.horizontal ? + this._layoutHorizontal(child, index) : + this._layoutVertical(child, index); + } + }, + + // 检测是否需要更新UI. + checkNeedUpdate() { + if (this.adapter == null) { + return -1; + } + + let scroll = this.horizontal ? (this.content.x - this.content.parent.width * this.content.parent.anchorX) : + (this.content.y - this.content.parent.height * this.content.parent.anchorY); + if (scroll < 0) { //为负有bug + scroll = 0; + } + let itemStartIndex = Math.floor(scroll / ((this.horizontal ? this._itemWidth : this._itemHeight) + this.spacing)); + if (itemStartIndex < 0 && !this.scrollTopNotifyed) { + this.notifyScrollToTop(); + this.scrollTopNotifyed = true; + return itemStartIndex; + } + // 防止重复触发topNotify.仅当首item不可见后才能再次触发 + if (itemStartIndex > 0) { + this.scrollTopNotifyed = false; + } + + if (this.lastStartIndex != itemStartIndex) { + this.lastStartIndex = itemStartIndex; + return itemStartIndex; + } + + return -1; + }, + + // 查找需要补充的元素索引. + findUpdateIndex(itemStartIndex, itemEndIndex) { + const d = []; + for (let i = itemStartIndex; i < itemEndIndex; i++) { + if (this._filledIds.hasOwnProperty(i)) { + continue; + } + d.push(i); + } + return d; + }, + + notifyScrollToTop() { + if (!this.adapter || this.adapter.getCount() <= 0) { + return; + } + if (this.pullDownCallback) { + this.pullDownCallback(); + } + }, + + notifyScrollToBottom() { + if (!this.adapter || this.adapter.getCount() <= 0) { + return; + } + if (this.pullUpCallback) { + this.pullUpCallback(); + } + }, + + adjustEvent() { + this.content.on(this.isMobile() ? cc.Node.EventType.TOUCH_END : cc.Node.EventType.MOUSE_UP, () => { + this.scrollTopNotifyed = false; + this.scrollBottomNotifyed = false; + }, this); + this.content.on(this.isMobile() ? cc.Node.EventType.TOUCH_CANCEL : cc.Node.EventType.MOUSE_LEAVE, () => { + this.scrollTopNotifyed = false; + this.scrollBottomNotifyed = false; + }, this); + }, + + isMobile() { + return (cc.sys.isMobile || cc.sys.platform === cc.sys.WECHAT_GAME || cc.sys.platform === cc.sys.QQ_PLAY); + }, + + onDestroy() {} +}); \ No newline at end of file diff --git a/ListViewJsDemo/assets/Script/ListView.ts.meta b/ListViewJsDemo/assets/Script/ListView.js.meta similarity index 74% rename from ListViewJsDemo/assets/Script/ListView.ts.meta rename to ListViewJsDemo/assets/Script/ListView.js.meta index 3bdbb3d..cb56fed 100644 --- a/ListViewJsDemo/assets/Script/ListView.ts.meta +++ b/ListViewJsDemo/assets/Script/ListView.js.meta @@ -1,6 +1,6 @@ { "ver": "1.0.5", - "uuid": "8a20b952-8dfd-4538-aba8-d30cc2a55f00", + "uuid": "2a51d610-c7b8-4b8c-a361-7cbe9553acb9", "isPlugin": false, "loadPluginInWeb": true, "loadPluginInNative": true, diff --git a/ListViewJsDemo/assets/Script/ListView.ts b/ListViewJsDemo/assets/Script/ListView.ts deleted file mode 100644 index f106924..0000000 --- a/ListViewJsDemo/assets/Script/ListView.ts +++ /dev/null @@ -1,321 +0,0 @@ -const {ccclass, property} = cc._decorator; - -@ccclass -export default class ListView extends cc.Component { - - @property(cc.Prefab) - private itemTemplate: cc.Prefab = null; - - @property - private spacing: number = 1; - - // 比可见元素多缓存3个, 缓存越多,快速滑动越流畅,但同时初始化越慢. - @property - private spawnCount: number = 2; - - @property(cc.ScrollView) - private scrollView: cc.ScrollView = null; - - private content: cc.Node = null; - - private adapter: AbsAdapter = null; - - private readonly _items: cc.NodePool = new cc.NodePool(); - // 记录当前填充在树上的索引. 用来快速查找哪些位置缺少item了. - private readonly _filledIds: { [key: number]: number } = {}; - - private horizontal: boolean = false; - - // 初始时即计算item的高度.因为布局时要用到. - private _itemHeight: number = 1; - - private _itemWidth: number = 1; - - private _itemsVisible: number = 1; - - private lastStartIndex: number = -1; - - private scrollTopNotifyed: boolean = false; - private scrollBottomNotifyed: boolean = false; - - private pullDownCallback: () => void = null; - private pullUpCallback: () => void = null; - - public onLoad() { - if (this.scrollView) { - this.content = this.scrollView.content; - this.horizontal = this.scrollView.horizontal; - if (this.horizontal) { - this.scrollView.vertical = false - this.content.anchorX = 0; - this.content.x = this.content.parent.width * this.content.parent.anchorX; - } else { - this.scrollView.vertical = true; - this.content.anchorY = 1; - this.content.y = this.content.parent.height * this.content.parent.anchorY; - } - } else { - console.error("ListView need a scrollView for showing.") - } - let itemOne = this._items.get() || cc.instantiate(this.itemTemplate); - this._items.put(itemOne); - this._itemHeight = itemOne.height || 10; - this._itemWidth = itemOne.width || 10; - - if (this.horizontal) { - this._itemsVisible = Math.ceil(this.content.parent.width / this._itemWidth); - } else { - this._itemsVisible = Math.ceil(this.content.parent.height / this._itemHeight); - } - console.log("可见区域的item数量为:", this._itemsVisible); - this.adjustEvent(); - } - - public async setAdapter(adapter: AbsAdapter) { - this.adapter = adapter; - if (this.adapter == null) { - console.warn("adapter 为空.") - return - } - if (this.itemTemplate == null) { - console.error("Listview 未设置待显示的Item模板."); - return; - } - - this.notifyUpdate(); - } - - public getItemIndex(height: number): number { - return Math.floor(Math.abs(height / ((this._itemHeight + this.spacing)))); - } - - public getPositionInView(item: cc.Node) { - let worldPos = item.parent.convertToWorldSpaceAR(item.position); - let viewPos = this.scrollView.node.convertToNodeSpaceAR(worldPos); - return viewPos; - } - - // 数据变更了需要进行更新UI显示, 可只更新某一条. - public notifyUpdate(updateIndex?: number[]) { - if (this.adapter == null) { - return; - } - if (updateIndex && updateIndex.length > 0) { - updateIndex.forEach(i => { - if (this._filledIds.hasOwnProperty(i)) { - delete this._filledIds[i]; - } - }) - } else { - Object.keys(this._filledIds).forEach(key => { - delete this._filledIds[key]; - }) - } - this.lastStartIndex = -1; - if (this.horizontal) { - this.content.width = this.adapter.getCount() * (this._itemWidth + this.spacing) + this.spacing; - } else { - this.content.height = this.adapter.getCount() * (this._itemHeight + this.spacing) + this.spacing; // get total content height - } - this.scrollView.scrollToTop() - } - - public scrollToTop(anim: boolean = false) { - this.scrollView.scrollToTop(anim ? 1 : 0); - } - - public scrollToBottom(anim: boolean = false) { - this.scrollView.scrollToBottom(anim ? 1 : 0); - } - - public scrollToLeft(anim: boolean = false) { - this.scrollView.scrollToLeft(anim ? 1 : 0); - } - - public scrollToRight(anim: boolean = false) { - this.scrollView.scrollToRight(anim ? 1 : 0); - } - - // 下拉事件. - public pullDown(callback: () => void, this$: any) { - this.pullDownCallback = callback.bind(this$); - } - - // 上拉事件. - public pullUp(callback: () => void, this$: any) { - this.pullUpCallback = callback.bind(this$); - } - - protected update(dt) { - const startIndex = this.checkNeedUpdate(); - if (startIndex >= 0) { - this.updateView(startIndex); - } - } - - // 向某位置添加一个item. - private _layoutVertical(child: cc.Node, posIndex: number) { - this.content.addChild(child); - // 增加一个tag 属性用来存储child的位置索引. - child["_tag"] = posIndex; - this._filledIds[posIndex] = posIndex; - child.setPosition(0, -child.height * (0.5 + posIndex) - this.spacing * (posIndex + 1)); - } - - // 向某位置添加一个item. - private _layoutHorizontal(child: cc.Node, posIndex: number) { - this.content.addChild(child); - // 增加一个tag 属性用来存储child的位置索引. - child["_tag"] = posIndex; - this._filledIds[posIndex] = posIndex; - child.setPosition(-child.width * (0.5 + posIndex) - this.spacing * (posIndex + 1), 0); - } - - // 获取可回收item - private getRecycleItems(beginIndex: number, endIndex: number): cc.Node[] { - const children = this.content.children; - const recycles = [] - children.forEach(item => { - if (item["_tag"] < beginIndex || item["_tag"] > endIndex) { - recycles.push(item); - delete this._filledIds[item["_tag"]]; - } - }) - return recycles; - } - - // 填充View. - private updateView(startIndex) { - let itemStartIndex = startIndex; - // 比实际元素多3个. - let itemEndIndex = itemStartIndex + this._itemsVisible + (this.spawnCount || 2); - const totalCount = this.adapter.getCount(); - if (itemStartIndex >= totalCount) { - return; - } - - if (itemEndIndex > totalCount) { - itemEndIndex = totalCount; - if (!this.scrollBottomNotifyed) { - this.notifyScrollToBottom() - this.scrollBottomNotifyed = true; - } - } else { - this.scrollBottomNotifyed = false; - } - - // 回收需要回收的元素位置.向上少收一个.向下少收2两. - const recyles = this.getRecycleItems(itemStartIndex - (this.spawnCount || 2), itemEndIndex); - recyles.forEach(item => { - this._items.put(item); - }) - - // 查找需要更新的元素位置. - const updates = this.findUpdateIndex(itemStartIndex, itemEndIndex) - - // 更新相应位置. - for (let index of updates) { - let child = this.adapter._getView(this._items.get() || cc.instantiate(this.itemTemplate), index); - this.horizontal ? - this._layoutHorizontal(child, index) : - this._layoutVertical(child, index); - } - } - - // 检测是否需要更新UI. - private checkNeedUpdate(): number { - if (this.adapter == null) { - return -1 - } - - let scroll = this.horizontal ? (this.content.x - this.content.parent.width * this.content.parent.anchorX) - : (this.content.y - this.content.parent.height * this.content.parent.anchorY); - let itemStartIndex = Math.floor(scroll / ((this.horizontal ? this._itemWidth : this._itemHeight) + this.spacing)); - if (itemStartIndex < 0 && !this.scrollTopNotifyed) { - this.notifyScrollToTop(); - this.scrollTopNotifyed = true; - return itemStartIndex; - } - // 防止重复触发topNotify.仅当首item不可见后才能再次触发 - if (itemStartIndex > 0) { - this.scrollTopNotifyed = false; - } - - if (this.lastStartIndex != itemStartIndex) { - this.lastStartIndex = itemStartIndex; - return itemStartIndex; - } - - return -1; - } - - // 查找需要补充的元素索引. - private findUpdateIndex(itemStartIndex: number, itemEndIndex: number): number[] { - const d = []; - for (let i = itemStartIndex; i < itemEndIndex; i++) { - if (this._filledIds.hasOwnProperty(i)) { - continue; - } - d.push(i); - } - return d; - } - - private notifyScrollToTop() { - if (!this.adapter || this.adapter.getCount() <= 0) { - return; - } - if (this.pullDownCallback) { - this.pullDownCallback(); - } - } - - private notifyScrollToBottom() { - if (!this.adapter || this.adapter.getCount() <= 0) { - return; - } - if (this.pullUpCallback) { - this.pullUpCallback(); - } - } - - private adjustEvent() { - this.content.on(this.isMobile() ? cc.Node.EventType.TOUCH_END : cc.Node.EventType.MOUSE_UP, () => { - this.scrollTopNotifyed = false; - this.scrollBottomNotifyed = false; - }, this) - this.content.on(this.isMobile() ? cc.Node.EventType.TOUCH_CANCEL : cc.Node.EventType.MOUSE_LEAVE, () => { - this.scrollTopNotifyed = false; - this.scrollBottomNotifyed = false; - }, this); - } - - private isMobile(): boolean { - return (cc.sys.isMobile || cc.sys.platform === cc.sys.WECHAT_GAME || cc.sys.platform === cc.sys.QQ_PLAY) - } -} - -// 数据绑定的辅助适配器 -export abstract class AbsAdapter { - - private dataSet: any[] = []; - - public setDataSet(data: any[]) { - this.dataSet = data; - } - - public getCount(): number { - return this.dataSet.length; - } - - public getItem(posIndex: number): any { - return this.dataSet[posIndex]; - } - - public _getView(item: cc.Node, posIndex: number): cc.Node { - this.updateView(item, posIndex); - return item; - } - - public abstract updateView(item: cc.Node, posIndex: number); -} \ No newline at end of file diff --git a/ListViewJsDemo/assets/Texture/HelloWorld.png.meta b/ListViewJsDemo/assets/Texture/HelloWorld.png.meta index efdbc77..9c52a59 100644 --- a/ListViewJsDemo/assets/Texture/HelloWorld.png.meta +++ b/ListViewJsDemo/assets/Texture/HelloWorld.png.meta @@ -1,10 +1,9 @@ { - "ver": "2.2.0", + "ver": "1.0.0", "uuid": "6aa0aa6a-ebee-4155-a088-a687a6aadec4", "type": "sprite", "wrapMode": "clamp", "filterMode": "bilinear", - "premultiplyAlpha": false, "subMetas": { "HelloWorld": { "ver": "1.0.3", diff --git a/ListViewJsDemo/assets/Texture/singleColor.png.meta b/ListViewJsDemo/assets/Texture/singleColor.png.meta index e3a0a2b..89cdf74 100644 --- a/ListViewJsDemo/assets/Texture/singleColor.png.meta +++ b/ListViewJsDemo/assets/Texture/singleColor.png.meta @@ -1,10 +1,9 @@ { - "ver": "2.2.0", + "ver": "1.0.0", "uuid": "a8027877-d8d6-4645-97a0-52d4a0123dba", "type": "sprite", "wrapMode": "clamp", "filterMode": "bilinear", - "premultiplyAlpha": false, "subMetas": { "singleColor": { "ver": "1.0.3",