@tarojs/plugin-platform-harmony-ets 4.0.0-beta.25 → 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.
@@ -19,7 +19,7 @@ export function temporarilyNotSupport (name: string, recommended?: string) {
19
19
  return (option = {}, ...args) => {
20
20
  const { success, fail, complete } = option as any
21
21
  const handle = new MethodHandler({ name, success, fail, complete })
22
- let errMsg = '暂时不支持 API'
22
+ let errMsg = `暂时不支持 API ${name}`
23
23
  if (recommended) {
24
24
  errMsg += `, 请使用 ${recommended}`
25
25
  }
@@ -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 {
@@ -186,7 +186,7 @@ function temporarilyNotSupport(name, recommended) {
186
186
  return (option = {}, ...args) => {
187
187
  const { success, fail, complete } = option;
188
188
  const handle = new MethodHandler({ name, success, fail, complete });
189
- let errMsg = '暂时不支持 API';
189
+ let errMsg = `暂时不支持 API ${name}`;
190
190
  if (recommended) {
191
191
  errMsg += `, 请使用 ${recommended}`;
192
192
  }