@tarojs/plugin-platform-harmony-ets 4.0.0-beta.1 → 4.0.0-beta.2

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 (33) hide show
  1. package/dist/apis/device/memory.ts +10 -3
  2. package/dist/components-harmony-ets/button.ets +19 -24
  3. package/dist/components-harmony-ets/checkbox.ets +85 -7
  4. package/dist/components-harmony-ets/form.ets +93 -11
  5. package/dist/components-harmony-ets/label.ets +105 -17
  6. package/dist/components-harmony-ets/picker.ets +16 -4
  7. package/dist/components-harmony-ets/radio.ets +85 -7
  8. package/dist/components-harmony-ets/scrollView.ets +1 -1
  9. package/dist/components-harmony-ets/text.ets +3 -3
  10. package/dist/components-harmony-ets/utils/flexManager.ets +43 -6
  11. package/dist/components-harmony-ets/utils/helper.ets +1 -1
  12. package/dist/components-harmony-ets/utils/styles.ets +11 -1
  13. package/dist/components-harmony-ets/view.ets +11 -14
  14. package/dist/components-harmony-ets/webView.ets +113 -0
  15. package/dist/index.js +85 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +23 -3
  18. package/dist/runtime-ets/dom/element/index.ts +4 -1
  19. package/dist/runtime-ets/dom/element/normal.ts +1 -0
  20. package/dist/runtime-ets/dom/element/webView.ts +61 -0
  21. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +73 -0
  22. package/dist/runtime-ets/dom/stylesheet/util.ts +3 -1
  23. package/dist/runtime-ets/utils/index.ts +4 -1
  24. package/dist/runtime-framework/react/app.ts +12 -22
  25. package/dist/runtime-framework/react/index.ts +1 -0
  26. package/dist/runtime-framework/react/native-page.ts +344 -0
  27. package/dist/runtime-framework/react/page.ts +2 -2
  28. package/dist/runtime-utils.js +9 -3
  29. package/dist/runtime-utils.js.map +1 -1
  30. package/dist/runtime.js +9 -3
  31. package/dist/runtime.js.map +1 -1
  32. package/package.json +8 -8
  33. package/types/runtime.d.ts +2 -0
@@ -1,4 +1,11 @@
1
- import { temporarilyNotSupport } from '../utils'
1
+ import { hooks } from '@tarojs/runtime'
2
2
 
3
- export const onMemoryWarning = temporarilyNotSupport('onMemoryWarning')
4
- export const offMemoryWarning = temporarilyNotSupport('offMemoryWarning')
3
+ export const onMemoryWarning = (listener) => {
4
+ hooks.tap('getMemoryLevel', (res) => {
5
+ listener(res)
6
+ })
7
+ }
8
+
9
+ export const offMemoryWarning = (listener) => {
10
+ hooks.off('getMemoryLevel', listener)
11
+ }
@@ -34,7 +34,6 @@ function attrs (style: TaroStyleType) {
34
34
  minHeight: style.minHeight,
35
35
  maxHeight: style.maxHeight
36
36
  })
37
- .backgroundColor(style.backgroundColor)
38
37
  .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
39
38
  .backgroundImageSize(style.backgroundSize)
40
39
  .backgroundImagePosition(style.backgroundPosition)
@@ -44,26 +43,7 @@ function attrs (style: TaroStyleType) {
44
43
  bottom: style.borderBottomStyle,
45
44
  left: style.borderLeftStyle
46
45
  })
47
- .borderWidth({
48
- top: style.borderTopWidth,
49
- right: style.borderRightWidth,
50
- bottom: style.borderBottomWidth,
51
- left: style.borderLeftWidth
52
- })
53
- .borderColor({
54
- top: style.borderTopColor,
55
- right: style.borderRightColor,
56
- bottom: style.borderBottomColor,
57
- left: style.borderLeftColor
58
- })
59
- .borderRadius({
60
- topLeft: style.borderTopLeftRadius,
61
- topRight: style.borderTopRightRadius,
62
- bottomLeft: style.borderBottomLeftRadius,
63
- bottomRight: style.borderBottomRightRadius
64
- })
65
46
  .zIndex(style.zIndex)
66
- .opacity(style.opacity)
67
47
  .linearGradient(style.linearGradient)
68
48
  .clip(style.overflow)
69
49
  .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
@@ -106,9 +86,24 @@ function getThemeAttributes (node: TaroButtonElement): TaroStyleType {
106
86
  const type: string = _attrs.type || 'default'
107
87
 
108
88
  return {
109
- borderColor: hmStyle.borderColor || getButtonColor(node, BUTTON_THEME_COLOR.get(type).background),
110
- borderWidth: hmStyle.borderWidth || 1,
111
- borderRadius: hmStyle.borderRadius || convertNumber2VP(10),
89
+ borderColor: {
90
+ top: hmStyle.borderTopColor || getButtonColor(node, BUTTON_THEME_COLOR.get(type).background),
91
+ right: hmStyle.borderRightColor || getButtonColor(node, BUTTON_THEME_COLOR.get(type).background),
92
+ bottom: hmStyle.borderBottomColor || getButtonColor(node, BUTTON_THEME_COLOR.get(type).background),
93
+ left: hmStyle.borderLeftColor || getButtonColor(node, BUTTON_THEME_COLOR.get(type).background)
94
+ },
95
+ borderWidth: {
96
+ top: hmStyle.borderTopWidth || 1,
97
+ right: hmStyle.borderRightWidth || 1,
98
+ bottom: hmStyle.borderBottomWidth || 1,
99
+ left: hmStyle.borderLeftWidth || 1
100
+ },
101
+ borderRadius: {
102
+ topLeft: hmStyle.borderTopLeftRadius || convertNumber2VP(10),
103
+ topRight: hmStyle.borderTopRightRadius || convertNumber2VP(10),
104
+ bottomLeft: hmStyle.borderBottomLeftRadius || convertNumber2VP(10),
105
+ bottomRight: hmStyle.borderBottomRightRadius || convertNumber2VP(10)
106
+ },
112
107
  opacity: isDisabled ? 0.4 : hmStyle.opacity,
113
108
  backgroundColor: isPlain ? Color.Transparent : (hmStyle.backgroundColor || BUTTON_THEME_COLOR.get(type).background),
114
109
  color: hmStyle.color || getButtonColor(node, BUTTON_THEME_COLOR.get(type).text),
@@ -165,7 +160,7 @@ export default function TaroButton (node: TaroButtonElement) {
165
160
  })
166
161
  .type(ButtonType.Normal)
167
162
  .onClick((e: ClickEvent) => {
168
- if (['submit', 'reset'].includes(node._attrs.formType)) {
163
+ if (node._attrs.formType && ['submit', 'reset'].includes(node._attrs.formType)) {
169
164
  const eventName = node._attrs.formType + '-btn'
170
165
  const event: TaroEvent = createTaroEvent(eventName, {}, node)
171
166
  eventHandler(event, eventName, node)
@@ -154,8 +154,73 @@ export struct TaroCheckbox {
154
154
  }
155
155
  }
156
156
 
157
- @Extend(Flex)
158
- function checkboxGroupAttrs (style: TaroStyleType) {
157
+ @Extend(Column)
158
+ function checkboxGroupColumnAttrs (style: TaroStyleType) {
159
+ .id(style.id)
160
+ .key(style.id)
161
+ .flexGrow(style.flexGrow)
162
+ .flexShrink(style.flexShrink)
163
+ .flexBasis(style.flexBasis)
164
+ .alignSelf(style.alignSelf)
165
+ .padding({
166
+ top: style.paddingTop,
167
+ right: style.paddingRight,
168
+ bottom: style.paddingBottom,
169
+ left: style.paddingLeft
170
+ })
171
+ .margin({
172
+ top: style.marginTop,
173
+ right: style.marginRight,
174
+ bottom: style.marginBottom,
175
+ left: style.marginLeft
176
+ })
177
+ .width(style.width)
178
+ .height(style.height)
179
+ .constraintSize({
180
+ minWidth: style.minWidth,
181
+ maxWidth: style.maxWidth,
182
+ minHeight: style.minHeight,
183
+ maxHeight: style.maxHeight
184
+ })
185
+ .backgroundColor(style.backgroundColor)
186
+ .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
187
+ .backgroundImageSize(style.backgroundSize)
188
+ .backgroundImagePosition(style.backgroundPosition)
189
+ .borderStyle({
190
+ top: style.borderTopStyle,
191
+ right: style.borderRightStyle,
192
+ bottom: style.borderBottomStyle,
193
+ left: style.borderLeftStyle
194
+ })
195
+ .borderWidth({
196
+ top: style.borderTopWidth,
197
+ right: style.borderRightWidth,
198
+ bottom: style.borderBottomWidth,
199
+ left: style.borderLeftWidth
200
+ })
201
+ .borderColor({
202
+ top: style.borderTopColor,
203
+ right: style.borderRightColor,
204
+ bottom: style.borderBottomColor,
205
+ left: style.borderLeftColor
206
+ })
207
+ .borderRadius({
208
+ topLeft: style.borderTopLeftRadius,
209
+ topRight: style.borderTopRightRadius,
210
+ bottomLeft: style.borderBottomLeftRadius,
211
+ bottomRight: style.borderBottomRightRadius
212
+ })
213
+ .zIndex(style.zIndex)
214
+ .opacity(style.opacity)
215
+ .linearGradient(style.linearGradient)
216
+ .clip(style.overflow)
217
+ .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
218
+ .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
219
+ .transform(style.transform)
220
+ }
221
+
222
+ @Extend(Row)
223
+ function checkboxGroupRowAttrs (style: TaroStyleType) {
159
224
  .id(style.id)
160
225
  .key(style.id)
161
226
  .flexGrow(style.flexGrow)
@@ -250,12 +315,25 @@ export struct TaroCheckboxGroup {
250
315
 
251
316
  build() {
252
317
  if (this.node) {
253
- Flex(FlexManager.flexOptions(this.node)) {
254
- createLazyChildren(this.node)
318
+ if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node).direction !== FlexDirection.Column) {
319
+ Row() {
320
+ createLazyChildren(this.node)
321
+ }
322
+ .checkboxGroupRowAttrs(getNormalAttributes(this.node))
323
+ .defaultEvent()
324
+ .visibleChangeEvent()
325
+ .alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
326
+ .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
327
+ } else {
328
+ Column() {
329
+ createLazyChildren(this.node)
330
+ }
331
+ .checkboxGroupColumnAttrs(getNormalAttributes(this.node))
332
+ .defaultEvent()
333
+ .visibleChangeEvent()
334
+ .alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
335
+ .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
255
336
  }
256
- .checkboxGroupAttrs(getNormalAttributes(this.node))
257
- .defaultEvent()
258
- .visibleChangeEvent()
259
337
  }
260
338
  }
261
339
  }
@@ -7,8 +7,73 @@ import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils
7
7
 
8
8
  import type { TaroAny, TaroFormElement, TaroStyleType } from '@tarojs/runtime'
9
9
 
10
- @Extend(Flex)
11
- function attrs (style: TaroStyleType) {
10
+ @Extend(Row)
11
+ function rowAttrs (style: TaroStyleType) {
12
+ .id(style.id)
13
+ .key(style.id)
14
+ .flexGrow(style.flexGrow)
15
+ .flexShrink(style.flexShrink)
16
+ .flexBasis(style.flexBasis)
17
+ .alignSelf(style.alignSelf)
18
+ .padding({
19
+ top: style.paddingTop,
20
+ right: style.paddingRight,
21
+ bottom: style.paddingBottom,
22
+ left: style.paddingLeft
23
+ })
24
+ .margin({
25
+ top: style.marginTop,
26
+ right: style.marginRight,
27
+ bottom: style.marginBottom,
28
+ left: style.marginLeft
29
+ })
30
+ .width(style.width)
31
+ .height(style.height)
32
+ .constraintSize({
33
+ minWidth: style.minWidth,
34
+ maxWidth: style.maxWidth,
35
+ minHeight: style.minHeight,
36
+ maxHeight: style.maxHeight
37
+ })
38
+ .backgroundColor(style.backgroundColor)
39
+ .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
40
+ .backgroundImageSize(style.backgroundSize)
41
+ .backgroundImagePosition(style.backgroundPosition)
42
+ .borderStyle({
43
+ top: style.borderTopStyle,
44
+ right: style.borderRightStyle,
45
+ bottom: style.borderBottomStyle,
46
+ left: style.borderLeftStyle
47
+ })
48
+ .borderWidth({
49
+ top: style.borderTopWidth,
50
+ right: style.borderRightWidth,
51
+ bottom: style.borderBottomWidth,
52
+ left: style.borderLeftWidth
53
+ })
54
+ .borderColor({
55
+ top: style.borderTopColor,
56
+ right: style.borderRightColor,
57
+ bottom: style.borderBottomColor,
58
+ left: style.borderLeftColor
59
+ })
60
+ .borderRadius({
61
+ topLeft: style.borderTopLeftRadius,
62
+ topRight: style.borderTopRightRadius,
63
+ bottomLeft: style.borderBottomLeftRadius,
64
+ bottomRight: style.borderBottomRightRadius
65
+ })
66
+ .zIndex(style.zIndex)
67
+ .opacity(style.opacity)
68
+ .linearGradient(style.linearGradient)
69
+ .clip(style.overflow)
70
+ .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
71
+ .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
72
+ .transform(style.transform)
73
+ }
74
+
75
+ @Extend(Column)
76
+ function columnAttrs (style: TaroStyleType) {
12
77
  .id(style.id)
13
78
  .key(style.id)
14
79
  .flexGrow(style.flexGrow)
@@ -74,14 +139,31 @@ function attrs (style: TaroStyleType) {
74
139
 
75
140
  @Builder
76
141
  export default function TaroForm (node: TaroFormElement) {
77
- Flex(FlexManager.flexOptions(node)) {
78
- createLazyChildren(node)
142
+ if (FlexManager.isFlexNode(node) && FlexManager.flexOptions(node).direction !== FlexDirection.Column) {
143
+ Row() {
144
+ createLazyChildren(node)
145
+ }
146
+ .rowAttrs(getNormalAttributes(node))
147
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
148
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
149
+ .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
150
+ node._nodeInfo.areaInfo = res[1]
151
+ }))
152
+ .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
153
+ .alignItems(FlexManager.flexOptions(node).alignItems as VerticalAlign)
154
+ .justifyContent(FlexManager.flexOptions(node).justifyContent)
155
+ } else {
156
+ Column() {
157
+ createLazyChildren(node)
158
+ }
159
+ .columnAttrs(getNormalAttributes(node))
160
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
161
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
162
+ .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
163
+ node._nodeInfo.areaInfo = res[1]
164
+ }))
165
+ .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
166
+ .alignItems(FlexManager.flexOptions(node).alignItems as HorizontalAlign)
167
+ .justifyContent(FlexManager.flexOptions(node).justifyContent)
79
168
  }
80
- .attrs(getNormalAttributes(node))
81
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
82
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
83
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
84
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
85
- node._nodeInfo.areaInfo = res[1]
86
- }))
87
169
  }
@@ -7,8 +7,73 @@ import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils
7
7
 
8
8
  import type { TaroStyleType, TaroLabelElement, TaroElement, TaroAny, TaroRadioElement, TaroCheckboxElement } from '@tarojs/runtime'
9
9
 
10
- @Extend(Flex)
11
- function attrs (style: TaroStyleType) {
10
+ @Extend(Column)
11
+ function columnAttrs (style: TaroStyleType) {
12
+ .id(style.id)
13
+ .key(style.id)
14
+ .flexGrow(style.flexGrow)
15
+ .flexShrink(style.flexShrink)
16
+ .flexBasis(style.flexBasis)
17
+ .alignSelf(style.alignSelf)
18
+ .padding({
19
+ top: style.paddingTop,
20
+ right: style.paddingRight,
21
+ bottom: style.paddingBottom,
22
+ left: style.paddingLeft
23
+ })
24
+ .margin({
25
+ top: style.marginTop,
26
+ right: style.marginRight,
27
+ bottom: style.marginBottom,
28
+ left: style.marginLeft
29
+ })
30
+ .width(style.width)
31
+ .height(style.height)
32
+ .constraintSize({
33
+ minWidth: style.minWidth,
34
+ maxWidth: style.maxWidth,
35
+ minHeight: style.minHeight,
36
+ maxHeight: style.maxHeight
37
+ })
38
+ .backgroundColor(style.backgroundColor)
39
+ .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
40
+ .backgroundImageSize(style.backgroundSize)
41
+ .backgroundImagePosition(style.backgroundPosition)
42
+ .borderStyle({
43
+ top: style.borderTopStyle,
44
+ right: style.borderRightStyle,
45
+ bottom: style.borderBottomStyle,
46
+ left: style.borderLeftStyle
47
+ })
48
+ .borderWidth({
49
+ top: style.borderTopWidth,
50
+ right: style.borderRightWidth,
51
+ bottom: style.borderBottomWidth,
52
+ left: style.borderLeftWidth
53
+ })
54
+ .borderColor({
55
+ top: style.borderTopColor,
56
+ right: style.borderRightColor,
57
+ bottom: style.borderBottomColor,
58
+ left: style.borderLeftColor
59
+ })
60
+ .borderRadius({
61
+ topLeft: style.borderTopLeftRadius,
62
+ topRight: style.borderTopRightRadius,
63
+ bottomLeft: style.borderBottomLeftRadius,
64
+ bottomRight: style.borderBottomRightRadius
65
+ })
66
+ .zIndex(style.zIndex)
67
+ .opacity(style.opacity)
68
+ .linearGradient(style.linearGradient)
69
+ .clip(style.overflow)
70
+ .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
71
+ .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
72
+ .transform(style.transform)
73
+ }
74
+
75
+ @Extend(Row)
76
+ function rowAttrs (style: TaroStyleType) {
12
77
  .id(style.id)
13
78
  .key(style.id)
14
79
  .flexGrow(style.flexGrow)
@@ -100,20 +165,43 @@ function handleTargetChange (id: string) {
100
165
 
101
166
  @Builder
102
167
  export default function TaroLabel (node: TaroLabelElement) {
103
- Flex(FlexManager.flexOptions(node)) {
104
- createLazyChildren(node)
168
+ if (FlexManager.isFlexNode(node) && FlexManager.flexOptions(node).direction !== FlexDirection.Column) {
169
+ Row() {
170
+ createLazyChildren(node)
171
+ }
172
+ .rowAttrs(getNormalAttributes(node))
173
+ .onClick((e: ClickEvent) => {
174
+ const firstChild: TaroElement | null = node.childNodes[0] as TaroElement | null
175
+ const id: string = node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
176
+
177
+ handleTargetChange(id)
178
+ eventHandler(e, 'click', node)
179
+ })
180
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
181
+ .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
182
+ node._nodeInfo.areaInfo = res[1]
183
+ }))
184
+ .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
185
+ .alignItems(FlexManager.flexOptions(node).alignItems as VerticalAlign)
186
+ .justifyContent(FlexManager.flexOptions(node).justifyContent)
187
+ } else {
188
+ Column() {
189
+ createLazyChildren(node)
190
+ }
191
+ .columnAttrs(getNormalAttributes(node))
192
+ .onClick((e: ClickEvent) => {
193
+ const firstChild: TaroElement | null = node.childNodes[0] as TaroElement | null
194
+ const id: string = node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
195
+
196
+ handleTargetChange(id)
197
+ eventHandler(e, 'click', node)
198
+ })
199
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
200
+ .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
201
+ node._nodeInfo.areaInfo = res[1]
202
+ }))
203
+ .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
204
+ .alignItems(FlexManager.flexOptions(node).alignItems as HorizontalAlign)
205
+ .justifyContent(FlexManager.flexOptions(node).justifyContent)
105
206
  }
106
- .attrs(getNormalAttributes(node))
107
- .onClick((e: ClickEvent) => {
108
- const firstChild: TaroElement | null = node.childNodes[0] as TaroElement | null
109
- const id: string = node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
110
-
111
- handleTargetChange(id)
112
- eventHandler(e, 'click', node)
113
- })
114
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
115
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
116
- node._nodeInfo.areaInfo = res[1]
117
- }))
118
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
119
207
  }
@@ -427,11 +427,23 @@ export default struct TaroPicker {
427
427
 
428
428
  build() {
429
429
  if (this.node) {
430
- Flex(FlexManager.flexOptions(this.node)) {
431
- createLazyChildren(this.node)
430
+ if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node).direction !== FlexDirection.Column) {
431
+ Row() {
432
+ createLazyChildren(this.node)
433
+ }
434
+ .defaultEvent()
435
+ .visibleChangeEvent()
436
+ .alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
437
+ .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
438
+ } else {
439
+ Column() {
440
+ createLazyChildren(this.node)
441
+ }
442
+ .defaultEvent()
443
+ .visibleChangeEvent()
444
+ .alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
445
+ .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
432
446
  }
433
- .defaultEvent()
434
- .visibleChangeEvent()
435
447
  }
436
448
  }
437
449
  }
@@ -156,8 +156,73 @@ export struct TaroRadio {
156
156
  }
157
157
  }
158
158
 
159
- @Extend(Flex)
160
- function radioGroupAttrs (style: TaroStyleType) {
159
+ @Extend(Column)
160
+ function radioGroupColumnAttrs (style: TaroStyleType) {
161
+ .id(style.id)
162
+ .key(style.id)
163
+ .flexGrow(style.flexGrow)
164
+ .flexShrink(style.flexShrink)
165
+ .flexBasis(style.flexBasis)
166
+ .alignSelf(style.alignSelf)
167
+ .padding({
168
+ top: style.paddingTop,
169
+ right: style.paddingRight,
170
+ bottom: style.paddingBottom,
171
+ left: style.paddingLeft
172
+ })
173
+ .margin({
174
+ top: style.marginTop,
175
+ right: style.marginRight,
176
+ bottom: style.marginBottom,
177
+ left: style.marginLeft
178
+ })
179
+ .width(style.width)
180
+ .height(style.height)
181
+ .constraintSize({
182
+ minWidth: style.minWidth,
183
+ maxWidth: style.maxWidth,
184
+ minHeight: style.minHeight,
185
+ maxHeight: style.maxHeight
186
+ })
187
+ .backgroundColor(style.backgroundColor)
188
+ .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
189
+ .backgroundImageSize(style.backgroundSize)
190
+ .backgroundImagePosition(style.backgroundPosition)
191
+ .borderStyle({
192
+ top: style.borderTopStyle,
193
+ right: style.borderRightStyle,
194
+ bottom: style.borderBottomStyle,
195
+ left: style.borderLeftStyle
196
+ })
197
+ .borderWidth({
198
+ top: style.borderTopWidth,
199
+ right: style.borderRightWidth,
200
+ bottom: style.borderBottomWidth,
201
+ left: style.borderLeftWidth
202
+ })
203
+ .borderColor({
204
+ top: style.borderTopColor,
205
+ right: style.borderRightColor,
206
+ bottom: style.borderBottomColor,
207
+ left: style.borderLeftColor
208
+ })
209
+ .borderRadius({
210
+ topLeft: style.borderTopLeftRadius,
211
+ topRight: style.borderTopRightRadius,
212
+ bottomLeft: style.borderBottomLeftRadius,
213
+ bottomRight: style.borderBottomRightRadius
214
+ })
215
+ .zIndex(style.zIndex)
216
+ .opacity(style.opacity)
217
+ .linearGradient(style.linearGradient)
218
+ .clip(style.overflow)
219
+ .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
220
+ .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
221
+ .transform(style.transform)
222
+ }
223
+
224
+ @Extend(Row)
225
+ function radioGroupRowAttrs (style: TaroStyleType) {
161
226
  .id(style.id)
162
227
  .key(style.id)
163
228
  .flexGrow(style.flexGrow)
@@ -253,12 +318,25 @@ export struct TaroRadioGroup {
253
318
 
254
319
  build() {
255
320
  if (this.node) {
256
- Flex(FlexManager.flexOptions(this.node)) {
257
- createLazyChildren(this.node)
321
+ if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node).direction !== FlexDirection.Column) {
322
+ Row() {
323
+ createLazyChildren(this.node)
324
+ }
325
+ .radioGroupRowAttrs(getNormalAttributes(this.node))
326
+ .defaultEvent()
327
+ .visibleChangeEvent()
328
+ .alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
329
+ .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
330
+ } else {
331
+ Column() {
332
+ createLazyChildren(this.node)
333
+ }
334
+ .radioGroupColumnAttrs(getNormalAttributes(this.node))
335
+ .defaultEvent()
336
+ .visibleChangeEvent()
337
+ .alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
338
+ .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
258
339
  }
259
- .radioGroupAttrs(getNormalAttributes(this.node))
260
- .defaultEvent()
261
- .visibleChangeEvent()
262
340
  }
263
341
  }
264
342
  }
@@ -168,7 +168,7 @@ function getScrollable (node: TaroScrollViewElement) {
168
168
  }
169
169
 
170
170
  function handleScrollEvent (node: TaroScrollViewElement, eventName = 'scroll', xOffset?: number, yOffset?: number) {
171
- const currentOffset: ScrollViewCurrentOffset = node.scroller.currentOffset()
171
+ const currentOffset = node.scroller.currentOffset() as ScrollViewCurrentOffset
172
172
  const currentXOffset = currentOffset.xOffset
173
173
  const currentYOffset = currentOffset.yOffset
174
174
  const value: ScrollViewEvent = {
@@ -119,12 +119,12 @@ export default function TaroText (node: TaroTextElement) {
119
119
  } else {
120
120
  Text(node.textContent)
121
121
  .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
122
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
123
- node._nodeInfo.areaInfo = res[1]
124
- }))
125
122
  .textNormalStyle(getNormalAttributes(node))
126
123
  .textNormalFontStyle(getNormalAttributes(node))
127
124
  .textSpecialFontStyle(getFontAttributes(node))
128
125
  .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
126
+ .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
127
+ node._nodeInfo.areaInfo = res[1]
128
+ }))
129
129
  }
130
130
  }
@@ -1,20 +1,57 @@
1
- import type { TaroAny, TaroElement } from '@tarojs/runtime'
1
+ import type { TaroElement } from '@tarojs/runtime'
2
+
3
+ interface IFlexOptions {
4
+ direction: FlexDirection,
5
+ justifyContent: FlexAlign,
6
+ alignItems: VerticalAlign | HorizontalAlign,
7
+ // Row 和 Column 不支持下面两个属性
8
+ // wrap: FlexWrap,
9
+ // alignContent: FlexAlignContent
10
+ }
2
11
 
3
12
  class FlexManager {
4
- static flexOptions (node: TaroElement): FlexOptions {
13
+ static isFlexNode (node: TaroElement): boolean {
14
+ return !!node.hmStyle?.display?.includes('flex')
15
+ }
16
+
17
+ static convertFlexAlignItemsToColumnOrRow (direction: FlexDirection, alignItems: ItemAlign | undefined): VerticalAlign | HorizontalAlign {
18
+ if (direction === FlexDirection.Column) {
19
+ switch (alignItems) {
20
+ case ItemAlign.Start:
21
+ return HorizontalAlign.Start
22
+ case ItemAlign.End:
23
+ return HorizontalAlign.End
24
+ default:
25
+ return HorizontalAlign.Center
26
+ }
27
+ } else {
28
+ switch (alignItems) {
29
+ case ItemAlign.Start:
30
+ return VerticalAlign.Top
31
+ case ItemAlign.End:
32
+ return VerticalAlign.Bottom
33
+ default:
34
+ return VerticalAlign.Center
35
+ }
36
+ }
37
+ }
38
+
39
+ static flexOptions (node: TaroElement): IFlexOptions {
5
40
  const hmStyle = node.hmStyle
41
+ const isFlex = FlexManager.isFlexNode(node)
42
+ const justifyContent: FlexAlign = isFlex ? (hmStyle.justifyContent || FlexAlign.Center) : FlexAlign.Start
6
43
 
7
44
  let flexDirection = hmStyle.flexDirection
8
45
  if (!flexDirection && flexDirection !== 0) {
9
46
  flexDirection = hmStyle.display === 'flex' ? FlexDirection.Row : FlexDirection.Column
10
47
  }
11
48
 
49
+ const alignItems = isFlex ? FlexManager.convertFlexAlignItemsToColumnOrRow(flexDirection, hmStyle.alignItems) : HorizontalAlign.Start
50
+
12
51
  return {
52
+ alignItems,
53
+ justifyContent,
13
54
  direction: flexDirection,
14
- justifyContent: hmStyle.justifyContent,
15
- alignItems: hmStyle.alignItems,
16
- wrap: hmStyle.flexWrap,
17
- alignContent: hmStyle.alignContent,
18
55
  }
19
56
  }
20
57
  }
@@ -20,7 +20,7 @@ export const parseStyles = (styles = ''): Record<string, string> => {
20
20
  return styleObj
21
21
  }
22
22
 
23
- export function shouldBindEvent (cb: Func, node: TaroElement, eventNames: string[], disabled = false) {
23
+ export function shouldBindEvent (cb: Func, node: TaroElement | null, eventNames: string[], disabled = false) {
24
24
  if (!node || node._attrs?.disabled || disabled) return null
25
25
  if (!node.__listeners) {
26
26
  return null