cx-cocos/cx3-demo/assets/script/page/pageScrollView.ts
2021-06-07 15:13:32 +08:00

64 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {_decorator, Component, Node, Label, color} from 'cc';
const {ccclass} = _decorator;
@ccclass('pageScrollView')
class pageScrollView extends Component
{
dataCount: number = 0;
isRefresh: boolean = false;
start ()
{
cx.gn(this, "spClose").setTouchCallback(this, cx.closePage);
cx.script.scrollView.initDeltaInsert(this, "view", this.queryData); //设置增量新增数据到view的能力
cx.script.scrollView.initDropRefresh(this, "view", this.refreshData); //设置下拉刷新能力
this.queryData();
}
refreshData ()
{
this.dataCount = 0;
this.isRefresh = true;
this.queryData();
}
queryData ()
{
//模拟从服务器取数据0.5秒后获得数据
cx.log("queryData " + this.dataCount);
this.scheduleOnce(this.queryDataOk, 0.5);
}
queryDataOk ()
{
cx.log("queryDataOk...");
if (this.isRefresh)
{
this.isRefresh = false;
cx.gn(this, "content").removeAllChildren();
}
for (var i = 0; i < 20; i++)
this.createPanel();
cx.script.scrollView.overDeltaInsert(this, this.dataCount > 200); //结束新增能力模拟总数量200个
cx.script.scrollView.overDropRefresh(this); //结束本次下拉刷新
}
createPanel ()
{
var node = new Node();
node.addComponent(Label).string = ++this.dataCount + "";
node.getComponent(Label)!.color = color("555555");
var panel = cx.createPanel("ffffffff", cx.sw, 100);
panel.addChild(node);
cx.gn(this, "content").addChild(panel);
}
}