@tarojs/plugin-platform-harmony-ets 4.0.0-beta.50 → 4.0.0-beta.52

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.
@@ -1,6 +1,9 @@
1
+ import { eventCenter } from '@tarojs/runtime/dist/runtime.esm'
2
+
1
3
  import { isTagFirstChild } from './utils/helper'
2
4
 
3
- import type { TaroNavigationBarElement } from '@tarojs/runtime'
5
+ import type { TaroAny, TaroNavigationBarElement } from '@tarojs/runtime'
6
+ import type { IComponentAttributeUpdateEvents } from './pageMeta'
4
7
 
5
8
  @Component
6
9
  export default struct TaroNavigationBar {
@@ -15,6 +18,42 @@ export default struct TaroNavigationBar {
15
18
  if (this.node) {
16
19
  this.node._instance = this
17
20
  }
21
+
22
+ eventCenter.on('__taroComponentAttributeUpdate', this.handleAttributeUpdate.bind(this))
23
+ this.handleAttributes(this.node._attrs)
24
+ }
25
+
26
+ aboutToDisappear(): void {
27
+ eventCenter.off('__taroComponentAttributeUpdate', this.handleAttributeUpdate.bind(this))
28
+ }
29
+
30
+ handleAttributeUpdate (opt: IComponentAttributeUpdateEvents) {
31
+ if (opt.id === this.node._nid && opt.tagName === 'NAVIGATION-BAR') {
32
+ const attrs: Record<string, TaroAny> = {}
33
+ attrs[opt.attribute] = opt.value
34
+ this.handleAttributes(attrs)
35
+ }
36
+ }
37
+
38
+ handleAttributes (attrs: Record<string, TaroAny>) {
39
+ const options: Record<string, TaroAny> = {}
40
+
41
+ // FIXME 更新类型支持度
42
+ if (attrs.title) {
43
+ options.title = attrs.title
44
+ }
45
+ if (attrs.loading) {
46
+ options.loading = attrs.loading
47
+ }
48
+ if (attrs.backgroundColor) {
49
+ options.backgroundColor = attrs.backgroundColor
50
+ }
51
+ if (attrs.frontColor) {
52
+ options.frontColor = attrs.frontColor
53
+ }
54
+ eventCenter.trigger('__taroNavigationStyle', options)
55
+ // attrs.colorAnimationDuration
56
+ // attrs.colorAnimationTimingFunc
18
57
  }
19
58
 
20
59
  build() {
@@ -1,8 +1,15 @@
1
- import { APP } from '@tarojs/runtime/dist/runtime.esm'
1
+ import { APP, eventCenter } from '@tarojs/runtime/dist/runtime.esm'
2
2
 
3
3
  import { isTagFirstChild } from './utils/helper'
4
4
 
5
- import type { TaroPageMetaElement } from '@tarojs/runtime'
5
+ import type { TaroAny, TaroPageMetaElement } from '@tarojs/runtime'
6
+
7
+ export interface IComponentAttributeUpdateEvents {
8
+ id: string
9
+ tagName: string
10
+ attribute: string
11
+ value: TaroAny
12
+ }
6
13
 
7
14
  @Component
8
15
  export default struct TaroPageMeta {
@@ -18,6 +25,54 @@ export default struct TaroPageMeta {
18
25
  if (this.node) {
19
26
  this.node._instance = this
20
27
  }
28
+
29
+ eventCenter.on('__taroComponentAttributeUpdate', this.handleAttributeUpdate.bind(this))
30
+ this.handleAttributes(this.node._attrs)
31
+ }
32
+
33
+ aboutToDisappear(): void {
34
+ eventCenter.off('__taroComponentAttributeUpdate', this.handleAttributeUpdate.bind(this))
35
+ }
36
+
37
+ handleAttributeUpdate (opt: IComponentAttributeUpdateEvents) {
38
+ if (opt.id === this.node._nid && opt.tagName === 'PAGE-META') {
39
+ const attrs: Record<string, TaroAny> = {}
40
+ attrs[opt.attribute] = opt.value
41
+ this.handleAttributes(attrs)
42
+ }
43
+ }
44
+
45
+ handleAttributes (attrs: Record<string, TaroAny>) {
46
+ const options: Record<string, TaroAny> = {}
47
+
48
+ // FIXME 更新类型支持度
49
+ if (attrs.backgroundColorTop || options.backgroundColor) {
50
+ options.backgroundColorContext = attrs.backgroundColorTop || options.backgroundColor
51
+ }
52
+ if (attrs.backgroundColorBottom || options.backgroundColor) {
53
+ options.backgroundColor = attrs.backgroundColorBottom || options.backgroundColor
54
+ }
55
+ if (attrs.backgroundTextStyle) {
56
+ options.backgroundTextStyle = attrs.backgroundTextStyle
57
+ }
58
+
59
+ // if (attrs.scrollTop || attrs.scrollDuration) {
60
+ // pageScrollTo({
61
+ // scrollTop: attrs.scrollTop || this.node._attrs.scrollTop,
62
+ // duration: attrs.scrollDuration || this.node._attrs.scrollDuration,
63
+ // })
64
+ // }
65
+ // pageStyle
66
+ if (attrs.rootBackgroundColor) {
67
+ options.backgroundColor = attrs.rootBackgroundColor
68
+ }
69
+ // rootFontSize
70
+ // pageFontSize
71
+ // pageOrientation
72
+ eventCenter.trigger('__taroPageStyle', options)
73
+ // onResize
74
+ // onScroll
75
+ // onScrollDone
21
76
  }
22
77
 
23
78
  build() {
@@ -39,12 +39,13 @@ export function getNodeThresholds (node: TaroElement): number[] | null {
39
39
  export function isTagFirstChild (node: TaroElement, tagName = VIEW, level = 0): boolean {
40
40
  const parent: TaroElement | null = node.parentElement
41
41
  const list: TaroNode[] = node.parentNode?.childNodes || []
42
- if (!parent || list.length < 1 || level < 0) return false
42
+ if (list.length < 1 || level < 0) return false
43
+ else if (!parent) return true
43
44
 
44
45
  if (parent.nodeName === tagName.toUpperCase()) {
45
46
  return list[0] === node
46
47
  } else {
47
- return list[0] === node && isTagFirstChild(parent, tagName, --level)
48
+ return (list[0] === node) && isTagFirstChild(parent, tagName, --level)
48
49
  }
49
50
  }
50
51
 
@@ -1,4 +1,3 @@
1
- import { Current } from '../current'
2
1
  import { ObjectAssign } from '../utils'
3
2
 
4
3
  import type { TaroAny } from '../utils'
@@ -1,4 +1,4 @@
1
- import { eventSource } from '@tarojs/runtime/dist/runtime.esm'
1
+ import { eventCenter, eventSource } from '@tarojs/runtime/dist/runtime.esm'
2
2
  import { EMPTY_OBJ, toCamelCase } from '@tarojs/shared'
3
3
 
4
4
  import { ATTRIBUTES_CALLBACK_TRIGGER_MAP, ID } from '../../constant'
@@ -31,7 +31,7 @@ export class TaroElement<
31
31
  public _nodeInfo: TaroAny = {
32
32
  layer: 0 // 渲染层级
33
33
  }
34
-
34
+
35
35
  public hm_instance: TaroAny
36
36
 
37
37
  public get _instance () {
@@ -115,14 +115,24 @@ export class TaroElement<
115
115
 
116
116
  this._attrs[name] = value
117
117
 
118
- const attributeTriggerValue: TaroAny = ATTRIBUTES_CALLBACK_TRIGGER_MAP[name]
119
- if (attributeTriggerValue) {
120
- const triggerName: TaroAny = attributeTriggerValue.triggerName
121
- const valueInspect: TaroAny = attributeTriggerValue.valueInspect
118
+ if (['PAGE-META', 'NAVIGATION-BAR'].includes(this.tagName)) {
119
+ // FIXME 等 Harmony 支持更细粒度的 @Watch 方法后移出
120
+ eventCenter.trigger('__taroComponentAttributeUpdate', {
121
+ id: this._nid,
122
+ tagName: this.tagName,
123
+ attribute: name,
124
+ value
125
+ })
126
+ } else {
127
+ const attributeTriggerValue: TaroAny = ATTRIBUTES_CALLBACK_TRIGGER_MAP[name]
128
+ if (attributeTriggerValue) {
129
+ const triggerName: TaroAny = attributeTriggerValue.triggerName
130
+ const valueInspect: TaroAny = attributeTriggerValue.valueInspect
122
131
 
123
- if (valueInspect && !valueInspect(value)) return
132
+ if (valueInspect && !valueInspect(value)) return
124
133
 
125
- triggerAttributesCallback(this, triggerName)
134
+ triggerAttributesCallback(this, triggerName)
135
+ }
126
136
  }
127
137
  }
128
138
 
@@ -240,7 +250,7 @@ export class TaroElement<
240
250
  this._pseudo_after = null
241
251
  }
242
252
  }
243
-
253
+
244
254
  // 伪类,在获取的时候根据dom和parent的关系,动态设置
245
255
  public _pseudo_class: Record<string, StyleSheet | null> = {
246
256
  // ["::first-child"]: new StyleSheet(),
@@ -346,7 +356,7 @@ export class TaroElement<
346
356
  }
347
357
  }
348
358
 
349
- // 设置动画
359
+ // 设置动画
350
360
  public setAnimation (playing) {
351
361
  if (!this._instance) {
352
362
  if (!this._nodeInfo.aboutToAppear) {
@@ -364,7 +374,7 @@ export class TaroElement<
364
374
  if (playing && keyframes && keyframes[0] && keyframes[0].percentage === 0) {
365
375
  this._instance.overwriteStyle = keyframes[0].event
366
376
  }
367
-
377
+
368
378
  // 首次设置,不用实例替换
369
379
  if (!this._nodeInfo.hasAnimation) {
370
380
  this._nodeInfo.hasAnimation = true
@@ -396,8 +406,8 @@ export class TaroElement<
396
406
  }
397
407
 
398
408
  private playAnimation () {
399
- const {
400
- animationDuration = 0, animationDelay = 0, animationIterationCount = 1, animationName: keyframes,
409
+ const {
410
+ animationDuration = 0, animationDelay = 0, animationIterationCount = 1, animationName: keyframes,
401
411
  animationTimingFunction
402
412
  } = this._st.hmStyle
403
413
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/plugin-platform-harmony-ets",
3
- "version": "4.0.0-beta.50",
3
+ "version": "4.0.0-beta.52",
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.50",
29
- "@tarojs/runner-utils": "4.0.0-beta.50",
30
- "@tarojs/helper": "4.0.0-beta.50",
31
- "@tarojs/service": "4.0.0-beta.50",
32
- "@tarojs/runtime": "4.0.0-beta.50",
33
- "@tarojs/shared": "4.0.0-beta.50",
34
- "@tarojs/taro": "4.0.0-beta.50"
28
+ "@tarojs/components": "4.0.0-beta.52",
29
+ "@tarojs/runner-utils": "4.0.0-beta.52",
30
+ "@tarojs/helper": "4.0.0-beta.52",
31
+ "@tarojs/runtime": "4.0.0-beta.52",
32
+ "@tarojs/service": "4.0.0-beta.52",
33
+ "@tarojs/shared": "4.0.0-beta.52",
34
+ "@tarojs/taro": "4.0.0-beta.52"
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.50"
47
+ "rollup-plugin-copy": "4.0.0-beta.52"
48
48
  },
49
49
  "scripts": {
50
50
  "prebuild": "rimraf ./dist",