@cc-component/cc-ex-component 1.1.6 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/core/BaseReference.ts +40 -0
- package/assets/{video/VideoComponent.ts.meta → core/BaseReference.ts.meta} +1 -1
- package/assets/core/BaseViewModelData.ts +12 -0
- package/assets/{video/Interface.ts.meta → core/BaseViewModelData.ts.meta} +1 -1
- package/assets/core/ReferenceComponent.ts +317 -0
- package/assets/core/ViewModel.ts +542 -0
- package/assets/{video/IVideo.ts.meta → core/ViewModel.ts.meta} +9 -9
- package/assets/ex/EXButton.ts +191 -0
- package/assets/ex/EXButton.ts.meta +9 -0
- package/assets/ex/ExCommon.ts +6 -4
- package/assets/ex/ExTool.ts +116 -0
- package/assets/ex/ExTool.ts.meta +9 -0
- package/assets/lib/collectView/lib-ext/custom-grid-flow-layout.ts +105 -0
- package/assets/lib/collectView/lib-ext/custom-grid-flow-layout.ts.meta +9 -0
- package/assets/lib/collectView/lib-ext/horizontal-center-layout.ts +84 -0
- package/assets/lib/collectView/lib-ext/horizontal-center-layout.ts.meta +9 -0
- package/assets/lib/collectView/lib-ext/yx-card-page-layout.ts +132 -0
- package/assets/lib/collectView/lib-ext/yx-card-page-layout.ts.meta +9 -0
- package/assets/lib/collectView/lib-ext/yx-carousel-layout.ts +156 -0
- package/assets/lib/collectView/lib-ext/yx-carousel-layout.ts.meta +9 -0
- package/assets/lib/collectView/lib-ext/yx-cover-layout.ts +405 -0
- package/assets/lib/collectView/lib-ext/yx-cover-layout.ts.meta +9 -0
- package/assets/lib/collectView/lib-ext/yx-masonry-flow-layout.ts +194 -0
- package/assets/lib/collectView/lib-ext/yx-masonry-flow-layout.ts.meta +9 -0
- package/assets/lib/collectView/lib-ext/yx-page-view.ts +232 -0
- package/assets/lib/collectView/lib-ext/yx-page-view.ts.meta +9 -0
- package/assets/lib/collectView/lib-ext/yx-table-view.ts +159 -0
- package/assets/lib/collectView/lib-ext/yx-table-view.ts.meta +9 -0
- package/assets/lib/collectView/lib-ext.meta +9 -0
- package/assets/lib/collectView/lib_collect/yx-collection-view.ts +1549 -0
- package/assets/lib/collectView/lib_collect/yx-collection-view.ts.meta +9 -0
- package/assets/lib/collectView/lib_collect/yx-compact-flow-layout.ts +364 -0
- package/assets/lib/collectView/lib_collect/yx-compact-flow-layout.ts.meta +9 -0
- package/assets/lib/collectView/lib_collect/yx-flow-layout.ts +909 -0
- package/assets/lib/collectView/lib_collect/yx-flow-layout.ts.meta +9 -0
- package/assets/lib/collectView/lib_collect/yx-table-layout.ts +352 -0
- package/assets/lib/collectView/lib_collect/yx-table-layout.ts.meta +9 -0
- package/assets/lib/collectView/lib_collect.meta +9 -0
- package/assets/{video/list.meta → lib/collectView.meta} +9 -9
- package/assets/lib/tableView/IListView.ts +17 -0
- package/assets/lib/tableView/IListView.ts.meta +9 -0
- package/assets/lib/tableView/ListView.ts +197 -0
- package/assets/lib/tableView/ListView.ts.meta +9 -0
- package/assets/lib/tableView/ListViewPage.ts +1048 -0
- package/assets/lib/tableView/ListViewPage.ts.meta +9 -0
- package/assets/lib/tableView/ListViewPageLoop.ts +922 -0
- package/assets/lib/tableView/ListViewPageLoop.ts.meta +1 -0
- package/assets/lib/tableView/TableView.ts +82 -0
- package/assets/lib/tableView/TableView.ts.meta +9 -0
- package/assets/lib/tableView.meta +9 -0
- package/assets/{video.meta → lib.meta} +1 -1
- package/assets/platform/Interface.ts +15 -10
- package/assets/platform/android/AndroidModule.ts +12 -0
- package/assets/platform/android/AndroidModule.ts.meta +9 -0
- package/assets/platform/android/AndroidSDK.ts +1 -2
- package/assets/platform/base/PlatfprmModule.ts +44 -29
- package/assets/platform/base/SDKBase.ts +2 -2
- package/assets/platform/base/TTSDK.ts +21 -10
- package/assets/platform/base/WXSDK.ts +15 -16
- package/assets/platform/wx/MiniSDK.ts +41 -3
- package/assets/platform/wx/wxmini.d.ts +2 -2
- package/index.ts +0 -1
- package/package.json +1 -1
- package/assets/core/ReferenceCollector.ts +0 -172
- package/assets/video/IVideo.ts +0 -73
- package/assets/video/Interface.ts +0 -25
- package/assets/video/VideoComponent.prefab +0 -614
- package/assets/video/VideoComponent.prefab.meta +0 -13
- package/assets/video/VideoComponent.ts +0 -33
- package/assets/video/VideoManager.ts +0 -399
- package/assets/video/VideoManager.ts.meta +0 -9
- package/assets/video/VideoModule.ts +0 -137
- package/assets/video/VideoModule.ts.meta +0 -9
- package/assets/video/VideoPlayTT.ts +0 -338
- package/assets/video/VideoPlayTT.ts.meta +0 -9
- package/assets/video/VideoPlayWX.ts +0 -274
- package/assets/video/VideoPlayWX.ts.meta +0 -9
- package/assets/video/VideoPlayWeb.ts +0 -228
- package/assets/video/VideoPlayWeb.ts.meta +0 -9
- /package/assets/core/{ReferenceCollector.ts.meta → ReferenceComponent.ts.meta} +0 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { _decorator, Component, Node, ScrollView } from 'cc';
|
|
2
|
+
import { YXCollectionView, YXIndexPath } from '../lib_collect/yx-collection-view';
|
|
3
|
+
import { YXFlowLayout } from '../lib_collect/yx-flow-layout';
|
|
4
|
+
const { ccclass, property } = _decorator;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 基于 YXCollectionView 和 YXFlowLayout 封装的一个简单的 PageView
|
|
8
|
+
* 请注意,这个组件更多是为了演示如何基于 YXCollectionView 来实现 PageView 相关的需求,并非完整的功能组件
|
|
9
|
+
* 如果这个组件符合业务的话可以直接拿来用,如果满足不了需求,可以根据实际业务,选择开放更多的配置或者直接使用 YXCollectionView
|
|
10
|
+
*
|
|
11
|
+
* ---
|
|
12
|
+
* 此组件说明
|
|
13
|
+
* - 支持一般的 PageView 业务
|
|
14
|
+
* - 演示了如何封装页面变化事件
|
|
15
|
+
*/
|
|
16
|
+
@ccclass('YXPageView')
|
|
17
|
+
export class YXPageView extends Component {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 监听页面变化事件
|
|
21
|
+
* 在滚动过程实时的检查页面变化
|
|
22
|
+
*/
|
|
23
|
+
static PAGE_CHANGE_EVENT1 = `YXPageView.PAGE_CHANGE_EVENT1`
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 监听页面变化事件
|
|
27
|
+
* 仅在滚动结束的时候去检查页面变化
|
|
28
|
+
*/
|
|
29
|
+
static PAGE_CHANGE_EVENT2 = `YXPageView.PAGE_CHANGE_EVENT2`
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 列表组件
|
|
33
|
+
*/
|
|
34
|
+
private collectionView: YXCollectionView = null
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 滚动方向
|
|
38
|
+
*/
|
|
39
|
+
@property({ tooltip: `滚动方向`, type: YXCollectionView.ScrollDirection, visible: true })
|
|
40
|
+
private _scrollDirection: YXCollectionView.ScrollDirection = YXCollectionView.ScrollDirection.HORIZONTAL
|
|
41
|
+
|
|
42
|
+
set scrollDirection(value: YXCollectionView.ScrollDirection) {
|
|
43
|
+
this.collectionView.scrollDirection = value
|
|
44
|
+
this.collectionView.reloadData()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get scrollDirection(): YXCollectionView.ScrollDirection {
|
|
48
|
+
return this.collectionView.scrollDirection
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 是否允许手势滚动
|
|
53
|
+
* 关闭的话可以禁掉手势滚动业务,但仍然可以通过代码切换页面
|
|
54
|
+
*/
|
|
55
|
+
@property({ tooltip: `是否允许手势滚动`, visible: true })
|
|
56
|
+
private _scrollEnabled: boolean = true
|
|
57
|
+
|
|
58
|
+
set scrollEnabled(value: boolean) {
|
|
59
|
+
this.collectionView.scrollEnabled = value
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get scrollEnabled(): boolean {
|
|
63
|
+
return this.collectionView.scrollEnabled
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 保存所有的页面
|
|
68
|
+
*/
|
|
69
|
+
private pages: Node[] = []
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 获取所有页面
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
getPages(): Node[] {
|
|
76
|
+
return this.pages
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 新增页面到尾部
|
|
81
|
+
* @param page
|
|
82
|
+
*/
|
|
83
|
+
addPage(page: Node) {
|
|
84
|
+
this.pages.push(page)
|
|
85
|
+
this._late_update_pages = true
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 获取当前页面索引
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
getCurrentPageIndex(): number {
|
|
93
|
+
if (this.collectionView.scrollDirection == YXCollectionView.ScrollDirection.HORIZONTAL) {
|
|
94
|
+
let offset = this.collectionView.scrollView.getScrollOffset()
|
|
95
|
+
offset.x = - offset.x
|
|
96
|
+
let idx = Math.round(offset.x / this.collectionView.scrollView.view.width)
|
|
97
|
+
return idx
|
|
98
|
+
}
|
|
99
|
+
if (this.collectionView.scrollDirection == YXCollectionView.ScrollDirection.VERTICAL) {
|
|
100
|
+
let offset = this.collectionView.scrollView.getScrollOffset()
|
|
101
|
+
let idx = Math.round(offset.y / this.collectionView.scrollView.view.height)
|
|
102
|
+
return idx
|
|
103
|
+
}
|
|
104
|
+
return null
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 设置当前要显示的页面
|
|
109
|
+
* 也可以视作 scrollToPage 方法
|
|
110
|
+
* @param index
|
|
111
|
+
* @param timeInSecond
|
|
112
|
+
*/
|
|
113
|
+
setCurrentPageIndex(index: number, timeInSecond: number = 0) {
|
|
114
|
+
let indexPath = new YXIndexPath(0, index)
|
|
115
|
+
this.collectionView.scrollTo(indexPath, timeInSecond)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 插入一个新页面
|
|
120
|
+
* @param page
|
|
121
|
+
* @param index
|
|
122
|
+
*/
|
|
123
|
+
insertPage(page: Node, index: number) {
|
|
124
|
+
this.pages.splice(index, 0, page)
|
|
125
|
+
this._late_update_pages = true
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 移除指定页面
|
|
130
|
+
* @param page
|
|
131
|
+
* @returns
|
|
132
|
+
*/
|
|
133
|
+
removePage(page: Node) {
|
|
134
|
+
for (let index = 0; index < this.pages.length; index++) {
|
|
135
|
+
let node = this.pages[index]
|
|
136
|
+
if (page === node) {
|
|
137
|
+
this.removePageAtIndex(index)
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 移除指定页面
|
|
145
|
+
* @param index
|
|
146
|
+
*/
|
|
147
|
+
removePageAtIndex(index: number) {
|
|
148
|
+
this.pages.splice(index, 1)
|
|
149
|
+
this._late_update_pages = true
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 移除所有页面
|
|
154
|
+
*/
|
|
155
|
+
removeAllPages() {
|
|
156
|
+
this.pages = []
|
|
157
|
+
this._late_update_pages = true
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 立即更新当前页面
|
|
162
|
+
*/
|
|
163
|
+
markForUpdatePages() {
|
|
164
|
+
this.collectionView.reloadData()
|
|
165
|
+
this.onScrolling()
|
|
166
|
+
this.onScrollEnded()
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
protected onLoad(): void {
|
|
170
|
+
this.collectionView = this.node.getComponent(YXCollectionView) || this.node.addComponent(YXCollectionView)
|
|
171
|
+
|
|
172
|
+
this.collectionView.recycleInterval = 0
|
|
173
|
+
this.collectionView.scrollEnabled = this._scrollEnabled
|
|
174
|
+
this.collectionView.scrollDirection = this._scrollDirection
|
|
175
|
+
this.collectionView.numberOfItems = () => this.pages.length
|
|
176
|
+
this.collectionView.registerCell(`cell`, () => {
|
|
177
|
+
let result = new Node(`yx-page`)
|
|
178
|
+
result.layer = this.collectionView.node.layer
|
|
179
|
+
return result
|
|
180
|
+
})
|
|
181
|
+
this.collectionView.onCellDisplay = (cell, indexPath, collectionView) => {
|
|
182
|
+
cell.removeAllChildren()
|
|
183
|
+
let page = this.pages[indexPath.item]
|
|
184
|
+
page.parent = cell
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
let layout = new YXFlowLayout()
|
|
188
|
+
layout.pagingEnabled = true
|
|
189
|
+
layout.itemSize = () => this.collectionView.scrollView.view.contentSize
|
|
190
|
+
this.collectionView.layout = layout
|
|
191
|
+
|
|
192
|
+
this.collectionView.node.on(ScrollView.EventType.SCROLLING, () => {
|
|
193
|
+
this.onScrolling()
|
|
194
|
+
})
|
|
195
|
+
this.collectionView.node.on(ScrollView.EventType.SCROLL_ENDED, () => {
|
|
196
|
+
this.onScrollEnded()
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
protected onDestroy(): void {
|
|
201
|
+
this.pages = []
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private _late_update_pages: boolean = false
|
|
205
|
+
protected update(dt: number): void {
|
|
206
|
+
if (this._late_update_pages) {
|
|
207
|
+
this._late_update_pages = false
|
|
208
|
+
this.collectionView.reloadData()
|
|
209
|
+
this.onScrolling()
|
|
210
|
+
this.onScrollEnded()
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private currentPageForOnScrolling: number = null
|
|
215
|
+
private onScrolling() {
|
|
216
|
+
let getCurrentPageIndex = this.getCurrentPageIndex()
|
|
217
|
+
if (this.currentPageForOnScrolling != getCurrentPageIndex) {
|
|
218
|
+
this.currentPageForOnScrolling = getCurrentPageIndex
|
|
219
|
+
this.node.emit(YXPageView.PAGE_CHANGE_EVENT1, this.currentPageForOnScrolling)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private currentPageForOnScrollEnded: number = null
|
|
224
|
+
private onScrollEnded() {
|
|
225
|
+
let getCurrentPageIndex = this.getCurrentPageIndex()
|
|
226
|
+
if (this.currentPageForOnScrollEnded != getCurrentPageIndex) {
|
|
227
|
+
this.currentPageForOnScrollEnded = getCurrentPageIndex
|
|
228
|
+
this.node.emit(YXPageView.PAGE_CHANGE_EVENT2, this.currentPageForOnScrollEnded)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { _decorator, Component, Enum, instantiate, math, Node, Prefab, UITransform } from 'cc';
|
|
2
|
+
import { YXCollectionView, YXEdgeInsets, YXIndexPath } from '../lib_collect/yx-collection-view';
|
|
3
|
+
import { YXFlowLayout } from '../lib_collect/yx-flow-layout';
|
|
4
|
+
const { ccclass, property } = _decorator;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 节点对齐方式枚举
|
|
8
|
+
*/
|
|
9
|
+
enum _yx_table_view_item_alignment {
|
|
10
|
+
/**
|
|
11
|
+
* cell 节点紧靠列表左边
|
|
12
|
+
*/
|
|
13
|
+
LEFT,
|
|
14
|
+
/**
|
|
15
|
+
* cell 节点相对列表水平居中
|
|
16
|
+
*/
|
|
17
|
+
CENTER,
|
|
18
|
+
/**
|
|
19
|
+
* cell 节点紧靠列表右边
|
|
20
|
+
*/
|
|
21
|
+
RIGHT,
|
|
22
|
+
}
|
|
23
|
+
Enum(_yx_table_view_item_alignment)
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 节点大小模式枚举
|
|
27
|
+
*/
|
|
28
|
+
enum _yx_table_view_item_size_mode {
|
|
29
|
+
/**
|
|
30
|
+
* 使用预制体节点大小
|
|
31
|
+
*/
|
|
32
|
+
USE_PREFAB_SIZE,
|
|
33
|
+
/**
|
|
34
|
+
* 自定义节点大小
|
|
35
|
+
*/
|
|
36
|
+
CUSTOM,
|
|
37
|
+
}
|
|
38
|
+
Enum(_yx_table_view_item_size_mode)
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 基于 YXCollectionView 和 YXFlowLayout 封装的一个简单的 TableView
|
|
42
|
+
* 请注意,这个组件更多是为了演示如何基于 YXCollectionView 来实现自己需要的列表组件,并非完整的功能组件
|
|
43
|
+
* 如果这个组件符合业务的话可以直接拿来用,如果满足不了需求,可以根据实际业务,选择开放更多的配置或者直接使用 YXCollectionView
|
|
44
|
+
*
|
|
45
|
+
* ---
|
|
46
|
+
* 此组件说明
|
|
47
|
+
* - 仅支持编辑器配置
|
|
48
|
+
* - 仅支持垂直方向滚动
|
|
49
|
+
* - 仅支持单类型 cell 节点样式
|
|
50
|
+
* - 仅支持固定的 cell 节点大小
|
|
51
|
+
* - 支持 cell 节点相对于列表的对齐方式,默认居中对齐
|
|
52
|
+
*/
|
|
53
|
+
@ccclass('YXTableView')
|
|
54
|
+
export class YXTableView<T = any> extends Component {
|
|
55
|
+
|
|
56
|
+
static Alignment = _yx_table_view_item_alignment
|
|
57
|
+
|
|
58
|
+
@property({ tooltip: `cell 节点预制体`, type: Prefab, visible: true })
|
|
59
|
+
private cellPrefab: Prefab = null
|
|
60
|
+
|
|
61
|
+
@property({ tooltip: `如何配置 cell 节点大小\nUSE_PREFAB_SIZE: 自动读取预制体大小\nCUSTOM: 自定义节点大小`, type: _yx_table_view_item_size_mode, visible: true })
|
|
62
|
+
private itemSizeMode: _yx_table_view_item_size_mode = _yx_table_view_item_size_mode.CUSTOM
|
|
63
|
+
|
|
64
|
+
@property({
|
|
65
|
+
tooltip: `cell 节点大小`, visible: function (this) {
|
|
66
|
+
return (this.itemSizeMode == _yx_table_view_item_size_mode.CUSTOM)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
private itemSize: math.Size = new math.Size(100, 100)
|
|
70
|
+
|
|
71
|
+
@property({ tooltip: `cell 节点对齐方式`, type: _yx_table_view_item_alignment, visible: true })
|
|
72
|
+
private alignment: _yx_table_view_item_alignment = _yx_table_view_item_alignment.CENTER
|
|
73
|
+
|
|
74
|
+
@property({ tooltip: `cell 节点之间间距`, visible: true })
|
|
75
|
+
private spacing: number = 0
|
|
76
|
+
|
|
77
|
+
@property({ tooltip: `顶部最大偏移距离`, visible: true })
|
|
78
|
+
private top: number = 0
|
|
79
|
+
|
|
80
|
+
@property({ tooltip: `底部最大偏移距离`, visible: true })
|
|
81
|
+
private bottom: number = 0
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 列表组件
|
|
85
|
+
*/
|
|
86
|
+
private collectionView: YXCollectionView = null
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 更新列表数据
|
|
90
|
+
* @param data 列表绑定的数据源
|
|
91
|
+
*/
|
|
92
|
+
setData(data: T[]) {
|
|
93
|
+
this.data = data
|
|
94
|
+
this.reloadCollectionViewIfNeeds()
|
|
95
|
+
}
|
|
96
|
+
private data: T[] = null
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 更新 cell 节点
|
|
100
|
+
* @param call
|
|
101
|
+
*/
|
|
102
|
+
onCellDisplay(call: typeof this.updateCellCall) {
|
|
103
|
+
this.updateCellCall = call
|
|
104
|
+
this.reloadCollectionViewIfNeeds()
|
|
105
|
+
}
|
|
106
|
+
private updateCellCall: (cell: Node, itemData: T, index: number) => void = null
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 滚动到指定节点位置
|
|
110
|
+
* @param idx
|
|
111
|
+
*/
|
|
112
|
+
scrollTo(idx: number) {
|
|
113
|
+
let indexPath = new YXIndexPath(0, idx)
|
|
114
|
+
this.collectionView.scrollTo(indexPath)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 生命周期方法
|
|
119
|
+
*/
|
|
120
|
+
protected onLoad(): void {
|
|
121
|
+
this.collectionView = this.node.getComponent(YXCollectionView) || this.node.addComponent(YXCollectionView)
|
|
122
|
+
|
|
123
|
+
this.collectionView.registerCell(`cell`, () => instantiate(this.cellPrefab))
|
|
124
|
+
this.collectionView.scrollDirection = YXCollectionView.ScrollDirection.VERTICAL
|
|
125
|
+
this.collectionView.numberOfItems = () => this.data.length
|
|
126
|
+
this.collectionView.onCellDisplay = (cell, indexPath, collectionView) => {
|
|
127
|
+
if (this.updateCellCall) {
|
|
128
|
+
this.updateCellCall(cell, this.data[indexPath.item], indexPath.item)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let layout = new YXFlowLayout()
|
|
133
|
+
let itemSize = this.itemSize
|
|
134
|
+
if (this.itemSizeMode == _yx_table_view_item_size_mode.USE_PREFAB_SIZE) {
|
|
135
|
+
itemSize = instantiate(this.cellPrefab).getComponent(UITransform).contentSize
|
|
136
|
+
}
|
|
137
|
+
layout.itemSize = itemSize
|
|
138
|
+
let left = 0
|
|
139
|
+
if (this.alignment == YXTableView.Alignment.LEFT) { left = 0 }
|
|
140
|
+
if (this.alignment == YXTableView.Alignment.CENTER) { left = (this.collectionView.scrollView.view.width - itemSize.width) * 0.5 }
|
|
141
|
+
if (this.alignment == YXTableView.Alignment.RIGHT) { left = (this.collectionView.scrollView.view.width - itemSize.width) * 1 }
|
|
142
|
+
layout.sectionInset = new YXEdgeInsets(this.top, left, this.bottom, 0)
|
|
143
|
+
layout.verticalSpacing = this.spacing
|
|
144
|
+
this.collectionView.layout = layout
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
protected onDestroy(): void {
|
|
148
|
+
this.data = []
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private reloadCollectionViewIfNeeds() {
|
|
152
|
+
// `数据源` 配置好后才去更新列表,没配置好的话更新没有意义
|
|
153
|
+
if (this.data == null) {
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
this.collectionView.reloadData()
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|