@tarojs/plugin-platform-harmony-ets 4.0.0-beta.26 → 4.0.0-beta.27

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,3 +1,4 @@
1
+ import { isString } from '@tarojs/shared'
1
2
  import { eventHandler, convertNumber2VP, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, NodeType } from '@tarojs/runtime'
2
3
 
3
4
  import commonStyleModify from './style'
@@ -39,6 +40,17 @@ function getButtonFontSize (node: TaroButtonElement) {
39
40
  return isMini ? convertNumber2VP(26) : convertNumber2VP(36)
40
41
  }
41
42
 
43
+ function getTextInViewWidth (node: TaroElement | null): TaroAny {
44
+ if (node) {
45
+ const hmStyle = node.hmStyle || {}
46
+ const isFlexView = hmStyle.display === 'flex'
47
+ const width: TaroAny = getStyleAttr(node, 'width')
48
+ const isPercentWidth = isString(width) && width.includes('%')
49
+
50
+ return isFlexView || isPercentWidth ? null : getStyleAttr(node, 'width')
51
+ }
52
+ }
53
+
42
54
  @Component
43
55
  export default struct TaroText {
44
56
  @Builder customBuilder() {}
@@ -65,8 +77,7 @@ export default struct TaroText {
65
77
  Text(this.node.textContent)
66
78
  .textNormalFontStyle(this.node.parentElement?.hmStyle || {})
67
79
  .textSpecialFontStyle(getFontAttributes(this.node.parentElement as TaroElement))
68
- .width(getStyleAttr(this.node.parentElement, 'width'))
69
- .height(getStyleAttr(this.node.parentElement, 'height'))
80
+ .width(getTextInViewWidth(this.node.parentElement))
70
81
  }
71
82
  }
72
83
  } else {
@@ -27,13 +27,54 @@ export function getFontAttributes (node: TaroElement): TaroTextStyleType {
27
27
  }
28
28
  }
29
29
 
30
+ const isFlexText = hmStyle.display === 'flex'
31
+ let textAlign = hmStyle.textAlign
32
+ let verticalAlign = hmStyle.verticalAlign
33
+
34
+ // 按照 w3c 规范,一旦设置了 display: flex,textAlign 和 verticalAlign 都会直接失效
35
+ // 需要使用 justifyContent 和 alignItems
36
+ if (isFlexText) {
37
+ switch (hmStyle.justifyContent) {
38
+ case FlexAlign.Start:
39
+ textAlign = TextAlign.Start
40
+ break
41
+ case FlexAlign.Center:
42
+ textAlign = TextAlign.Center
43
+ break
44
+ case FlexAlign.End:
45
+ textAlign = TextAlign.End
46
+ break
47
+ case FlexAlign.SpaceBetween:
48
+ case FlexAlign.SpaceAround:
49
+ textAlign = TextAlign.JUSTIFY
50
+ break
51
+ default:
52
+ textAlign = TextAlign.Start
53
+ break
54
+ }
55
+ switch (hmStyle.alignItems) {
56
+ case ItemAlign.Start:
57
+ verticalAlign = Alignment.Top
58
+ break
59
+ case ItemAlign.Center:
60
+ verticalAlign = Alignment.Center
61
+ break
62
+ case ItemAlign.End:
63
+ verticalAlign = Alignment.End
64
+ break
65
+ default:
66
+ verticalAlign = Alignment.Top
67
+ break
68
+ }
69
+ }
70
+
30
71
  const attributes: TaroAny = {
72
+ textAlign,
73
+ verticalAlign,
31
74
  WebkitLineClamp: WebkitLineClamp,
32
75
  // 已做处理的属性
33
76
  letterSpacing: hmStyle.letterSpacing,
34
- textAlign: hmStyle.textAlign,
35
77
  textOverflow: hmStyle.textOverflow,
36
- verticalAlign: hmStyle.verticalAlign,
37
78
  lineHeight: lineHeight
38
79
  }
39
80
 
@@ -44,8 +85,7 @@ export function getFontAttributes (node: TaroElement): TaroTextStyleType {
44
85
  export function isMaxWidthView (node: TaroElement) {
45
86
  const parentNode: TaroElement = node.parentNode as TaroElement
46
87
 
47
- return node.tagName === 'VIEW' && parentNode && parentNode.tagName === 'VIEW' &&
48
- !(FlexManager.isFlexNode(parentNode) && FlexManager.flexOptions(parentNode).direction !== FlexDirection.Column)
88
+ return node.tagName === 'VIEW' && parentNode && parentNode.tagName === 'VIEW' && !FlexManager.isFlexNode(parentNode)
49
89
  }
50
90
 
51
91
  export function getNormalAttributes (node: TaroElement): HarmonyStyle {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/plugin-platform-harmony-ets",
3
- "version": "4.0.0-beta.26",
3
+ "version": "4.0.0-beta.27",
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.26",
29
- "@tarojs/helper": "4.0.0-beta.26",
30
- "@tarojs/service": "4.0.0-beta.26",
31
- "@tarojs/runner-utils": "4.0.0-beta.26",
32
- "@tarojs/runtime": "4.0.0-beta.26",
33
- "@tarojs/shared": "4.0.0-beta.26",
34
- "@tarojs/taro": "4.0.0-beta.26"
28
+ "@tarojs/components": "4.0.0-beta.27",
29
+ "@tarojs/helper": "4.0.0-beta.27",
30
+ "@tarojs/runner-utils": "4.0.0-beta.27",
31
+ "@tarojs/shared": "4.0.0-beta.27",
32
+ "@tarojs/runtime": "4.0.0-beta.27",
33
+ "@tarojs/taro": "4.0.0-beta.27",
34
+ "@tarojs/service": "4.0.0-beta.27"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@rollup/plugin-commonjs": "^25.0.7",
@@ -44,7 +44,7 @@
44
44
  "solid-js": "^1.6.15",
45
45
  "tslib": "^2.4.0",
46
46
  "typescript": "^4.8.2",
47
- "rollup-plugin-copy": "4.0.0-beta.26"
47
+ "rollup-plugin-copy": "4.0.0-beta.27"
48
48
  },
49
49
  "scripts": {
50
50
  "prebuild": "rimraf ./dist",