@cc-component/cc-ex-component 1.1.5 → 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.
Files changed (82) hide show
  1. package/assets/core/BaseReference.ts +40 -0
  2. package/assets/{video/Interface.ts.meta → core/BaseReference.ts.meta} +1 -1
  3. package/assets/core/BaseViewModelData.ts +12 -0
  4. package/assets/{video/VideoComponent.ts.meta → core/BaseViewModelData.ts.meta} +1 -1
  5. package/assets/core/ReferenceComponent.ts +317 -0
  6. package/assets/core/ViewModel.ts +542 -0
  7. package/assets/core/ViewModel.ts.meta +9 -0
  8. package/assets/ex/EXButton.ts +191 -0
  9. package/assets/ex/EXButton.ts.meta +9 -0
  10. package/assets/ex/{BaseEx.ts → ExCommon.ts} +6 -4
  11. package/assets/ex/ExTool.ts +116 -0
  12. package/assets/ex/ExTool.ts.meta +9 -0
  13. package/assets/lib/collectView/lib-ext/custom-grid-flow-layout.ts +105 -0
  14. package/assets/{video/IVideo.ts.meta → lib/collectView/lib-ext/custom-grid-flow-layout.ts.meta} +1 -1
  15. package/assets/lib/collectView/lib-ext/horizontal-center-layout.ts +84 -0
  16. package/assets/lib/collectView/lib-ext/horizontal-center-layout.ts.meta +9 -0
  17. package/assets/lib/collectView/lib-ext/yx-card-page-layout.ts +132 -0
  18. package/assets/lib/collectView/lib-ext/yx-card-page-layout.ts.meta +9 -0
  19. package/assets/lib/collectView/lib-ext/yx-carousel-layout.ts +156 -0
  20. package/assets/lib/collectView/lib-ext/yx-carousel-layout.ts.meta +9 -0
  21. package/assets/lib/collectView/lib-ext/yx-cover-layout.ts +405 -0
  22. package/assets/lib/collectView/lib-ext/yx-cover-layout.ts.meta +9 -0
  23. package/assets/lib/collectView/lib-ext/yx-masonry-flow-layout.ts +194 -0
  24. package/assets/lib/collectView/lib-ext/yx-masonry-flow-layout.ts.meta +9 -0
  25. package/assets/lib/collectView/lib-ext/yx-page-view.ts +232 -0
  26. package/assets/lib/collectView/lib-ext/yx-page-view.ts.meta +9 -0
  27. package/assets/lib/collectView/lib-ext/yx-table-view.ts +159 -0
  28. package/assets/lib/collectView/lib-ext/yx-table-view.ts.meta +9 -0
  29. package/assets/lib/collectView/lib-ext.meta +9 -0
  30. package/assets/lib/collectView/lib_collect/yx-collection-view.ts +1549 -0
  31. package/assets/lib/collectView/lib_collect/yx-collection-view.ts.meta +9 -0
  32. package/assets/lib/collectView/lib_collect/yx-compact-flow-layout.ts +364 -0
  33. package/assets/lib/collectView/lib_collect/yx-compact-flow-layout.ts.meta +9 -0
  34. package/assets/lib/collectView/lib_collect/yx-flow-layout.ts +909 -0
  35. package/assets/lib/collectView/lib_collect/yx-flow-layout.ts.meta +9 -0
  36. package/assets/lib/collectView/lib_collect/yx-table-layout.ts +352 -0
  37. package/assets/lib/collectView/lib_collect/yx-table-layout.ts.meta +9 -0
  38. package/assets/lib/collectView/lib_collect.meta +9 -0
  39. package/assets/{video/list.meta → lib/collectView.meta} +9 -9
  40. package/assets/lib/tableView/IListView.ts +17 -0
  41. package/assets/lib/tableView/IListView.ts.meta +9 -0
  42. package/assets/lib/tableView/ListView.ts +197 -0
  43. package/assets/lib/tableView/ListView.ts.meta +9 -0
  44. package/assets/lib/tableView/ListViewPage.ts +1048 -0
  45. package/assets/lib/tableView/ListViewPage.ts.meta +9 -0
  46. package/assets/lib/tableView/ListViewPageLoop.ts +922 -0
  47. package/assets/lib/tableView/ListViewPageLoop.ts.meta +1 -0
  48. package/assets/lib/tableView/TableView.ts +82 -0
  49. package/assets/lib/tableView/TableView.ts.meta +9 -0
  50. package/assets/lib/tableView.meta +9 -0
  51. package/assets/{video.meta → lib.meta} +1 -1
  52. package/assets/platform/Interface.ts +15 -10
  53. package/assets/platform/android/AndroidModule.ts +12 -0
  54. package/assets/platform/android/AndroidModule.ts.meta +9 -0
  55. package/assets/platform/android/AndroidSDK.ts +12 -2
  56. package/assets/platform/base/EditorSDK.ts +12 -11
  57. package/assets/platform/base/PlatfprmModule.ts +44 -29
  58. package/assets/platform/base/SDKBase.ts +3 -3
  59. package/assets/platform/base/TTSDK.ts +22 -11
  60. package/assets/platform/base/WXSDK.ts +16 -17
  61. package/assets/platform/wx/MiniSDK.ts +41 -3
  62. package/assets/platform/wx/wxmini.d.ts +2 -2
  63. package/index.ts +1 -3
  64. package/package.json +1 -1
  65. package/assets/core/ReferenceCollector.ts +0 -172
  66. package/assets/video/IVideo.ts +0 -73
  67. package/assets/video/Interface.ts +0 -25
  68. package/assets/video/VideoComponent.prefab +0 -614
  69. package/assets/video/VideoComponent.prefab.meta +0 -13
  70. package/assets/video/VideoComponent.ts +0 -33
  71. package/assets/video/VideoManager.ts +0 -399
  72. package/assets/video/VideoManager.ts.meta +0 -9
  73. package/assets/video/VideoModule.ts +0 -137
  74. package/assets/video/VideoModule.ts.meta +0 -9
  75. package/assets/video/VideoPlayTT.ts +0 -338
  76. package/assets/video/VideoPlayTT.ts.meta +0 -9
  77. package/assets/video/VideoPlayWX.ts +0 -274
  78. package/assets/video/VideoPlayWX.ts.meta +0 -9
  79. package/assets/video/VideoPlayWeb.ts +0 -228
  80. package/assets/video/VideoPlayWeb.ts.meta +0 -9
  81. /package/assets/core/{ReferenceCollector.ts.meta → ReferenceComponent.ts.meta} +0 -0
  82. /package/assets/ex/{BaseEx.ts.meta → ExCommon.ts.meta} +0 -0
@@ -0,0 +1,9 @@
1
+ {
2
+ "ver": "4.0.24",
3
+ "importer": "typescript",
4
+ "imported": true,
5
+ "uuid": "f2c14ab4-51e7-4ea7-ba67-5882a26bc0be",
6
+ "files": [],
7
+ "subMetas": {},
8
+ "userData": {}
9
+ }
@@ -0,0 +1,364 @@
1
+ import { _decorator, math, UITransform } from 'cc';
2
+ import { YXBinaryLayout, YXCollectionView, YXEdgeInsets, YXIndexPath, YXLayoutAttributes } from './yx-collection-view';
3
+ const { ccclass, property } = _decorator;
4
+
5
+ const _rectOut = new math.Rect()
6
+
7
+ /**
8
+ * 流式布局 (紧凑排列)
9
+ * 支持水平/垂直方向排列滚动
10
+ */
11
+ export class YXCompactFlowLayout extends YXBinaryLayout {
12
+
13
+ /**
14
+ * 是否开启分页滚动效果
15
+ */
16
+ pagingEnabled: boolean = false
17
+
18
+ /**
19
+ * 元素大小
20
+ */
21
+ itemSize: math.Size | ((indexPath: YXIndexPath, layout: YXCompactFlowLayout, collectionView: YXCollectionView) => math.Size) = new math.Size(100, 100)
22
+ getItemSize(): math.Size {
23
+ if (this.itemSize instanceof Function == false) {
24
+ return this.itemSize
25
+ }
26
+ throw new Error("YXFlowLayout: 动态配置的布局参数不支持直接获取,请检查自己的布局逻辑并谨慎的通过动态配置自己获取,注意避免死循环");
27
+ }
28
+
29
+ /**
30
+ * 元素之间垂直间距
31
+ */
32
+ verticalSpacing: number | ((section: number, layout: YXCompactFlowLayout, collectionView: YXCollectionView) => number) = 0
33
+ getVerticalSpacing(): number {
34
+ if (this.verticalSpacing instanceof Function == false) {
35
+ return this.verticalSpacing
36
+ }
37
+ throw new Error("YXFlowLayout: 动态配置的布局参数不支持直接获取,请检查自己的布局逻辑并谨慎的通过动态配置自己获取,注意避免死循环");
38
+ }
39
+
40
+ /**
41
+ * 元素之间水平间距
42
+ */
43
+ horizontalSpacing: number | ((section: number, layout: YXCompactFlowLayout, collectionView: YXCollectionView) => number) = 0
44
+ getHorizontalSpacing(): number {
45
+ if (this.horizontalSpacing instanceof Function == false) {
46
+ return this.horizontalSpacing
47
+ }
48
+ throw new Error("YXFlowLayout: 动态配置的布局参数不支持直接获取,请检查自己的布局逻辑并谨慎的通过动态配置自己获取,注意避免死循环");
49
+ }
50
+
51
+ /**
52
+ * 边距
53
+ */
54
+ sectionInset: YXEdgeInsets | ((section: number, layout: YXCompactFlowLayout, collectionView: YXCollectionView) => YXEdgeInsets) = YXEdgeInsets.ZERO
55
+ getSectionInset(): YXEdgeInsets {
56
+ if (this.sectionInset instanceof Function == false) {
57
+ return this.sectionInset
58
+ }
59
+ throw new Error("YXFlowLayout: 动态配置的布局参数不支持直接获取,请检查自己的布局逻辑并谨慎的通过动态配置自己获取,注意避免死循环");
60
+ }
61
+
62
+ prepare(collectionView: YXCollectionView): void {
63
+ if (collectionView.scrollDirection == YXCollectionView.ScrollDirection.HORIZONTAL) {
64
+ this._horizontal(collectionView)
65
+ return
66
+ }
67
+ if (collectionView.scrollDirection == YXCollectionView.ScrollDirection.VERTICAL) {
68
+ this._vertical(collectionView)
69
+ return
70
+ }
71
+ }
72
+
73
+ initOffset(collectionView: YXCollectionView): void {
74
+ if (collectionView.scrollDirection == YXCollectionView.ScrollDirection.HORIZONTAL) {
75
+ collectionView.scrollView.scrollToLeft(0)
76
+ return
77
+ }
78
+ if (collectionView.scrollDirection == YXCollectionView.ScrollDirection.VERTICAL) {
79
+ collectionView.scrollView.scrollToTop(0)
80
+ return
81
+ }
82
+ }
83
+
84
+ targetOffset(collectionView: YXCollectionView, touchMoveVelocity: math.Vec3, startOffset: math.Vec2, originTargetOffset: math.Vec2, originScrollDuration: number): { offset: math.Vec2; time?: number; attenuated?: boolean; } | null {
85
+ if (this.pagingEnabled == false) {
86
+ return null
87
+ }
88
+ let offset = collectionView.scrollView.getScrollOffset()
89
+ offset.x = - offset.x
90
+ let threshold = 0.2
91
+ if (collectionView.scrollDirection == YXCollectionView.ScrollDirection.HORIZONTAL) {
92
+ let idx = Math.round(offset.x / collectionView.scrollView.view.width)
93
+ let r = touchMoveVelocity.x / collectionView.scrollView.view.width
94
+ if (startOffset && Math.abs(r) >= threshold) {
95
+ idx = Math.round(startOffset.x / collectionView.scrollView.view.width) + (r > 0 ? -1 : 1)
96
+ }
97
+ offset.x = idx * collectionView.scrollView.view.width
98
+ }
99
+ if (collectionView.scrollDirection == YXCollectionView.ScrollDirection.VERTICAL) {
100
+ let idx = Math.round(offset.y / collectionView.scrollView.view.height)
101
+ let r = touchMoveVelocity.y / collectionView.scrollView.view.height
102
+ if (startOffset && Math.abs(r) >= threshold) {
103
+ idx = Math.round(startOffset.y / collectionView.scrollView.view.height) + (r > 0 ? 1 : -1)
104
+ }
105
+ offset.y = idx * collectionView.scrollView.view.height
106
+ }
107
+ return { offset: offset, time: 0.25 }
108
+ }
109
+
110
+ private _horizontal(collectionView: YXCollectionView) {
111
+ collectionView.scrollView.horizontal = true
112
+ collectionView.scrollView.vertical = false
113
+ let contentSize = collectionView.node.getComponent(UITransform).contentSize.clone()
114
+ let allAttributes: YXLayoutAttributes[] = []
115
+
116
+ let numberOfSections = collectionView.getNumberOfSections()
117
+
118
+ let sectionMaxX = 0
119
+ for (let section = 0; section < numberOfSections; section++) {
120
+ let numberOfItems = collectionView.getNumberOfItems(section)
121
+ let verticalSpacing = this.verticalSpacing instanceof Function ? this.verticalSpacing(section, this, collectionView) : this.verticalSpacing
122
+ let horizontalSpacing = this.horizontalSpacing instanceof Function ? this.horizontalSpacing(section, this, collectionView) : this.horizontalSpacing
123
+ let sectionInset = this.sectionInset instanceof Function ? this.sectionInset(section, this, collectionView) : this.sectionInset
124
+
125
+ sectionMaxX += sectionInset.left
126
+
127
+ let whole = new _yx_flow_layout_whole()
128
+ whole.verticalSpacing = verticalSpacing
129
+ whole.horizontalSpacing = horizontalSpacing
130
+ whole.sectionInset = sectionInset
131
+ whole.offset = sectionMaxX
132
+ whole.attrs = []
133
+ whole.containerWidth = 0
134
+ whole.containerHeight = contentSize.height
135
+
136
+ for (let item = 0; item < numberOfItems; item++) {
137
+ let indexPath = new YXIndexPath(section, item)
138
+ let itemSize = this.itemSize instanceof Function ? this.itemSize(indexPath, this, collectionView) : this.itemSize
139
+
140
+ let attr = whole.layout_horizontal_item(indexPath, itemSize)
141
+ if (attr == null) {
142
+ // 返回 null 表示摆不下了,需要换列排列
143
+ whole.offset = whole.offset + whole.containerWidth + horizontalSpacing
144
+ whole.containerWidth = 0
145
+ whole.attrs = []
146
+ attr = whole.layout_horizontal_item(indexPath, itemSize)
147
+ }
148
+ if (attr) {
149
+ allAttributes.push(attr)
150
+ }
151
+ sectionMaxX = Math.max(sectionMaxX, whole.offset + whole.containerWidth)
152
+ }
153
+ sectionMaxX += sectionInset.right
154
+ }
155
+
156
+ this.attributes = allAttributes
157
+ contentSize.width = Math.max(contentSize.width, sectionMaxX)
158
+ this.contentSize = contentSize
159
+ }
160
+
161
+ private _vertical(collectionView: YXCollectionView) {
162
+ collectionView.scrollView.horizontal = false
163
+ collectionView.scrollView.vertical = true
164
+ let contentSize = collectionView.node.getComponent(UITransform).contentSize.clone()
165
+ let allAttributes: YXLayoutAttributes[] = []
166
+
167
+ let numberOfSections = collectionView.getNumberOfSections()
168
+
169
+ let sectionMaxY = 0
170
+ for (let section = 0; section < numberOfSections; section++) {
171
+ let numberOfItems = collectionView.getNumberOfItems(section)
172
+ let verticalSpacing = this.verticalSpacing instanceof Function ? this.verticalSpacing(section, this, collectionView) : this.verticalSpacing
173
+ let horizontalSpacing = this.horizontalSpacing instanceof Function ? this.horizontalSpacing(section, this, collectionView) : this.horizontalSpacing
174
+ let sectionInset = this.sectionInset instanceof Function ? this.sectionInset(section, this, collectionView) : this.sectionInset
175
+
176
+ sectionMaxY += sectionInset.top
177
+
178
+ let whole = new _yx_flow_layout_whole()
179
+ whole.verticalSpacing = verticalSpacing
180
+ whole.horizontalSpacing = horizontalSpacing
181
+ whole.sectionInset = sectionInset
182
+ whole.offset = sectionMaxY
183
+ whole.attrs = []
184
+ whole.containerWidth = contentSize.width
185
+ whole.containerHeight = 0
186
+
187
+ for (let item = 0; item < numberOfItems; item++) {
188
+ let indexPath = new YXIndexPath(section, item)
189
+ let itemSize = this.itemSize instanceof Function ? this.itemSize(indexPath, this, collectionView) : this.itemSize
190
+
191
+ let attr = whole.layout_vertical_item(indexPath, itemSize)
192
+ if (attr == null) {
193
+ // 返回 null 表示摆不下了,需要换行排列
194
+ whole.offset = whole.offset + whole.containerHeight + verticalSpacing
195
+ whole.containerHeight = 0
196
+ whole.attrs = []
197
+ attr = whole.layout_vertical_item(indexPath, itemSize)
198
+ }
199
+ if (attr) {
200
+ allAttributes.push(attr)
201
+ }
202
+ sectionMaxY = Math.max(sectionMaxY, whole.offset + whole.containerHeight)
203
+ }
204
+ sectionMaxY += sectionInset.bottom
205
+ }
206
+
207
+ this.attributes = allAttributes
208
+ contentSize.height = Math.max(contentSize.height, sectionMaxY)
209
+ this.contentSize = contentSize
210
+ }
211
+ }
212
+
213
+ /**
214
+ * 这个类用来实现紧凑流式布局
215
+ * 目前版本使用的策略: 贪心算法,遍历取当前整体内最优的位置
216
+ * GPT: 水平/垂直扫描 和 贪心算法 是解决这种矩形排列问题的简单有效方法。它们通过从当前矩形的位置出发,逐步扫描周围空白区域来寻找新矩形的放置位置。虽然这种方法比较直观且易于实现,但在复杂情况下可能不是最优解。对于更高效的排列策略,可能需要结合更多的启发式方法或优化算法。
217
+ * @todo 优化排列算法 (如果能想到更好的排列算法的话)
218
+ */
219
+ class _yx_flow_layout_whole {
220
+
221
+ /**
222
+ * 当前这块内容的起始位置
223
+ */
224
+ offset: number
225
+
226
+ /**
227
+ * flow layout 部分参数
228
+ */
229
+ verticalSpacing: number
230
+ horizontalSpacing: number
231
+ sectionInset: YXEdgeInsets
232
+
233
+ /**
234
+ * 容器相关的参数
235
+ */
236
+ containerWidth: number
237
+ containerHeight: number
238
+
239
+ /**
240
+ * 这块内容区域目前已经摆放的节点
241
+ */
242
+ attrs: YXLayoutAttributes[] = []
243
+
244
+ /**
245
+ * 检查传进来的位置是否跟当前这块内容的其他节点重叠
246
+ */
247
+ intersects(rect: math.Rect) {
248
+ for (let index = 0; index < this.attrs.length; index++) {
249
+ const element = this.attrs[index];
250
+ math.Rect.intersection(_rectOut, element.frame, rect)
251
+ if (_rectOut.width > 0 && _rectOut.height > 0) {
252
+ return true
253
+ }
254
+ }
255
+ return false
256
+ }
257
+
258
+ /**
259
+ * 垂直方向列表的节点的排列规则
260
+ */
261
+ layout_vertical_item(indexPath: YXIndexPath, itemSize: math.Size) {
262
+ if (this.attrs.length <= 0) {
263
+ let attributes = YXLayoutAttributes.layoutAttributesForCell(indexPath)
264
+ attributes.frame.set(this.sectionInset.left, this.offset, itemSize.width, itemSize.height)
265
+ this.attrs.push(attributes)
266
+ this.containerHeight = Math.max(this.containerHeight, attributes.frame.height)
267
+ return attributes
268
+ }
269
+
270
+ const frame = new math.Rect()
271
+ frame.size = itemSize
272
+
273
+ // 检查所有节点的右边
274
+ for (let index = 0; index < this.attrs.length; index++) {
275
+ const element = this.attrs[index];
276
+ frame.x = element.frame.xMax + this.horizontalSpacing
277
+ frame.y = element.frame.y
278
+ if (frame.xMax <= (this.containerWidth - this.sectionInset.right)) {
279
+ if (this.intersects(frame) == false) {
280
+ let attributes = YXLayoutAttributes.layoutAttributesForCell(indexPath)
281
+ attributes.frame.set(frame)
282
+ this.attrs.push(attributes)
283
+ this.containerHeight = Math.max(this.containerHeight, attributes.frame.yMax - this.offset)
284
+ return attributes
285
+ }
286
+ }
287
+ }
288
+
289
+ // 检测所有节点的下边
290
+ for (let index = 0; index < this.attrs.length; index++) {
291
+ const element = this.attrs[index];
292
+ frame.x = element.frame.x
293
+ frame.y = element.frame.yMax + this.verticalSpacing
294
+ const check_xMax = frame.xMax <= (this.containerWidth - this.sectionInset.right)
295
+ const check_yMax = frame.yMax <= (this.offset + this.containerHeight)
296
+ if (check_xMax && check_yMax) {
297
+ if (this.intersects(frame) == false) {
298
+ let attributes = YXLayoutAttributes.layoutAttributesForCell(indexPath)
299
+ attributes.frame.set(frame)
300
+ this.attrs.push(attributes)
301
+ this.containerHeight = Math.max(this.containerHeight, attributes.frame.height)
302
+ return attributes
303
+ }
304
+ }
305
+
306
+ }
307
+
308
+ // 走到这里表示这块内容区域已经摆不下了,需要换行处理
309
+ return null
310
+ }
311
+
312
+ /**
313
+ * 水平方向列表的节点的排列规则
314
+ */
315
+ layout_horizontal_item(indexPath: YXIndexPath, itemSize: math.Size) {
316
+ if (this.attrs.length <= 0) {
317
+ let attributes = YXLayoutAttributes.layoutAttributesForCell(indexPath)
318
+ attributes.frame.set(this.offset, this.sectionInset.top, itemSize.width, itemSize.height)
319
+ this.attrs.push(attributes)
320
+ this.containerWidth = Math.max(this.containerWidth, attributes.frame.width)
321
+ return attributes
322
+ }
323
+
324
+ const frame = new math.Rect()
325
+ frame.size = itemSize
326
+
327
+ // 检测所有节点的下边
328
+ for (let index = 0; index < this.attrs.length; index++) {
329
+ const element = this.attrs[index];
330
+ frame.x = element.frame.x
331
+ frame.y = element.frame.yMax + this.verticalSpacing
332
+ if (frame.yMax <= (this.containerHeight - this.sectionInset.bottom)) {
333
+ if (this.intersects(frame) == false) {
334
+ let attributes = YXLayoutAttributes.layoutAttributesForCell(indexPath)
335
+ attributes.frame.set(frame)
336
+ this.attrs.push(attributes)
337
+ this.containerWidth = Math.max(this.containerWidth, attributes.frame.xMax - this.offset)
338
+ return attributes
339
+ }
340
+ }
341
+ }
342
+
343
+ // 检查所有节点的右边
344
+ for (let index = 0; index < this.attrs.length; index++) {
345
+ const element = this.attrs[index];
346
+ frame.x = element.frame.xMax + this.horizontalSpacing
347
+ frame.y = element.frame.y
348
+ const check_xMax = frame.xMax <= (this.offset + this.containerWidth)
349
+ const check_yMax = frame.yMax <= (this.containerHeight - this.sectionInset.bottom)
350
+ if (check_xMax && check_yMax) {
351
+ if (this.intersects(frame) == false) {
352
+ let attributes = YXLayoutAttributes.layoutAttributesForCell(indexPath)
353
+ attributes.frame.set(frame)
354
+ this.attrs.push(attributes)
355
+ this.containerWidth = Math.max(this.containerWidth, attributes.frame.width)
356
+ return attributes
357
+ }
358
+ }
359
+ }
360
+
361
+ // 走到这里表示这块内容区域已经摆不下了
362
+ return null
363
+ }
364
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "ver": "4.0.24",
3
+ "importer": "typescript",
4
+ "imported": true,
5
+ "uuid": "6aefb187-febc-4916-93a9-f062e3bdd1f5",
6
+ "files": [],
7
+ "subMetas": {},
8
+ "userData": {}
9
+ }