@tarojs/plugin-platform-harmony-ets 4.0.0-beta.11 → 4.0.0-beta.111

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 (129) hide show
  1. package/dist/apis/base/system.ts +73 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +16 -8
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +25 -17
  6. package/dist/apis/media/image/index.ts +1 -1
  7. package/dist/apis/storage/index.ts +135 -131
  8. package/dist/apis/ui/animation/animation.ts +71 -29
  9. package/dist/apis/ui/background.ts +2 -1
  10. package/dist/apis/ui/interaction/index.ts +42 -59
  11. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  12. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  13. package/dist/apis/ui/scroll/index.ts +5 -5
  14. package/dist/apis/ui/tab-bar.ts +3 -3
  15. package/dist/apis/utils/index.ts +2 -1
  16. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  17. package/dist/apis/wxml/selectorQuery.ts +26 -13
  18. package/dist/components-harmony-ets/button.ets +35 -8
  19. package/dist/components-harmony-ets/canvas.ets +51 -0
  20. package/dist/components-harmony-ets/checkbox.ets +70 -60
  21. package/dist/components-harmony-ets/form.ets +35 -16
  22. package/dist/components-harmony-ets/icon.ets +16 -8
  23. package/dist/components-harmony-ets/image.ets +22 -6
  24. package/dist/components-harmony-ets/index.ets +92 -0
  25. package/dist/components-harmony-ets/innerHtml.ets +6 -5
  26. package/dist/components-harmony-ets/input.ets +62 -40
  27. package/dist/components-harmony-ets/label.ets +44 -21
  28. package/dist/components-harmony-ets/listView.ets +31 -0
  29. package/dist/components-harmony-ets/movableArea.ets +112 -53
  30. package/dist/components-harmony-ets/movableView.ets +75 -48
  31. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  32. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  33. package/dist/components-harmony-ets/picker.ets +41 -38
  34. package/dist/components-harmony-ets/progress.ets +31 -24
  35. package/dist/components-harmony-ets/pseudo.ets +80 -0
  36. package/dist/components-harmony-ets/radio.ets +76 -66
  37. package/dist/components-harmony-ets/richText.ets +4 -25
  38. package/dist/components-harmony-ets/scrollList.ets +103 -0
  39. package/dist/components-harmony-ets/scrollView.ets +47 -47
  40. package/dist/components-harmony-ets/slider.ets +18 -14
  41. package/dist/components-harmony-ets/stickySection.ets +42 -0
  42. package/dist/components-harmony-ets/style.ets +386 -130
  43. package/dist/components-harmony-ets/swiper.ets +41 -4
  44. package/dist/components-harmony-ets/switch.ets +35 -31
  45. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  46. package/dist/components-harmony-ets/text.ets +102 -46
  47. package/dist/components-harmony-ets/textArea.ets +49 -34
  48. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  49. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  50. package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
  51. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  52. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  53. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  54. package/dist/components-harmony-ets/utils/index.ts +54 -50
  55. package/dist/components-harmony-ets/utils/styles.ets +170 -93
  56. package/dist/components-harmony-ets/video.ets +27 -19
  57. package/dist/components-harmony-ets/view.ets +47 -40
  58. package/dist/components-harmony-ets/webView.ets +6 -5
  59. package/dist/index.d.ts +152 -0
  60. package/dist/index.js +69 -43
  61. package/dist/index.js.map +1 -1
  62. package/dist/runtime-ets/bom/document.ts +6 -4
  63. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  64. package/dist/runtime-ets/bom/window.ts +7 -0
  65. package/dist/runtime-ets/current.ts +5 -1
  66. package/dist/runtime-ets/dom/bind.ts +28 -12
  67. package/dist/runtime-ets/dom/class-list.ts +2 -2
  68. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  69. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  70. package/dist/runtime-ets/dom/document.ts +8 -11
  71. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  72. package/dist/runtime-ets/dom/element/element.ts +376 -56
  73. package/dist/runtime-ets/dom/element/form.ts +20 -22
  74. package/dist/runtime-ets/dom/element/index.ts +22 -2
  75. package/dist/runtime-ets/dom/element/movableArea.ts +0 -1
  76. package/dist/runtime-ets/dom/element/movableView.ts +234 -2
  77. package/dist/runtime-ets/dom/element/normal.ts +27 -6
  78. package/dist/runtime-ets/dom/element/progress.ts +0 -2
  79. package/dist/runtime-ets/dom/element/text.ts +0 -8
  80. package/dist/runtime-ets/dom/element/video.ts +4 -4
  81. package/dist/runtime-ets/dom/element/webView.ts +4 -5
  82. package/dist/runtime-ets/dom/event.ts +3 -5
  83. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  84. package/dist/runtime-ets/dom/node.ts +51 -19
  85. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
  86. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  87. package/dist/runtime-ets/dom/stylesheet/type.ts +51 -9
  88. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  89. package/dist/runtime-ets/index.ts +2 -1
  90. package/dist/runtime-ets/interface/event.ts +1 -1
  91. package/dist/runtime-ets/utils/index.ts +74 -13
  92. package/dist/runtime-ets/utils/info.ts +2 -2
  93. package/dist/runtime-framework/react/app.ts +15 -10
  94. package/dist/runtime-framework/react/hooks.ts +0 -1
  95. package/dist/runtime-framework/react/index.ts +0 -2
  96. package/dist/runtime-framework/react/native-page.ts +185 -78
  97. package/dist/runtime-framework/react/page.ts +4 -9
  98. package/dist/runtime-framework/react/utils/index.ts +3 -3
  99. package/dist/runtime-framework/solid/app.ts +30 -46
  100. package/dist/runtime-framework/solid/connect.ts +21 -3
  101. package/dist/runtime-framework/solid/hooks.ts +16 -11
  102. package/dist/runtime-framework/solid/index.ts +6 -2
  103. package/dist/runtime-framework/solid/page.ts +85 -31
  104. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  105. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  106. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  107. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  108. package/dist/runtime-utils.d.ts +827 -0
  109. package/dist/runtime-utils.js +425 -253
  110. package/dist/runtime-utils.js.map +1 -1
  111. package/dist/runtime.d.ts +1 -0
  112. package/dist/runtime.js +425 -253
  113. package/dist/runtime.js.map +1 -1
  114. package/index.js +3 -1
  115. package/package.json +14 -15
  116. package/static/media/cancel.svg +1 -1
  117. package/static/media/circle.svg +1 -1
  118. package/static/media/clear.svg +1 -1
  119. package/static/media/download.svg +1 -1
  120. package/static/media/info.svg +1 -1
  121. package/static/media/info_circle.svg +1 -1
  122. package/static/media/search.svg +1 -1
  123. package/static/media/success.svg +1 -1
  124. package/static/media/success_no_circle.svg +1 -1
  125. package/static/media/warn.svg +1 -1
  126. package/types/harmony.d.ts +4 -0
  127. package/types/index.d.ts +4 -0
  128. package/types/runtime.d.ts +1 -1
  129. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,13 +1,15 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
3
  import commonStyleModify from './style'
4
- import { getNormalAttributes, parseStyles, shouldBindEvent, getNodeThresholds } from './utils/helper'
4
+ import { parseStyles, shouldBindEvent, getNodeThresholds, getStyleAttr } from './utils/helper'
5
5
  import { INPUT_TYPE_MAP, INPUT_CONFIRM_MAP } from './utils/constant/style'
6
6
 
7
7
  import type { TaroStyleType, TaroAny, TaroInputElement, TaroEvent } from '@tarojs/runtime'
8
8
 
9
9
  interface InputAttrs {
10
10
  textAlign?: TextAlign
11
+ autoFocus?: boolean
12
+ disabled?: boolean
11
13
  }
12
14
 
13
15
  @Extend(TextInput)
@@ -22,12 +24,15 @@ function styles (style: TaroStyleType) {
22
24
  @Extend(TextInput)
23
25
  function attrs(attr: InputAttrs) {
24
26
  .textAlign(attr.textAlign)
27
+ .defaultFocus(attr.autoFocus)
28
+ .enabled(!attr.disabled)
25
29
  }
26
30
 
27
-
28
31
  function getAttributes(node: TaroInputElement): InputAttrs {
29
32
  return {
30
33
  textAlign: node.hmStyle.textAlign,
34
+ autoFocus: node._attrs.autoFocus || node._attrs.focus || false,
35
+ disabled: node._attrs.disabled || false,
31
36
  }
32
37
  }
33
38
 
@@ -44,11 +49,26 @@ function getPlaceholderColor (node: TaroInputElement): string {
44
49
  return placeholderTextColor || parseStyles(placeholderStyle)?.color
45
50
  }
46
51
 
52
+ function getPlaceholderFont(node: TaroInputElement): Font {
53
+ const placeholderStyle: string = node._attrs.placeholderStyle || ''
54
+ const styles = parseStyles(placeholderStyle);
55
+ if (styles) {
56
+ return {
57
+ size: styles.fontSize,
58
+ }
59
+ }
60
+
61
+ return {}
62
+ }
63
+
47
64
  @Component
48
65
  export default struct TaroInput {
49
66
  @State value: string = ''
50
67
 
68
+ @Builder customBuilder() {}
69
+ @BuilderParam createLazyChildren: (node: TaroInputElement, layer?: number) => void = this.customBuilder
51
70
  @ObjectLink node: TaroInputElement
71
+ @State overwriteStyle: Record<string, TaroAny> = {}
52
72
 
53
73
  aboutToAppear () {
54
74
  if (this.node) {
@@ -63,43 +83,45 @@ export default struct TaroInput {
63
83
  }
64
84
 
65
85
  build () {
66
- if (this.node) {
67
- TextInput({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
68
- .key(this.node._nid)
69
- .type(getInputType(this.node))
70
- .maxLength(Number(this.node._attrs?.maxlength) || null)
71
- .placeholderColor(getPlaceholderColor(this.node))
72
- .enterKeyType(INPUT_CONFIRM_MAP.get(this.node._attrs?.confirmType) || EnterKeyType.Done)
73
- .attributeModifier(commonStyleModify.setNode(this.node))
74
- .styles(getNormalAttributes(this.node))
75
- .attrs(getAttributes(this.node))
76
- .onChange((value: string) => {
77
- const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
78
-
79
- this.value = value
80
- this.node?.updateFormWidgetValue(value)
81
- eventHandler(event, 'input', this.node)
82
- })
83
- .onSubmit(() => {
84
- const event: TaroEvent = createTaroEvent('confirm', { detail: { value: this.value } }, this.node)
85
- eventHandler(event, 'confirm', this.node)
86
- })
87
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
88
- .onBlur(() => {
89
- const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.value } }, this.node)
90
- eventHandler(event, 'blur', this.node)
91
- })
92
- .onFocus(() => {
93
- const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.value, height: this.node?._height } }, this.node)
94
-
95
- eventHandler(event, 'focus', this.node)
96
- })
97
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
98
- if (this.node) {
99
- this.node._nodeInfo.areaInfo = res[1]
100
- }
101
- }))
102
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
103
- }
86
+ TextInput({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
87
+ .key(this.node._nid.toString())
88
+ .type(getInputType(this.node))
89
+ .maxLength(Number(this.node._attrs?.maxlength) || null)
90
+ .placeholderColor(getPlaceholderColor(this.node))
91
+ .placeholderFont(getPlaceholderFont(this.node))
92
+ .enterKeyType(INPUT_CONFIRM_MAP.get(this.node._attrs?.confirmType) || EnterKeyType.Done)
93
+ .padding(0) // Note: 移出 Input 默认 padding 设置
94
+ .backgroundColor(getStyleAttr(this.node, "backgroundColor"))//
95
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
96
+ .styles(this.node?.hmStyle)
97
+ .attrs(getAttributes(this.node))
98
+ .onChange((value: string) => {
99
+ const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
100
+
101
+ this.value = value
102
+ this.node?.updateFormWidgetValue(value)
103
+ eventHandler(event, 'input', this.node)
104
+ })
105
+ .onSubmit(() => {
106
+ const event: TaroEvent = createTaroEvent('confirm', { detail: { value: this.value } }, this.node)
107
+ eventHandler(event, 'confirm', this.node)
108
+ })
109
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
110
+ .onBlur(() => {
111
+ const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.value } }, this.node)
112
+ eventHandler(event, 'blur', this.node)
113
+ })
114
+ .onFocus(() => {
115
+ const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.value, height: this.node?._height } }, this.node)
116
+
117
+ eventHandler(event, 'focus', this.node)
118
+ })
119
+ .enableKeyboardOnFocus(typeof (this.node._attrs as TaroAny)?.enableKeyboardOnFocus === 'undefined' ? true : (this.node._attrs as TaroAny).enableKeyboardOnFocus)
120
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
121
+ if (this.node) {
122
+ this.node._nodeInfo.areaInfo = res[1]
123
+ }
124
+ }))
125
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
104
126
  }
105
127
  }
@@ -1,18 +1,19 @@
1
1
  import { Current, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, getPageScrollerOrNode, AREA_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
2
 
3
- import commonStyleModify from './style'
4
- import { createLazyChildren } from './render'
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
4
+
5
5
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
6
- import { FlexManager } from './utils/FlexManager'
7
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
6
+ import { FlexManager } from './utils/flexManager'
7
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
8
8
 
9
9
  import type { TaroLabelElement, TaroElement, TaroAny, TaroRadioElement, TaroCheckboxElement } from '@tarojs/runtime'
10
+ import { isUndefined } from '@tarojs/shared'
10
11
 
11
12
  function handleTargetChange (id: string) {
12
13
  const taro: TaroAny = Current.taro
13
14
  const page: TaroAny = taro.getCurrentInstance().page
14
- const currentPageNode: TaroElement = getPageScrollerOrNode(page.node, page)
15
- const node: TaroElement | null = currentPageNode.getElementById(id)
15
+ const currentPageNode: TaroElement = getPageScrollerOrNode(page?.node, page)
16
+ const node: TaroElement | null = currentPageNode?.getElementById(id)
16
17
 
17
18
  if (!node) return
18
19
 
@@ -34,49 +35,71 @@ function handleTargetChange (id: string) {
34
35
  }
35
36
  }
36
37
 
37
-
38
38
  @Component
39
39
  export default struct TaroLabel {
40
- @ObjectLink node:TaroLabelElement
40
+ @Builder customBuilder() {}
41
+ @BuilderParam createLazyChildren: (node: TaroLabelElement, layer?: number) => void = this.customBuilder
42
+ @ObjectLink node: TaroLabelElement
43
+ @State overwriteStyle: Record<string, TaroAny> = {}
44
+
45
+ aboutToAppear(): void {
46
+ if (this.node) {
47
+ this.node._instance = this
48
+ }
49
+ }
50
+
41
51
  build() {
42
- if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node).direction !== FlexDirection.Column) {
52
+ if (FlexManager.useFlexLayout(this.node)) {
53
+ Flex(FlexManager.flexOptions(this.node)) {
54
+ this.createLazyChildren(this.node, 0)
55
+ }
56
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
57
+ .onClick((e: ClickEvent) => {
58
+ const firstChild: TaroElement | null = this.node.childNodes[0] as TaroElement | null
59
+ const id: string = this.node._attrs.for || firstChild?._attrs.id || firstChild?._nid.toString() || ''
60
+
61
+ handleTargetChange(id)
62
+ eventHandler(e, 'click', this.node)
63
+ })
64
+ .onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
65
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
66
+ this.node._nodeInfo.areaInfo = res[1]
67
+ }))
68
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
69
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
43
70
  Row() {
44
- createLazyChildren(this.node)
71
+ this.createLazyChildren(this.node, 0)
45
72
  }
46
- .attributeModifier(commonStyleModify.setNode(this.node))
73
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
47
74
  .onClick((e: ClickEvent) => {
48
75
  const firstChild: TaroElement | null = this.node.childNodes[0] as TaroElement | null
49
- const id: string = this.node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
76
+ const id: string = this.node._attrs.for || firstChild?._attrs.id || firstChild?._nid.toString() || ''
50
77
 
51
78
  handleTargetChange(id)
52
79
  eventHandler(e, 'click', this.node)
53
80
  })
54
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
81
+ .onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
55
82
  .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
56
83
  this.node._nodeInfo.areaInfo = res[1]
57
84
  }))
58
85
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
59
- .alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
60
- .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
61
86
  } else {
62
87
  Column() {
63
- createLazyChildren(this.node)
88
+ this.createLazyChildren(this.node, 0)
64
89
  }
65
- .attributeModifier(commonStyleModify.setNode(this.node))
90
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
66
91
  .onClick((e: ClickEvent) => {
67
92
  const firstChild: TaroElement | null = this.node.childNodes[0] as TaroElement | null
68
- const id: string = this.node._attrs.for || firstChild?._attrs.id || firstChild?._nid || ''
93
+ const id: string = this.node._attrs.for || firstChild?._attrs.id || firstChild?._nid.toString() || ''
69
94
 
70
95
  handleTargetChange(id)
71
96
  eventHandler(e, 'click', this.node)
72
97
  })
73
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
98
+ .onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
74
99
  .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
75
100
  this.node._nodeInfo.areaInfo = res[1]
76
101
  }))
77
102
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
78
- .alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
79
- .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
80
103
  }
81
104
  }
82
105
  }
@@ -0,0 +1,31 @@
1
+ import commonStyleModify from './style'
2
+
3
+ import type { TaroViewElement, TaroAny } from '@tarojs/runtime'
4
+
5
+ @Reusable
6
+ @Component
7
+ export default struct TaroListView {
8
+ @Builder customBuilder() {}
9
+ @BuilderParam createLazyChildren: (node: TaroViewElement, layer?: number) => void = this.customBuilder
10
+ @ObjectLink node: TaroViewElement
11
+ @State overwriteStyle: Record<string, TaroAny> = {}
12
+
13
+ aboutToAppear(): void {
14
+ if (this.node) {
15
+ this.node._instance = this
16
+ }
17
+ }
18
+
19
+ aboutToReuse(params: TaroAny): void {
20
+ // this.node = params.node;
21
+ }
22
+
23
+ build() {
24
+ ListItem() {
25
+ Stack() {
26
+ this.createLazyChildren(this.node, 0)
27
+ }
28
+ }
29
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
30
+ }
31
+ }
@@ -1,67 +1,126 @@
1
- import type { TaroMovableAreaElement, TaroStyleType } from '@tarojs/runtime'
2
- import commonStyleModify from './style'
3
- import { createLazyChildren } from './render'
1
+ import type { TaroAny, TaroMovableAreaElement, TaroMovableViewElement } from '@tarojs/runtime'
2
+ import { isTaroMovableViewElement } from '@tarojs/runtime'
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
4
4
 
5
- import { FlexManager } from './utils/FlexManager'
6
- import { getNormalAttributes } from './utils/helper'
7
-
8
-
9
- @Extend(Row)
10
- function rowAttrs(style: TaroStyleType) {
11
- .constraintSize({
12
- minWidth: style.minWidth || style.width,
13
- maxWidth: style.maxWidth,
14
- minHeight: style.minHeight,
15
- maxHeight: style.maxHeight
16
- })
17
- }
18
-
19
- @Extend(Column)
20
- function columnAttrs(style: TaroStyleType) {
21
- .constraintSize({
22
- minWidth: style.minWidth,
23
- maxWidth: style.maxWidth,
24
- minHeight: style.minHeight || style.height,
25
- maxHeight: style.maxHeight
26
- })
27
- }
5
+ import { FlexManager } from './utils/flexManager'
6
+ import { isUndefined } from '@tarojs/shared'
28
7
 
29
8
  @Component
30
9
  export default struct TaroMovableArea {
10
+ @Builder
11
+ customBuilder() {
12
+ }
13
+
14
+ @BuilderParam createLazyChildren: (node: TaroMovableAreaElement, layer?: number) => void = this.customBuilder
31
15
  @ObjectLink node: TaroMovableAreaElement
16
+ @State overwriteStyle: Record<string, TaroAny> = {}
17
+
18
+ aboutToAppear(): void {
19
+ if (this.node) {
20
+ this.node._instance = this
21
+ }
22
+ }
23
+
24
+
25
+
32
26
 
33
- @Provide areaWidth: Length = 0
34
- @Provide areaHeight: Length = 0
35
27
 
36
28
  build() {
37
- if (this.node) {
38
- if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node).direction !== FlexDirection.Column) {
39
- Row() {
40
- createLazyChildren(this.node)
41
- }
42
- .attributeModifier(commonStyleModify.setNode(this.node))
43
- .rowAttrs(getNormalAttributes(this.node))
44
- .alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
45
- .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
46
- .clip(true)
47
- .onAreaChange((oldValue: Area, newValue: Area) => {
48
- this.areaWidth = newValue.width
49
- this.areaHeight = newValue.height
29
+ if (FlexManager.useFlexLayout(this.node)) {
30
+ Flex(FlexManager.flexOptions(this.node)) {
31
+ this.createLazyChildren(this.node, 0)
32
+ }
33
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
34
+ .clip(true)
35
+ .onSizeChange((oldValue: SizeOptions, newValue: SizeOptions) => {
36
+ sizeChangeHandle(this.node, newValue)
37
+ })
38
+ .gesture(
39
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
40
+ this.node.childNodes.forEach(item => {
41
+ if (isTaroMovableViewElement(item)) {
42
+ item.startScale()
43
+ }
44
+ })
45
+ }).onActionUpdate((event) => {
46
+ const scaleArea = this.node.getAttribute('scaleArea')
47
+ if (scaleArea) {
48
+ this.node.childNodes.forEach(item => {
49
+ if (isTaroMovableViewElement(item)) {
50
+ item.doScale(event.scale)
51
+ }
52
+ })
53
+ }
50
54
  })
51
- } else {
52
- Column() {
53
- createLazyChildren(this.node)
54
- }
55
- .attributeModifier(commonStyleModify.setNode(this.node))
56
- .columnAttrs(getNormalAttributes(this.node))
57
- .alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
58
- .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
59
- .clip(true)
60
- .onAreaChange((oldValue: Area, newValue: Area) => {
61
- this.areaWidth = newValue.width
62
- this.areaHeight = newValue.height
55
+ )
56
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
57
+ Row() {
58
+ this.createLazyChildren(this.node, 0)
59
+ }
60
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
61
+ .clip(true)
62
+ .onSizeChange((oldValue: SizeOptions, newValue: SizeOptions) => {
63
+ sizeChangeHandle(this.node, newValue)
64
+ })
65
+ .gesture(
66
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
67
+ this.node.childNodes.forEach(item => {
68
+ if (isTaroMovableViewElement(item)) {
69
+ item.startScale()
70
+ }
71
+ })
72
+ }).onActionUpdate((event) => {
73
+ const scaleArea = this.node.getAttribute('scaleArea')
74
+ if (scaleArea) {
75
+ this.node.childNodes.forEach(item => {
76
+ if (isTaroMovableViewElement(item)) {
77
+ item.doScale(event.scale)
78
+ }
79
+ })
80
+ }
63
81
  })
82
+ )
83
+ } else {
84
+ Column() {
85
+ this.createLazyChildren(this.node, 0)
64
86
  }
87
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
88
+ .clip(true)
89
+ .onSizeChange((oldValue: SizeOptions, newValue: SizeOptions) => {
90
+ sizeChangeHandle(this.node, newValue)
91
+ })
92
+ .gesture(
93
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
94
+ this.node.childNodes.forEach(item => {
95
+ if (isTaroMovableViewElement(item)) {
96
+ item.startScale()
97
+ }
98
+ })
99
+ }).onActionUpdate((event) => {
100
+ const scaleArea = this.node.getAttribute('scaleArea')
101
+ if (scaleArea) {
102
+ this.node.childNodes.forEach(item => {
103
+ if (isTaroMovableViewElement(item)) {
104
+ item.doScale(event.scale)
105
+ }
106
+ })
107
+ }
108
+ })
109
+ )
65
110
  }
66
111
  }
67
112
  }
113
+
114
+
115
+ function sizeChangeHandle(node: TaroMovableAreaElement, newValue: Area | SizeOptions) {
116
+ node.childNodes.forEach(item => {
117
+ if (isTaroMovableViewElement(item)) {
118
+ if (item.area?.w !== Number(newValue.width) || item.area?.h !== Number(newValue.height)) {
119
+ item.area = {
120
+ w: Number(newValue.width),
121
+ h: Number(newValue.height)
122
+ }
123
+ }
124
+ }
125
+ })
126
+ }
@@ -1,66 +1,93 @@
1
- import type { TaroMovableViewElement, TaroStyleType } from '@tarojs/runtime'
1
+ import type { TaroAny, TaroMovableViewElement, TaroElement } from '@tarojs/runtime'
2
2
 
3
- import commonStyleModify from './style'
4
- import { createLazyChildren } from './render'
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
4
+
5
+ import { FlexManager } from './utils/flexManager'
5
6
 
6
- import { FlexManager } from './utils/FlexManager'
7
- import { getNormalAttributes, } from './utils/helper'
8
- @Extend(Row)
9
- function rowAttrs(style: TaroStyleType) {
10
- .constraintSize({
11
- minWidth: style.minWidth || style.width,
12
- maxWidth: style.maxWidth,
13
- minHeight: style.minHeight,
14
- maxHeight: style.maxHeight
15
- })
16
- }
17
7
 
18
- @Extend(Column)
19
- function columnAttrs(style: TaroStyleType) {
20
- .constraintSize({
21
- minWidth: style.minWidth,
22
- maxWidth: style.maxWidth,
23
- minHeight: style.minHeight || style.height,
24
- maxHeight: style.maxHeight
25
- })
26
- }
27
8
 
28
9
  @Component
29
- export default struct TaroMovableArea {
10
+ export default struct TaroMovableView {
11
+ @Builder customBuilder() {}
12
+ @BuilderParam createLazyChildren: (node: TaroMovableViewElement, layer?: number) => void = this.customBuilder
30
13
  @ObjectLink node: TaroMovableViewElement
14
+ @State overwriteStyle: Record<string, TaroAny> = {}
31
15
 
32
- @Provide areaWidth: Length = 0
33
- @Provide areaHeight: Length = 0
16
+ aboutToAppear(): void {
17
+ if (this.node) {
18
+ this.node._instance = this
19
+
20
+ }
21
+ }
34
22
 
35
23
  build() {
36
- if (this.node) {
37
- if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node).direction !== FlexDirection.Column) {
24
+ Stack() {
25
+ if (FlexManager.useFlexLayout(this.node)) {
26
+ Flex(FlexManager.flexOptions(this.node)) {
27
+ this.createLazyChildren(this.node, 0)
28
+ }
29
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
30
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
38
31
  Row() {
39
- createLazyChildren(this.node)
32
+ this.createLazyChildren(this.node, 0)
40
33
  }
41
- .attributeModifier(commonStyleModify.setNode(this.node))
42
- .rowAttrs(getNormalAttributes(this.node))
43
- .alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
44
- .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
45
- .clip(true)
46
- .onAreaChange((oldValue: Area, newValue: Area) => {
47
- this.areaWidth = newValue.width
48
- this.areaHeight = newValue.height
49
- })
34
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
50
35
  } else {
51
36
  Column() {
52
- createLazyChildren(this.node)
37
+ this.createLazyChildren(this.node, 0)
53
38
  }
54
- .attributeModifier(commonStyleModify.setNode(this.node))
55
- .columnAttrs(getNormalAttributes(this.node))
56
- .alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
57
- .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
58
- .clip(true)
59
- .onAreaChange((oldValue: Area, newValue: Area) => {
60
- this.areaWidth = newValue.width
61
- this.areaHeight = newValue.height
62
- })
39
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
63
40
  }
64
41
  }
42
+ .translate({ x: this.node.position.x, y: this.node.position.y })
43
+ .scale({ x: this.node.scaleValue, y: this.node.scaleValue })
44
+ .onSizeChange((oldValue: SizeOptions, newValue: SizeOptions) => {
45
+ if (this.node.selfSize?.w !== Number(newValue.width) || this.node.selfSize?.h !== Number(newValue.height)) {
46
+ this.node.selfSize = { w: Number(newValue.width), h: Number(newValue.height) }
47
+ }
48
+ })
49
+ .visibility(this.node.visibility)
50
+ .gesture(
51
+ GestureGroup(GestureMode.Parallel,
52
+ PanGesture(getPanOption(this.node)).onActionStart((e: GestureEvent) => {
53
+
54
+ this.node.startMove()
55
+ this.node.callTouchEventFnFromGesture('touchstart', e)
56
+ }).onActionUpdate((e: GestureEvent) => {
57
+ this.node.callTouchEventFnFromGesture('touchmove', e)
58
+ this.node.doMove({
59
+ x: e.offsetX,
60
+ y: e.offsetY
61
+ })
62
+
63
+ }).onActionEnd((e: GestureEvent) => {
64
+ this.node.callTouchEventFnFromGesture('touchend', e)
65
+ this.node.checkPositionBoundary(this.node.position, this.node.scaleValue)
66
+ }),
67
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
68
+ this.node.startScale()
69
+ }).onActionUpdate((event) => {
70
+ this.node.doScale(event.scale)
71
+ })
72
+ )
73
+ )
65
74
  }
66
75
  }
76
+
77
+
78
+ function getPanOption(node: TaroMovableViewElement) {
79
+ const attrDirection = node.getAttribute('direction')
80
+ let panDirection = PanDirection.All
81
+
82
+ if(node.getAttribute('disabled')) {
83
+ panDirection = PanDirection.None
84
+ } else if(attrDirection === 'horizontal') {
85
+ panDirection = PanDirection.Horizontal
86
+ } else if (attrDirection === 'vertical') {
87
+ panDirection = PanDirection.Vertical
88
+ }
89
+ return new PanGestureOptions({
90
+ direction: panDirection,
91
+ fingers: 1
92
+ })
93
+ }