1dcf1cfa-fd4e-432a-98af-b4eb403033a3.js
4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"use strict";
cc._RF.push(module, '1dcf1z6/U5DKpivtOtAMDOj', 'ListViewImpl');
// script/game/ui/baseview/impl/ListViewImpl.ts
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListViewImpl = void 0;
const simba_utils_1 = require("simba-utils");
const CCViewBase_1 = require("../../../../common/classbase/CCViewBase");
const CCDummyObjects_1 = require("../../../../common/CCDummyObjects");
const { ccclass, property } = cc._decorator;
let ListViewImpl = /** @class */ (() => {
let ListViewImpl = class ListViewImpl extends CCViewBase_1.CCPureView {
constructor() {
super(...arguments);
//#region editor bindings
this.contentLayout = CCDummyObjects_1.DummyLayout;
this.scrollView = CCDummyObjects_1.DummyScrollView;
//#endregion
this._refreshing = false;
this._itemViews = {};
this._viewCache = [];
//#endregion
this.onItemClick = (key) => {
return () => {
if (this._props.onItemClick) {
this._props.onItemClick(key);
}
};
};
this.refreshList = async (list) => {
while (this._refreshing) {
await simba_utils_1.delay(0.5);
}
this._refreshing = true;
let allKeys = new Set(Object.keys(this._itemViews));
for (let i = 0; i < list.length; i++) {
let view = this._itemViews[list[i].key];
allKeys.delete(list[i].key);
if (!view) {
view = (this._viewCache.pop() || await this.createListItemView(i));
view.index = i;
view.node.parent = this.contentLayout.node;
view.node.setSiblingIndex(i);
this._itemViews[list[i].key] = view;
}
else if (view.index !== i) {
view.node.setSiblingIndex(i);
view.index = i;
}
view.setProps(Object.assign(Object.assign({}, list[i]), { onClick: this.onItemClick(list[i].key) }));
}
for (let key of allKeys) {
let view = this._itemViews[key];
view.node.removeFromParent(false);
delete this._itemViews[key];
this._viewCache.push(view);
}
this._refreshing = false;
this.onRefreshListEnd();
};
}
onLoad() {
// console.log("ListViewImpl onLoad", this.scrollView);
}
//#region base class overrides
onPropsReceive() {
this._props.items = [...this._props.items];
if (this._prevProps) {
if (!simba_utils_1.shallowEqual(this._props.items, this._prevProps.items)) {
this.refreshList(this._props.items);
}
}
}
onPropsLoad(props) {
// super.onPropsLoad(props);
this.refreshList(props.items);
}
//#endregion
//#region interface impl
scrollToTop() {
this.scrollView.scrollToTop();
}
scrollToBottom(animate = false) {
if (this.contentLayout.node.height > this.scrollView.node.height) {
this.scrollView.scrollToBottom(animate ? 0.3 : undefined);
}
}
onRefreshListEnd() { }
};
__decorate([
property(cc.Layout)
], ListViewImpl.prototype, "contentLayout", void 0);
__decorate([
property(cc.ScrollView)
], ListViewImpl.prototype, "scrollView", void 0);
ListViewImpl = __decorate([
ccclass
], ListViewImpl);
return ListViewImpl;
})();
exports.ListViewImpl = ListViewImpl;
cc._RF.pop();