6e88bf8c-bde8-4ae4-9361-55bb1a983d10.js
5.21 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
"use strict";
cc._RF.push(module, '6e88b+MvehK5JNhVbsamD0Q', 'ListSubviewImpl');
// script/game/ui/baseview/impl/ListSubviewImpl.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.ListSubviewImpl = void 0;
const CCViewBase_1 = require("../../../../common/classbase/CCViewBase");
const CCDummyObjects_1 = require("../../../../common/CCDummyObjects");
const simba_utils_1 = require("simba-utils");
const { ccclass, property } = cc._decorator;
let ListSubviewImpl = /** @class */ (() => {
let ListSubviewImpl = class ListSubviewImpl extends CCViewBase_1.CCPureSubview {
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 = await this.createItemView(list[i], 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.putItemView(view);
}
this._refreshing = false;
this.onRefreshListEnd();
};
this.createItemView = async (item, i) => {
let key = item.itype + "";
if (this._viewCache[key] && this._viewCache[key].length > 0) {
let ret = this._viewCache[key].pop();
ret._type = key;
return ret;
}
let ret = this.createListItemView(i);
ret._type = key;
return ret;
};
this.putItemView = (view) => {
let key = view._type;
let cacheArr = this._viewCache[key];
if (!cacheArr) {
this._viewCache[key] = cacheArr = [];
}
cacheArr.push(view);
};
}
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)
], ListSubviewImpl.prototype, "contentLayout", void 0);
__decorate([
property(cc.ScrollView)
], ListSubviewImpl.prototype, "scrollView", void 0);
ListSubviewImpl = __decorate([
ccclass
], ListSubviewImpl);
return ListSubviewImpl;
})();
exports.ListSubviewImpl = ListSubviewImpl;
cc._RF.pop();