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

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.
@@ -30,14 +30,14 @@ export class IntersectionObserver implements Taro.IntersectionObserver {
30
30
  this._observerNodes.forEach((n: TaroElement & any) => {
31
31
  disconnectEvent(n, VISIBLE_CHANGE_EVENT_NAME)
32
32
  // @ts-ignore
33
- n._nodeInfo?.thresholds = null
33
+ n._nodeInfo.thresholds = null
34
34
  })
35
35
  } else {
36
36
  disconnectEvent(this._observerNodes, VISIBLE_CHANGE_EVENT_NAME)
37
37
  // @ts-ignore
38
38
  if (this._observerNodes._nodeInfo) {
39
39
  // @ts-ignore
40
- this._observerNodes._nodeInfo?.thresholds = null
40
+ this._observerNodes._nodeInfo.thresholds = null
41
41
  }
42
42
  }
43
43
  }
@@ -54,7 +54,7 @@ export class IntersectionObserver implements Taro.IntersectionObserver {
54
54
  if (node instanceof Array) {
55
55
  node.forEach(n => {
56
56
  // @ts-ignore
57
- n._nodeInfo?.thresholds = thresholds
57
+ n._nodeInfo.thresholds = thresholds
58
58
 
59
59
  setNodeEventCallbackAndTriggerComponentUpdate(n, VISIBLE_CHANGE_EVENT_NAME, (isVisible: boolean, currentRatio: number) => {
60
60
  callback(this.handleResult(isVisible, currentRatio, n))
@@ -62,7 +62,7 @@ export class IntersectionObserver implements Taro.IntersectionObserver {
62
62
  })
63
63
  } else {
64
64
  // @ts-ignore
65
- node._nodeInfo?.thresholds = thresholds
65
+ node._nodeInfo.thresholds = thresholds
66
66
 
67
67
  setNodeEventCallbackAndTriggerComponentUpdate(node, VISIBLE_CHANGE_EVENT_NAME, (isVisible: boolean, currentRatio: number) => {
68
68
  callback(this.handleResult(isVisible, currentRatio, node))
@@ -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 {
@@ -4009,14 +4009,12 @@ class IntersectionObserver {
4009
4009
  Object.assign(this._options, options);
4010
4010
  }
4011
4011
  disconnect() {
4012
- var _a;
4013
4012
  if (this._observerNodes && this._component) {
4014
4013
  if (this._observerNodes instanceof Array) {
4015
4014
  this._observerNodes.forEach((n) => {
4016
- var _a;
4017
4015
  disconnectEvent(n, VISIBLE_CHANGE_EVENT_NAME);
4018
4016
  // @ts-ignore
4019
- (_a = n._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = null;
4017
+ n._nodeInfo.thresholds = null;
4020
4018
  });
4021
4019
  }
4022
4020
  else {
@@ -4024,13 +4022,12 @@ class IntersectionObserver {
4024
4022
  // @ts-ignore
4025
4023
  if (this._observerNodes._nodeInfo) {
4026
4024
  // @ts-ignore
4027
- (_a = this._observerNodes._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = null;
4025
+ this._observerNodes._nodeInfo.thresholds = null;
4028
4026
  }
4029
4027
  }
4030
4028
  }
4031
4029
  }
4032
4030
  observe(targetSelector, callback) {
4033
- var _a;
4034
4031
  if (!this._component)
4035
4032
  return;
4036
4033
  const { observeAll, thresholds } = this._options;
@@ -4039,9 +4036,8 @@ class IntersectionObserver {
4039
4036
  if (node) {
4040
4037
  if (node instanceof Array) {
4041
4038
  node.forEach(n => {
4042
- var _a;
4043
4039
  // @ts-ignore
4044
- (_a = n._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = thresholds;
4040
+ n._nodeInfo.thresholds = thresholds;
4045
4041
  setNodeEventCallbackAndTriggerComponentUpdate(n, VISIBLE_CHANGE_EVENT_NAME, (isVisible, currentRatio) => {
4046
4042
  callback(this.handleResult(isVisible, currentRatio, n));
4047
4043
  });
@@ -4049,7 +4045,7 @@ class IntersectionObserver {
4049
4045
  }
4050
4046
  else {
4051
4047
  // @ts-ignore
4052
- (_a = node._nodeInfo) === null || _a === void 0 ? void 0 : _a.thresholds = thresholds;
4048
+ node._nodeInfo.thresholds = thresholds;
4053
4049
  setNodeEventCallbackAndTriggerComponentUpdate(node, VISIBLE_CHANGE_EVENT_NAME, (isVisible, currentRatio) => {
4054
4050
  callback(this.handleResult(isVisible, currentRatio, node));
4055
4051
  });