@tarojs/plugin-platform-harmony-ets 4.0.0-beta.80 → 4.0.0-beta.82

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.
@@ -32,8 +32,8 @@ export default struct TaroMovableArea {
32
32
  }
33
33
  .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
34
34
  .clip(true)
35
- .onAreaChange((oldValue: Area, newValue: Area) => {
36
- areaChangeHandle(this.node, newValue)
35
+ .onSizeChange((oldValue: SizeOptions, newValue: SizeOptions) => {
36
+ sizeChangeHandle(this.node, newValue)
37
37
  })
38
38
  .gesture(
39
39
  PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
@@ -59,8 +59,8 @@ export default struct TaroMovableArea {
59
59
  }
60
60
  .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
61
61
  .clip(true)
62
- .onAreaChange((oldValue: Area, newValue: Area) => {
63
- areaChangeHandle(this.node, newValue)
62
+ .onSizeChange((oldValue: SizeOptions, newValue: SizeOptions) => {
63
+ sizeChangeHandle(this.node, newValue)
64
64
  })
65
65
  .gesture(
66
66
  PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
@@ -86,8 +86,8 @@ export default struct TaroMovableArea {
86
86
  }
87
87
  .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
88
88
  .clip(true)
89
- .onAreaChange((oldValue: Area, newValue: Area) => {
90
- areaChangeHandle(this.node, newValue)
89
+ .onSizeChange((oldValue: SizeOptions, newValue: SizeOptions) => {
90
+ sizeChangeHandle(this.node, newValue)
91
91
  })
92
92
  .gesture(
93
93
  PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
@@ -110,7 +110,9 @@ export default struct TaroMovableArea {
110
110
  }
111
111
  }
112
112
  }
113
- function areaChangeHandle(node: TaroMovableAreaElement,newValue: Area) {
113
+
114
+
115
+ function sizeChangeHandle(node: TaroMovableAreaElement, newValue: Area | SizeOptions) {
114
116
  node.childNodes.forEach(item => {
115
117
  if (isTaroMovableViewElement(item)) {
116
118
  if (item.area?.w !== Number(newValue.width) || item.area?.h !== Number(newValue.height)) {
@@ -41,7 +41,7 @@ export default struct TaroMovableView {
41
41
  }
42
42
  .translate({ x: this.node.position.x, y: this.node.position.y })
43
43
  .scale({ x: this.node.scaleValue, y: this.node.scaleValue })
44
- .onAreaChange((oldValue: Area, newValue: Area) => {
44
+ .onSizeChange((oldValue: SizeOptions, newValue: SizeOptions) => {
45
45
  if (this.node.selfSize?.w !== Number(newValue.width) || this.node.selfSize?.h !== Number(newValue.height)) {
46
46
  this.node.selfSize = { w: Number(newValue.width), h: Number(newValue.height) }
47
47
  }
@@ -4,7 +4,7 @@ import { isUndefined } from '@tarojs/shared'
4
4
  import { computeBackgroundPosition, convertVp2Px } from './utils'
5
5
  import { getNormalAttributes } from './utils/helper'
6
6
  import { isMaxWidthView } from './utils/styles'
7
- import { FlexManager } from './utils/flexManager.ets'
7
+ import { FlexManager } from './utils/flexManager'
8
8
 
9
9
  class TextStyleModify implements AttributeModifier<TextAttribute> {
10
10
  initStyle?: TaroStyleType
@@ -1,6 +1,6 @@
1
1
  import type { TaroElement, HarmonyStyle } from '@tarojs/runtime'
2
2
  import { isUndefined } from '@tarojs/shared'
3
- import { getNormalAttributes } from './styles.ets'
3
+ import { getNormalAttributes } from './styles'
4
4
 
5
5
  interface IFlexOptions {
6
6
  direction: FlexDirection,
@@ -1,7 +1,6 @@
1
1
  import { parseClasses } from '../utils'
2
2
 
3
3
  import type { CSSProperties, ReactElement } from 'react'
4
-
5
4
  // 抽出来的嵌套查询
6
5
  // const __nesting_style__ = [
7
6
  // {
@@ -74,7 +73,7 @@ function depthTraversal(root: ReactElement) {
74
73
  const result: Record<string, TMapping> = {}
75
74
  if (tree && tree.props) {
76
75
  // 兜底适配:如果Taro组件被原封不动的再别的地方导出使用,导致无法在编译环境添加__hmStyle
77
- // import { View } from '~/components'
76
+ // import { View } from '../../../~/components'
78
77
  // hack:如果是taro节点,但是被赋予了__styleSheet,则走一下__styleSheet转__hmStyle
79
78
  if (tree.props.__styleSheet && typeof tree.type !== 'function') {
80
79
  tree.props.__hmStyle = Object.assign({}, tree.props.__hmStyle, tree.props.__styleSheet.value)
@@ -128,28 +127,34 @@ function depthTraversal(root: ReactElement) {
128
127
  const processLeaf = (leaf, descendant_map: TMappingNode) => {
129
128
  if (!leaf) return
130
129
 
131
- // 如果是个数组
132
- if (leaf instanceof Array) {
133
- for (let i = 0; i < leaf.length; i++) {
134
- processLeaf(leaf[i], descendant_map)
130
+ const queue = [leaf]
131
+
132
+ while (queue.length > 0) {
133
+ const current = queue.shift()
134
+
135
+ if (current instanceof Array) {
136
+ for (let i = 0; i < current.length; i++) {
137
+ queue.push(current[i])
138
+ }
139
+ continue
135
140
  }
136
- }
137
141
 
138
- const leaf_map = traverse(leaf)
139
- if (!leaf_map) return
142
+ const leaf_map = traverse(current)
143
+ if (!leaf_map) continue
140
144
 
141
- // 直接后代
142
- Object.assign(descendant_map.children, leaf_map)
145
+ // 直接后代
146
+ Object.assign(descendant_map.children, leaf_map)
143
147
 
144
- // 子孙后代
145
- const grandchild: (Record<string, TMapping> | TMapping)[] = [leaf_map]
146
- Object.keys(leaf_map).forEach(key => {
147
- const leaf_child_map = class_mapping[key]
148
- if (leaf_child_map?.descendants) {
149
- grandchild.push(leaf_child_map.descendants)
150
- }
151
- })
152
- Object.assign(descendant_map.descendants, ...grandchild)
148
+ // 子孙后代
149
+ const grandchild: (Record<string, TMapping> | TMapping)[] = [leaf_map]
150
+ Object.keys(leaf_map).forEach(key => {
151
+ const leaf_child_map = class_mapping[key]
152
+ if (leaf_child_map?.descendants) {
153
+ grandchild.push(leaf_child_map.descendants)
154
+ }
155
+ })
156
+ Object.assign(descendant_map.descendants, ...grandchild)
157
+ }
153
158
  }
154
159
 
155
160
  traverse(root)
@@ -239,24 +244,29 @@ function combineStyle(nestingStyle: NestingStyle, class_mapping: TMapping, alias
239
244
  }
240
245
  return selector_nodes
241
246
  }
242
- const findSelector = (selectors, current_mapping, declaration): TSelectorNode[] => {
243
- const new_selectors = selectors.slice()
244
- const selector_string = new_selectors.shift()
245
- const combinator_type = new_selectors.shift()
246
- const _elements = findElement(selector_string, combinator_type, current_mapping, new_selectors, declaration)
247
- if (_elements.length) {
248
- if (new_selectors.length) {
249
- let elements: TSelectorNode[] = []
250
- _elements.forEach(element => {
251
- elements = elements.concat(findSelector(new_selectors.slice(), element.mapping, declaration))
252
- })
253
- return elements
254
- } else {
255
- return _elements
247
+ const findSelector = (selectors: string[], current_mapping: any, declaration: any): TSelectorNode[] => {
248
+ const workQueue: { selectors: string[], current_mapping: any }[] = [{ selectors, current_mapping }]
249
+ let resultElements: TSelectorNode[] = []
250
+ while (workQueue.length > 0) {
251
+ const { selectors: currentSelectors, current_mapping: currentMapping } = workQueue.shift()!
252
+ const new_selectors = currentSelectors.slice()
253
+ const selector_string = new_selectors.shift()
254
+ const combinator_type = new_selectors.shift()
255
+
256
+ const _elements = findElement(selector_string, combinator_type, currentMapping, new_selectors, declaration)
257
+
258
+ if (_elements.length) {
259
+ if (new_selectors.length) {
260
+ _elements.forEach(element => {
261
+ workQueue.push({ selectors: new_selectors.slice(), current_mapping: element.mapping })
262
+ })
263
+ } else {
264
+ resultElements = resultElements.concat(_elements)
265
+ }
256
266
  }
257
- } else {
258
- return []
259
267
  }
268
+
269
+ return resultElements
260
270
  }
261
271
  if (nestingStyle && nestingStyle instanceof Array) {
262
272
  // 合并样式
@@ -53,12 +53,16 @@ export class TaroElement<
53
53
  public dataset: Record<string, unknown> = EMPTY_OBJ
54
54
  public _attrs: T & TaroExtraProps = {} as T & TaroExtraProps
55
55
 
56
+ private _page: any
57
+
56
58
  constructor(tagName: string) {
57
59
  super(tagName.replace(new RegExp('(?<=.)([A-Z])', 'g'), '-$1').toUpperCase(), NodeType.ELEMENT_NODE)
58
60
  this.tagName = this.nodeName
59
61
  this._style = createCSSStyleDeclaration(this)
60
62
  initComponentNodeInfo(this)
61
63
  bindAnimation(this)
64
+
65
+ this._page = Current.page
62
66
  }
63
67
 
64
68
  public set id(value: string) {
@@ -115,6 +119,17 @@ export class TaroElement<
115
119
 
116
120
  this._attrs[name] = value
117
121
 
122
+ // 混合开发的组件没办法自动更新,需要把父级的结点删掉新建
123
+ // Current.nativeComponentNames会在render.ets中赋值
124
+ if(Current.nativeComponentNames?.includes(this.tagName)) {
125
+ const idxOfRef = this.parentNode?.findIndex(this)
126
+
127
+ if (idxOfRef !== undefined) {
128
+ this._nativeUpdateTrigger++
129
+ this.parentNode?.notifyDataChange(idxOfRef)
130
+ }
131
+ }
132
+
118
133
  if (['PAGE-META', 'NAVIGATION-BAR'].includes(this.tagName)) {
119
134
  // FIXME 等 Harmony 支持更细粒度的 @Watch 方法后移出
120
135
  eventCenter.trigger('__taroComponentAttributeUpdate', {
@@ -270,28 +285,28 @@ export class TaroElement<
270
285
  }
271
286
 
272
287
  get currentLayerNode () {
273
- if (!Current.page) return null
274
- if (typeof Current.page.tabBarCurrentIndex !== 'undefined') {
275
- Current.page.layerNode ||= []
276
- Current.page.layerNode[Current.page.tabBarCurrentIndex] ||= Current.createHarmonyElement('VIEW')
288
+ if (!this._page) return null
289
+ if (typeof this._page.tabBarCurrentIndex !== 'undefined') {
290
+ this._page.layerNode ||= []
291
+ this._page.layerNode[this._page.tabBarCurrentIndex] ||= Current.createHarmonyElement('VIEW')
277
292
  // Tabbar
278
- return Current.page.layerNode[Current.page.tabBarCurrentIndex]
293
+ return this._page.layerNode[this._page.tabBarCurrentIndex]
279
294
  } else {
280
- Current.page.layerNode ||= Current.createHarmonyElement('VIEW')
281
- return Current.page.layerNode
295
+ this._page.layerNode ||= Current.createHarmonyElement('VIEW')
296
+ return this._page.layerNode
282
297
  }
283
298
  }
284
299
 
285
300
  get currentLayerParents () {
286
- if (!Current.page) return null
287
- if (typeof Current.page.tabBarCurrentIndex !== 'undefined') {
288
- Current.page.layerParents ||= []
289
- Current.page.layerParents[Current.page.tabBarCurrentIndex] ||= []
301
+ if (!this._page) return null
302
+ if (typeof this._page.tabBarCurrentIndex !== 'undefined') {
303
+ this._page.layerParents ||= []
304
+ this._page.layerParents[this._page.tabBarCurrentIndex] ||= []
290
305
  // Tabbar
291
- return Current.page.layerParents[Current.page.tabBarCurrentIndex]
306
+ return this._page.layerParents[this._page.tabBarCurrentIndex]
292
307
  } else {
293
- Current.page.layerParents ||= []
294
- return Current.page.layerParents
308
+ this._page.layerParents ||= []
309
+ return this._page.layerParents
295
310
  }
296
311
  }
297
312
 
@@ -44,6 +44,9 @@ export class TaroNode extends TaroDataSourceElement {
44
44
  // 是否为半编译模板下拥有自主更新权的节点
45
45
  public _isDynamicNode = false
46
46
 
47
+ // 以下属性为原生混写组件才有意义的属性
48
+ public _nativeUpdateTrigger = 0
49
+
47
50
  constructor(nodeName: string, nodeType = NodeType.ELEMENT_NODE) {
48
51
  super()
49
52
 
@@ -196,7 +196,7 @@ export function createReactApp (
196
196
  const keys = Object.keys(globalData)
197
197
  const descriptors = Object.getOwnPropertyDescriptors(globalData)
198
198
  keys.forEach(key => {
199
- Object.defineProperty(this, key, {
199
+ Object.defineProperty(Current?.app || this, key, {
200
200
  configurable: true,
201
201
  enumerable: true,
202
202
  get () {
@@ -207,7 +207,7 @@ export function createReactApp (
207
207
  }
208
208
  })
209
209
  })
210
- Object.defineProperties(this, descriptors)
210
+ Object.defineProperties(Current?.app || this, descriptors)
211
211
  }
212
212
 
213
213
  app.onCreate?.()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/plugin-platform-harmony-ets",
3
- "version": "4.0.0-beta.80",
3
+ "version": "4.0.0-beta.82",
4
4
  "description": "OpenHarmony & 鸿蒙系统插件",
5
5
  "author": "O2Team",
6
6
  "homepage": "https://gitee.com/openharmony-sig/taro",
@@ -25,13 +25,13 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "webpack-sources": "^3.2.3",
28
- "@tarojs/components": "4.0.0-beta.80",
29
- "@tarojs/helper": "4.0.0-beta.80",
30
- "@tarojs/runner-utils": "4.0.0-beta.80",
31
- "@tarojs/service": "4.0.0-beta.80",
32
- "@tarojs/runtime": "4.0.0-beta.80",
33
- "@tarojs/shared": "4.0.0-beta.80",
34
- "@tarojs/taro": "4.0.0-beta.80"
28
+ "@tarojs/runner-utils": "4.0.0-beta.82",
29
+ "@tarojs/components": "4.0.0-beta.82",
30
+ "@tarojs/helper": "4.0.0-beta.82",
31
+ "@tarojs/runtime": "4.0.0-beta.82",
32
+ "@tarojs/service": "4.0.0-beta.82",
33
+ "@tarojs/shared": "4.0.0-beta.82",
34
+ "@tarojs/taro": "4.0.0-beta.82"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@rollup/plugin-commonjs": "^25.0.7",
@@ -44,7 +44,7 @@
44
44
  "solid-js": "^1.8.16",
45
45
  "tslib": "^2.4.0",
46
46
  "typescript": "^4.8.2",
47
- "rollup-plugin-copy": "4.0.0-beta.80"
47
+ "rollup-plugin-copy": "4.0.0-beta.82"
48
48
  },
49
49
  "scripts": {
50
50
  "prebuild": "rimraf ./dist",