@cc-component/cc-ex-component 1.1.6 → 1.1.8

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 (80) hide show
  1. package/assets/core/BaseReference.ts +40 -0
  2. package/assets/{video/VideoComponent.ts.meta → core/BaseReference.ts.meta} +1 -1
  3. package/assets/core/BaseViewModelData.ts +12 -0
  4. package/assets/{video/Interface.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/{video/IVideo.ts.meta → core/ViewModel.ts.meta} +9 -9
  8. package/assets/ex/EXButton.ts +191 -0
  9. package/assets/ex/EXButton.ts.meta +9 -0
  10. package/assets/ex/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/lib/collectView/lib-ext/custom-grid-flow-layout.ts.meta +9 -0
  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 +1 -2
  56. package/assets/platform/base/PlatfprmModule.ts +44 -29
  57. package/assets/platform/base/SDKBase.ts +2 -2
  58. package/assets/platform/base/TTSDK.ts +21 -10
  59. package/assets/platform/base/WXSDK.ts +15 -16
  60. package/assets/platform/wx/MiniSDK.ts +41 -3
  61. package/assets/platform/wx/wxmini.d.ts +2 -2
  62. package/index.ts +10 -3
  63. package/package.json +1 -1
  64. package/assets/core/ReferenceCollector.ts +0 -172
  65. package/assets/video/IVideo.ts +0 -73
  66. package/assets/video/Interface.ts +0 -25
  67. package/assets/video/VideoComponent.prefab +0 -614
  68. package/assets/video/VideoComponent.prefab.meta +0 -13
  69. package/assets/video/VideoComponent.ts +0 -33
  70. package/assets/video/VideoManager.ts +0 -399
  71. package/assets/video/VideoManager.ts.meta +0 -9
  72. package/assets/video/VideoModule.ts +0 -137
  73. package/assets/video/VideoModule.ts.meta +0 -9
  74. package/assets/video/VideoPlayTT.ts +0 -338
  75. package/assets/video/VideoPlayTT.ts.meta +0 -9
  76. package/assets/video/VideoPlayWX.ts +0 -274
  77. package/assets/video/VideoPlayWX.ts.meta +0 -9
  78. package/assets/video/VideoPlayWeb.ts +0 -228
  79. package/assets/video/VideoPlayWeb.ts.meta +0 -9
  80. /package/assets/core/{ReferenceCollector.ts.meta → ReferenceComponent.ts.meta} +0 -0
@@ -0,0 +1,132 @@
1
+ import { _decorator, Component, log, math, Node } from 'cc';
2
+ import { YXCollectionView, YXIndexPath, YXLayout, YXLayoutAttributes } from '../lib_collect/yx-collection-view';
3
+
4
+ export class YXCardPageLayout extends YXLayout {
5
+
6
+ /**
7
+ * 节点大小
8
+ */
9
+ itemSize: math.Size = null
10
+
11
+ /**
12
+ * 最多同时显示多少个节点
13
+ */
14
+ maxVisibleItemCount: number = 4
15
+
16
+ /**
17
+ * 每个节点之间的缩放差距
18
+ */
19
+ eachScale: number = 0.1
20
+
21
+ /**
22
+ * 每个节点之间间距
23
+ */
24
+ eachSpacing: number = 50
25
+
26
+ /**
27
+ * 整体内容偏移
28
+ */
29
+ contentOffset: math.Vec3 = null
30
+
31
+ /**
32
+ * 此类布局必须确定节点大小
33
+ */
34
+ constructor(itemSize: math.Size) {
35
+ super()
36
+ this.itemSize = itemSize
37
+ }
38
+
39
+ prepare(collectionView: YXCollectionView): void {
40
+ collectionView.scrollView.horizontal = true
41
+ collectionView.scrollView.vertical = false
42
+
43
+ let allAttributes = []
44
+ let total = collectionView.getNumberOfItems(0)
45
+ total = Math.min(total, this.maxVisibleItemCount)
46
+ for (let index = 0; index < total; index++) {
47
+ let attr = YXLayoutAttributes.layoutAttributesForCell(new YXIndexPath(0, index))
48
+ attr.frame.size = this.itemSize
49
+ allAttributes.push(attr)
50
+ }
51
+ this.attributes = allAttributes
52
+ let contentSize = collectionView.scrollView.view.contentSize.clone()
53
+ contentSize.width = contentSize.width * 3
54
+ this.contentSize = contentSize
55
+ }
56
+
57
+ layoutAttributesForElementsInRect(rect: math.Rect, collectionView: YXCollectionView): YXLayoutAttributes[] {
58
+ let offset = collectionView.scrollView.getScrollOffset()
59
+ offset.x = - offset.x
60
+ let progress = (offset.x - collectionView.scrollView.view.width) / collectionView.scrollView.view.width // [ -1 0 1 ]
61
+
62
+ for (let index = 0; index < this.attributes.length; index++) {
63
+ const attr = this.attributes[index];
64
+
65
+ // 调整层级
66
+ attr.zIndex = -index
67
+
68
+ // 调整位置
69
+ let startOffsetY = index * this.eachSpacing
70
+ attr.frame.x = offset.x + (collectionView.scrollView.view.width - attr.frame.width) * 0.5
71
+ attr.frame.y = offset.y + (collectionView.scrollView.view.height - attr.frame.height) * 0.5 + startOffsetY
72
+ attr.frame.y = attr.frame.y - this.eachSpacing * Math.abs(progress)
73
+ attr.frame.y = Math.max(attr.frame.y, offset.y + (collectionView.scrollView.view.height - attr.frame.height) * 0.5)
74
+ if (index == 0) {
75
+ attr.frame.x = attr.frame.x - progress * collectionView.scrollView.view.width
76
+ }
77
+
78
+ // 调整缩放
79
+ let startScale = 1 - index * this.eachScale
80
+ let scale = startScale
81
+ scale = scale + this.eachScale * Math.abs(progress)
82
+ scale = Math.min(scale, 1)
83
+ attr.scale = new math.Vec3(scale, scale, 1)
84
+
85
+ // 偏移
86
+ if (this.contentOffset) {
87
+ attr.offset = this.contentOffset
88
+ }
89
+ }
90
+ return this.attributes
91
+ }
92
+
93
+ initOffset(collectionView: YXCollectionView): void {
94
+ let offset = new math.Vec2()
95
+ offset.x = collectionView.scrollView.view.width
96
+ offset.y = 0
97
+ collectionView.scrollView.scrollToOffset(offset)
98
+ }
99
+
100
+ /**
101
+ * 分页逻辑
102
+ */
103
+ targetOffset(collectionView: YXCollectionView, touchMoveVelocity: math.Vec3, startOffset: math.Vec2, originTargetOffset: math.Vec2, originScrollDuration: number): { offset: math.Vec2; time?: number; attenuated?: boolean; } | null {
104
+ let offset = collectionView.scrollView.getScrollOffset()
105
+ offset.x = - offset.x
106
+ let threshold = 0.2
107
+
108
+ let idx = Math.round(offset.x / collectionView.scrollView.view.width)
109
+ let r = touchMoveVelocity.x / collectionView.scrollView.view.width
110
+ if (startOffset && Math.abs(r) >= threshold) {
111
+ idx = Math.round(startOffset.x / collectionView.scrollView.view.width) + (r > 0 ? -1 : 1)
112
+ }
113
+ offset.x = idx * collectionView.scrollView.view.width
114
+
115
+ return { offset: offset, time: 0.5 }
116
+ }
117
+
118
+ /**
119
+ * 标记此布局需要实时更新
120
+ */
121
+ shouldUpdateAttributesForBoundsChange(): boolean {
122
+ return true
123
+ }
124
+
125
+ /**
126
+ * 标记此布局需要调整节点层级
127
+ */
128
+ shouldUpdateAttributesZIndex(): boolean {
129
+ return true
130
+ }
131
+ }
132
+
@@ -0,0 +1,9 @@
1
+ {
2
+ "ver": "4.0.24",
3
+ "importer": "typescript",
4
+ "imported": true,
5
+ "uuid": "51c366be-372c-4db4-b338-ead340893f2d",
6
+ "files": [],
7
+ "subMetas": {},
8
+ "userData": {}
9
+ }
@@ -0,0 +1,156 @@
1
+ import { _decorator, log, math, misc } from 'cc';
2
+ import { YXCollectionView, YXIndexPath, YXLayout, YXLayoutAttributes } from '../lib_collect/yx-collection-view';
3
+
4
+ const _vec2Out = new math.Vec2()
5
+
6
+ /**
7
+ * 旋转木马,会加载所有节点,适合少量数据
8
+ * 仅支持了水平方向滚动
9
+ */
10
+ export class YXCarouselLayout extends YXLayout {
11
+ /**
12
+ * 节点大小
13
+ */
14
+ itemSize: math.Size = null
15
+
16
+ /**
17
+ * 是否开启循环滚动
18
+ */
19
+ loop: boolean = true
20
+
21
+ /**
22
+ * 半径
23
+ */
24
+ radius: number = 300
25
+
26
+ /**
27
+ * 最远节点的缩放比例,取值范围 [ 0 ~ 1 ]
28
+ * 模拟近大远小的视觉效果
29
+ */
30
+ minScale: number = 0.9
31
+
32
+ /**
33
+ * 最远节点的透明度变化,取值范围 [ 0 ~ 1 ]
34
+ */
35
+ minAlpha: number = null
36
+
37
+ /**
38
+ * 整体绕 x 轴旋转角度
39
+ * 备注: 只是影响节点的 y 坐标位置,并不会有 3d 旋转效果
40
+ */
41
+ angleX: number = 20
42
+
43
+ prepare(collectionView: YXCollectionView): void {
44
+ collectionView.scrollView.horizontal = true
45
+ collectionView.scrollView.vertical = false
46
+ let array = []
47
+ let contentSize = collectionView.scrollView.view.contentSize.clone()
48
+ let numberOfItems = collectionView.getNumberOfItems(0)
49
+ for (let item = 0; item < numberOfItems; item++) {
50
+ let indexPath = new YXIndexPath(0, item)
51
+ let attr = YXLayoutAttributes.layoutAttributesForCell(indexPath)
52
+ // 此类布局主要布局业务是在 layoutAttributesForElementsInRect ,这里只是创建出来确定一下节点大小,去 layoutAttributesForElementsInRect 里实时的调整变换效果
53
+ attr.frame.size = this.itemSize
54
+ array.push(attr)
55
+ }
56
+ this.attributes = array
57
+ contentSize.width = contentSize.width * numberOfItems * (this.loop ? 3 : 1)
58
+ this.contentSize = contentSize
59
+ }
60
+
61
+ layoutAttributesForElementsInRect(rect: math.Rect, collectionView: YXCollectionView): YXLayoutAttributes[] {
62
+ // 获取当前滚动视图偏移位置
63
+ let offset = rect.origin
64
+
65
+ // 圆点
66
+ let contentSize = collectionView.scrollView.view.contentSize.clone()
67
+ let center = new math.Vec2(contentSize.width * 0.5, contentSize.height * 0.5)
68
+
69
+ // 节点分布间隔
70
+ let angleIncrement = 360 / this.attributes.length
71
+
72
+ for (let index = 0; index < this.attributes.length; index++) {
73
+ const element = this.attributes[index];
74
+ // 当前节点角度
75
+ let itemAngle = 360 - element.indexPath.item * angleIncrement
76
+ // 从 90 度的位置开始排列
77
+ itemAngle = itemAngle + 90
78
+ // 根据当前滚动位置计算节点的偏移角度
79
+ let angleOffset = (offset.x * 1) / contentSize.width * angleIncrement
80
+ itemAngle = itemAngle + angleOffset
81
+ // 将角度转换为弧度
82
+ itemAngle = itemAngle % 360
83
+ const angle = misc.degreesToRadians(itemAngle);
84
+ // 计算节点变换
85
+ let x = center.x + this.radius * Math.cos(angle);
86
+ let z = 0 + this.radius * Math.sin(angle)
87
+ let y = center.y + z * Math.sin(misc.degreesToRadians(this.angleX))
88
+ _vec2Out.x = offset.x + x
89
+ _vec2Out.y = y
90
+ element.frame.center = _vec2Out
91
+ element.zIndex = z
92
+ // 通过缩放来补充近大远小的效果
93
+ let progress = Math.floor(Math.sin(angle) * 10000) / 10000
94
+ if (this.minScale) {
95
+ let scaleValue = this.minScale + (1 - this.minScale) * progress
96
+ element.scale = new math.Vec3(scaleValue, scaleValue, 1)
97
+ }
98
+ if (this.minAlpha) {
99
+ let opacity = this.minAlpha + (1 - this.minAlpha) * progress
100
+ element.opacity = opacity * 255
101
+ }
102
+ }
103
+
104
+ return this.attributes
105
+ }
106
+
107
+ initOffset(collectionView: YXCollectionView): void {
108
+ let x = (this.loop ? 1 : 0) * collectionView.scrollView.view.width * this.attributes.length
109
+ _vec2Out.x = x
110
+ _vec2Out.y = 0
111
+ collectionView.scrollView.scrollToOffset(_vec2Out)
112
+ }
113
+
114
+ shouldUpdateAttributesZIndex(): boolean {
115
+ return true
116
+ }
117
+
118
+ shouldUpdateAttributesOpacity(): boolean {
119
+ return true
120
+ }
121
+
122
+ shouldUpdateAttributesForBoundsChange(): boolean {
123
+ return true
124
+ }
125
+
126
+ scrollTo(indexPath: YXIndexPath, collectionView: YXCollectionView): math.Vec2 {
127
+ let leftX = (this.attributes.length * 0 + indexPath.item) * collectionView.scrollView.view.width
128
+ let midX = (this.attributes.length * 1 + indexPath.item) * collectionView.scrollView.view.width
129
+ let rightX = (this.attributes.length * 2 + indexPath.item) * collectionView.scrollView.view.width
130
+ let currentX = - collectionView.scrollView.getScrollOffset().x
131
+ // 挑出移动距离最短的一个位置
132
+ let array = [{ flag: 0, value: leftX }, { flag: 1, value: midX }, { flag: 2, value: rightX }]
133
+ let flag = array.sort((a, b) => Math.abs(currentX - a.value) - Math.abs(currentX - b.value)).shift().flag
134
+ do {
135
+ if (flag == 0) { _vec2Out.x = leftX; break }
136
+ if (flag == 1) { _vec2Out.x = midX; break }
137
+ if (flag == 2) { _vec2Out.x = rightX; break }
138
+ } while (false);
139
+ _vec2Out.y = 0
140
+ return _vec2Out
141
+ }
142
+
143
+ onScrollEnded(collectionView: YXCollectionView): void {
144
+ if (this.loop) {
145
+ let offset = collectionView.scrollView.getScrollOffset()
146
+ offset.x = - offset.x
147
+ let fullWidth = collectionView.scrollView.view.width * this.attributes.length
148
+ let x = offset.x % fullWidth + fullWidth
149
+ _vec2Out.x = x
150
+ _vec2Out.y = 0
151
+ collectionView.scrollView.scrollToOffset(_vec2Out)
152
+ collectionView.markForUpdateVisibleData(true)
153
+ }
154
+ }
155
+ }
156
+
@@ -0,0 +1,9 @@
1
+ {
2
+ "ver": "4.0.24",
3
+ "importer": "typescript",
4
+ "imported": true,
5
+ "uuid": "d84704bd-3a9d-44fb-b239-1c9b988b73ff",
6
+ "files": [],
7
+ "subMetas": {},
8
+ "userData": {}
9
+ }