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

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.
@@ -34,7 +34,7 @@ export const pageScrollTo: typeof Taro.pageScrollTo = (options) => {
34
34
  const page = taro.getCurrentInstance().page
35
35
 
36
36
  let scrollValue = -1
37
- let scroller = page.scroller
37
+ let scroller = getPageScrollerOrNode(page.scroller, page)
38
38
  const currentPageNode = getPageScrollerOrNode(page.node, page)
39
39
 
40
40
  if (scrollTop || typeof scrollTop === 'number') {
@@ -19,15 +19,16 @@ export default struct TaroNavigationBar {
19
19
  this.node._instance = this
20
20
  }
21
21
 
22
- eventCenter.on('__taroComponentAttributeUpdate', this.handleAttributeUpdate.bind(this))
22
+ // FIXME 在 Harmony 提供 @Watch 文档后,根据 node 实际使用更细粒度的监听
23
+ eventCenter.on('__taroComponentAttributeUpdate', this.handleAttributeUpdate)
23
24
  this.handleAttributes(this.node._attrs)
24
25
  }
25
26
 
26
27
  aboutToDisappear(): void {
27
- eventCenter.off('__taroComponentAttributeUpdate', this.handleAttributeUpdate.bind(this))
28
+ eventCenter.off('__taroComponentAttributeUpdate', this.handleAttributeUpdate)
28
29
  }
29
30
 
30
- handleAttributeUpdate (opt: IComponentAttributeUpdateEvents) {
31
+ handleAttributeUpdate = (opt: IComponentAttributeUpdateEvents) => {
31
32
  if (opt.id === this.node._nid && opt.tagName === 'NAVIGATION-BAR') {
32
33
  const attrs: Record<string, TaroAny> = {}
33
34
  attrs[opt.attribute] = opt.value
@@ -38,7 +39,6 @@ export default struct TaroNavigationBar {
38
39
  handleAttributes (attrs: Record<string, TaroAny>) {
39
40
  const options: Record<string, TaroAny> = {}
40
41
 
41
- // FIXME 更新类型支持度
42
42
  if (attrs.title) {
43
43
  options.title = attrs.title
44
44
  }
@@ -52,6 +52,7 @@ export default struct TaroNavigationBar {
52
52
  options.frontColor = attrs.frontColor
53
53
  }
54
54
  eventCenter.trigger('__taroNavigationStyle', options)
55
+ // FIXME: 以下属性暂时不支持
55
56
  // attrs.colorAnimationDuration
56
57
  // attrs.colorAnimationTimingFunc
57
58
  }
@@ -1,4 +1,5 @@
1
1
  import { APP, eventCenter } from '@tarojs/runtime/dist/runtime.esm'
2
+ import { getCurrentInstance, pageScrollTo } from '@tarojs/taro'
2
3
 
3
4
  import { isTagFirstChild } from './utils/helper'
4
5
 
@@ -17,24 +18,29 @@ export default struct TaroPageMeta {
17
18
  @BuilderParam createLazyChildren: (node: TaroPageMetaElement) => void = this.customBuilder
18
19
  @ObjectLink node: TaroPageMetaElement
19
20
 
21
+ page: TaroAny = {}
22
+
20
23
  aboutToAppear(): void {
21
24
  if (!isTagFirstChild(this.node, APP, 2)) {
22
25
  // PageMeta 只能是页面内的第一个元素
23
26
  console.error('PageMeta 只能是页面内的第一个元素。')
24
27
  }
28
+
29
+ this.page = getCurrentInstance().page
25
30
  if (this.node) {
26
31
  this.node._instance = this
27
32
  }
28
33
 
29
- eventCenter.on('__taroComponentAttributeUpdate', this.handleAttributeUpdate.bind(this))
34
+ // FIXME 在 Harmony 提供 @Watch 文档后,根据 node 实际使用更细粒度的监听
35
+ eventCenter.on('__taroComponentAttributeUpdate', this.handleAttributeUpdate)
30
36
  this.handleAttributes(this.node._attrs)
31
37
  }
32
38
 
33
39
  aboutToDisappear(): void {
34
- eventCenter.off('__taroComponentAttributeUpdate', this.handleAttributeUpdate.bind(this))
40
+ eventCenter.off('__taroComponentAttributeUpdate', this.handleAttributeUpdate)
35
41
  }
36
42
 
37
- handleAttributeUpdate (opt: IComponentAttributeUpdateEvents) {
43
+ handleAttributeUpdate = (opt: IComponentAttributeUpdateEvents) => {
38
44
  if (opt.id === this.node._nid && opt.tagName === 'PAGE-META') {
39
45
  const attrs: Record<string, TaroAny> = {}
40
46
  attrs[opt.attribute] = opt.value
@@ -44,32 +50,37 @@ export default struct TaroPageMeta {
44
50
 
45
51
  handleAttributes (attrs: Record<string, TaroAny>) {
46
52
  const options: Record<string, TaroAny> = {}
53
+ let triggerStyleEvent = false
47
54
 
48
55
  // FIXME 更新类型支持度
49
- if (attrs.backgroundColorTop || options.backgroundColor) {
50
- options.backgroundColorContext = attrs.backgroundColorTop || options.backgroundColor
56
+ if (attrs.backgroundColorTop || attrs.rootBackgroundColor || attrs.backgroundColor) {
57
+ options.backgroundColorContext = attrs.backgroundColorTop || attrs.rootBackgroundColor || attrs.backgroundColor
58
+ triggerStyleEvent = true
51
59
  }
52
- if (attrs.backgroundColorBottom || options.backgroundColor) {
53
- options.backgroundColor = attrs.backgroundColorBottom || options.backgroundColor
60
+ if (attrs.backgroundColorBottom || attrs.backgroundColor) {
61
+ options.backgroundColor = attrs.backgroundColorBottom || attrs.backgroundColor
62
+ triggerStyleEvent = true
54
63
  }
55
64
  if (attrs.backgroundTextStyle) {
56
65
  options.backgroundTextStyle = attrs.backgroundTextStyle
66
+ triggerStyleEvent = true
57
67
  }
58
68
 
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
69
+ if (this.page === getCurrentInstance().page) {
70
+ if (attrs.scrollTop || attrs.scrollDuration) {
71
+ pageScrollTo({
72
+ scrollTop: attrs.scrollTop || this.node._attrs.scrollTop,
73
+ duration: attrs.scrollDuration || this.node._attrs.scrollDuration,
74
+ } as TaroAny)
75
+ }
68
76
  }
77
+ // pageStyle
69
78
  // rootFontSize
70
79
  // pageFontSize
71
80
  // pageOrientation
72
- eventCenter.trigger('__taroPageStyle', options)
81
+ if (triggerStyleEvent) {
82
+ eventCenter.trigger('__taroPageStyle', options)
83
+ }
73
84
  // onResize
74
85
  // onScroll
75
86
  // onScrollDone
@@ -1,7 +1,7 @@
1
1
  import type { TaroAny, HarmonyStyle, TaroElement, TaroStyleType, TaroTextElement } from '@tarojs/runtime'
2
2
  import { ObjectAssign } from '@tarojs/runtime'
3
3
  import { isUndefined } from '@tarojs/shared'
4
- import { computeBackgroundPosition } from './utils'
4
+ import { computeBackgroundPosition, convertVp2Px } from './utils'
5
5
  import { getNormalAttributes } from './utils/helper'
6
6
  import { isMaxWidthView } from './utils/styles'
7
7
  import { FlexManager } from './utils/flexManager.ets'
@@ -376,34 +376,15 @@ export function setNormalAttributeIntoInstance(instance: CommonAttribute, style:
376
376
  // 为了适应position不设置z-index也能高于同层级组件,估且让设置了z-index的会更高一级
377
377
  instance.zIndex(style.zIndex + 1)
378
378
  }
379
- // if (!isUndefined(style.transform)) {
380
- // if (style.transform.Translate) {
381
- // instance.translate({
382
- // x: style.transform.Translate.x || 0,
383
- // y: style.transform.Translate.y || 0,
384
- // z: style.transform.Translate.z || 0,
385
- // })
386
- // }
387
- // if (style.transform.Scale) {
388
- // instance.scale({
389
- // x: style.transform.Scale.x || 0,
390
- // y: style.transform.Scale.y || 0,
391
- // z: style.transform.Scale.z || 0,
392
- // centerX: style.transformOrigin?.x || 0,
393
- // centerY: style.transformOrigin?.y || 0,
394
- // })
395
- // }
396
- // if (style.transform.Rotate) {
397
- // instance.rotate({
398
- // x: style.transform.Rotate.x || 0,
399
- // y: style.transform.Rotate.y || 0,
400
- // z: style.transform.Rotate.z || 0,
401
- // centerX: style.transformOrigin?.x || 0,
402
- // centerY: style.transformOrigin?.y || 0,
403
- // angle: style.transform.Rotate.angle
404
- // })
405
- // }
406
- // }
379
+ if (!isUndefined(style.boxShadow)) {
380
+ instance.shadow({
381
+ radius: convertVp2Px(style.boxShadow.radius),
382
+ color: style.boxShadow.color,
383
+ offsetX: convertVp2Px(style.boxShadow.offsetX),
384
+ offsetY: convertVp2Px(style.boxShadow.offsetY),
385
+ fill: style.boxShadow.fill,
386
+ })
387
+ }
407
388
  }
408
389
 
409
390
  export const pseudoModify = new PseudoStyleModify()
@@ -77,5 +77,28 @@ export default struct TaroSwiper {
77
77
  this.node._nodeInfo.areaInfo = res[1]
78
78
  }))
79
79
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
80
+ .onGestureSwipe(shouldBindEvent((index: number, extraInfo: SwiperAnimationEvent) => {
81
+ const currentOffset = extraInfo.currentOffset || 0
82
+ // 判断设置的滚动方向
83
+ const isVertical = this.node._attrs.vertical || false
84
+ let event: TaroEvent
85
+ if (isVertical) {
86
+ event = createTaroEvent('transition', { detail: { dx: 0, dy: currentOffset } }, this.node)
87
+ } else {
88
+ event = createTaroEvent('transition', { detail: { dx: currentOffset, dy: 0 } }, this.node)
89
+ }
90
+ eventHandler(event, 'transition', this.node)
91
+ }, this.node, ['transition']))
92
+ .onTouch(shouldBindEvent((event: TouchEvent) => {
93
+ if (event.type === TouchType.Down) {
94
+ eventHandler(event, 'touchStart', this.node)
95
+ }
96
+ if (event.type === TouchType.Up) {
97
+ eventHandler(event, 'touchEnd', this.node)
98
+ }
99
+ if (event.type === TouchType.Move) {
100
+ eventHandler(event, 'touchMove', this.node)
101
+ }
102
+ }, this.node, ['touchstart', 'touchmove', 'touchend']))
80
103
  }
81
104
  }
@@ -1,7 +1,7 @@
1
1
  import { isString } from '@tarojs/shared'
2
2
  import { eventHandler, convertNumber2VP, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, NodeType } from '@tarojs/runtime'
3
3
 
4
- import commonStyleModify, { textModify, setNormalTextAttributeIntoInstance } from './style'
4
+ import { textModify, setNormalTextAttributeIntoInstance } from './style'
5
5
  import { getButtonColor } from './button'
6
6
  import { getImageMode } from './image'
7
7
  import { BUTTON_THEME_COLOR } from './utils/constant/style'
@@ -78,9 +78,32 @@ export default struct TaroText {
78
78
  function createTextChildNode (item: TaroElement, align: ImageSpanAlignment) {
79
79
  if (item.tagName === 'IMAGE') {
80
80
  ImageSpan(item.getAttribute('src'))
81
- .attributeModifier(commonStyleModify.setNode(item))
81
+ // .attributeModifier(commonStyleModify.setNode(item))
82
82
  .objectFit(getImageMode(item.getAttribute('mode')))
83
83
  .verticalAlign(align)
84
+ .width(item._st.hmStyle.width)
85
+ .height(item._st.hmStyle.height)
86
+ .margin({
87
+ top: item._st.hmStyle.marginTop,
88
+ left: item._st.hmStyle.marginLeft,
89
+ right: item._st.hmStyle.marginRight,
90
+ bottom: item._st.hmStyle.marginBottom,
91
+ })
92
+ .padding({
93
+ top: item._st.hmStyle.paddingTop,
94
+ left: item._st.hmStyle.paddingLeft,
95
+ right: item._st.hmStyle.paddingRight,
96
+ bottom: item._st.hmStyle.paddingBottom,
97
+ })
98
+ .textBackgroundStyle({
99
+ color: item._st.hmStyle.backgroundColor,
100
+ radius: {
101
+ topLeft: item._st.hmStyle.borderTopLeftRadius,
102
+ topRight: item._st.hmStyle.borderTopRightRadius,
103
+ bottomLeft: item._st.hmStyle.borderBottomLeftRadius,
104
+ bottomRight: item._st.hmStyle.borderBottomRightRadius,
105
+ }
106
+ })
84
107
  .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', item), item, ['click']))
85
108
  } else if (item.nodeType === NodeType.TEXT_NODE) {
86
109
  Span(item.textContent)
@@ -88,6 +111,15 @@ function createTextChildNode (item: TaroElement, align: ImageSpanAlignment) {
88
111
  Span(item.textContent)
89
112
  .attributeModifier(spanModify.setNode(item))
90
113
  .letterSpacing(item._st.hmStyle.letterSpacing)
114
+ .textBackgroundStyle({
115
+ color: item._st.hmStyle.backgroundColor,
116
+ radius: {
117
+ topLeft: item._st.hmStyle.borderTopLeftRadius,
118
+ topRight: item._st.hmStyle.borderTopRightRadius,
119
+ bottomLeft: item._st.hmStyle.borderBottomLeftRadius,
120
+ bottomRight: item._st.hmStyle.borderBottomRightRadius,
121
+ }
122
+ })
91
123
  .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', item), item, ['click']))
92
124
  }
93
125
  }
@@ -80,3 +80,8 @@ export function computeBackgroundPosition(style) {
80
80
 
81
81
  return { offsetX, offsetY }
82
82
  }
83
+
84
+ export function convertVp2Px(val: string | number) {
85
+ const vp = parseFloat(`${val}`)
86
+ return vp2px(vp)
87
+ }
@@ -113,6 +113,15 @@ export interface TaroStyleType {
113
113
  animationDelay?: number
114
114
  animationIterationCount?: number
115
115
 
116
+ // shadow
117
+ boxShadow?: {
118
+ radius: number
119
+ color?: string
120
+ offsetX?: number
121
+ offsetY?: number
122
+ fill?: boolean
123
+ }
124
+
116
125
  // other
117
126
  opacity?: number | Resource
118
127
  zIndex?: number
@@ -3858,7 +3858,7 @@ const pageScrollTo = (options) => {
3858
3858
  const taro = Current.taro;
3859
3859
  const page = taro.getCurrentInstance().page;
3860
3860
  let scrollValue = -1;
3861
- let scroller = page.scroller;
3861
+ let scroller = getPageScrollerOrNode(page.scroller, page);
3862
3862
  const currentPageNode = getPageScrollerOrNode(page.node, page);
3863
3863
  if (scrollTop || typeof scrollTop === 'number') {
3864
3864
  scrollValue = scrollTop;