@tarojs/plugin-platform-harmony-ets 4.0.0-beta.35 → 4.0.0-beta.37

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.
Files changed (35) hide show
  1. package/dist/apis/index.ts +2 -1
  2. package/dist/components-harmony-ets/button.ets +30 -32
  3. package/dist/components-harmony-ets/checkbox.ets +52 -56
  4. package/dist/components-harmony-ets/form.ets +25 -27
  5. package/dist/components-harmony-ets/icon.ets +17 -19
  6. package/dist/components-harmony-ets/image.ets +10 -12
  7. package/dist/components-harmony-ets/input.ets +36 -38
  8. package/dist/components-harmony-ets/label.ets +36 -38
  9. package/dist/components-harmony-ets/movableArea.ets +55 -57
  10. package/dist/components-harmony-ets/movableView.ets +44 -46
  11. package/dist/components-harmony-ets/picker.ets +15 -17
  12. package/dist/components-harmony-ets/progress.ets +22 -24
  13. package/dist/components-harmony-ets/radio.ets +54 -58
  14. package/dist/components-harmony-ets/richText.ets +7 -9
  15. package/dist/components-harmony-ets/scrollView.ets +47 -49
  16. package/dist/components-harmony-ets/slider.ets +8 -10
  17. package/dist/components-harmony-ets/style.ets +103 -4
  18. package/dist/components-harmony-ets/swiper.ets +17 -19
  19. package/dist/components-harmony-ets/switch.ets +24 -26
  20. package/dist/components-harmony-ets/text.ets +80 -43
  21. package/dist/components-harmony-ets/textArea.ets +28 -30
  22. package/dist/components-harmony-ets/video.ets +19 -21
  23. package/dist/components-harmony-ets/view.ets +31 -33
  24. package/dist/components-harmony-ets/webView.ets +30 -32
  25. package/dist/runtime-ets/dom/document.ts +2 -0
  26. package/dist/runtime-ets/dom/element/element.ts +45 -1
  27. package/dist/runtime-ets/dom/element/index.ts +5 -2
  28. package/dist/runtime-ets/dom/element/normal.ts +4 -0
  29. package/dist/runtime-ets/dom/node.ts +11 -7
  30. package/dist/runtime-ets/dom/stylesheet/type.ts +1 -0
  31. package/dist/runtime-utils.js +5 -46
  32. package/dist/runtime-utils.js.map +1 -1
  33. package/dist/runtime.js +5 -46
  34. package/dist/runtime.js.map +1 -1
  35. package/package.json +9 -9
@@ -21,38 +21,36 @@ export default struct TaroWebView {
21
21
  @ObjectLink node: TaroWebViewElement
22
22
 
23
23
  build () {
24
- if (this.node.hmStyle?.display !== 'none') {
25
- Web({ src: this.node._attrs.src, controller: this.node.controller })
26
- .attributeModifier(commonStyleModify.setNode(this.node))
27
- .onPageEnd((e: IPageLoad) => {
28
- // 1. 创建消息端口
29
- this.node.ports = this.node.controller.createWebMessagePorts(true)
30
- // 2. 发送端口1到HTML5
31
- this.node.controller.postMessage('init_web_messageport', [this.node.ports[1]], '*');
32
- // 3. 保存端口0到本地
33
- this.node.nativePort = this.node.ports[0]
34
- // 4. 设置回调函数
35
- this.node.nativePort.onMessageEventExt((result) => {
36
- const message = this.node.handleMessageFromWeb(result)
37
- const messageEvent: TaroEvent = createTaroEvent('message', { detail: { data: message } }, this.node)
38
-
39
- eventHandler(messageEvent, 'message', this.node)
40
- })
41
-
42
- const onLoadEvent: TaroEvent = createTaroEvent('load', { detail: { src: this.node._attrs.src } }, this.node)
43
-
44
- eventHandler(onLoadEvent, 'load', this.node)
24
+ Web({ src: this.node._attrs.src, controller: this.node.controller })
25
+ .attributeModifier(commonStyleModify.setNode(this.node))
26
+ .onPageEnd((e: IPageLoad) => {
27
+ // 1. 创建消息端口
28
+ this.node.ports = this.node.controller.createWebMessagePorts(true)
29
+ // 2. 发送端口1到HTML5
30
+ this.node.controller.postMessage('init_web_messageport', [this.node.ports[1]], '*');
31
+ // 3. 保存端口0到本地
32
+ this.node.nativePort = this.node.ports[0]
33
+ // 4. 设置回调函数
34
+ this.node.nativePort.onMessageEventExt((result) => {
35
+ const message = this.node.handleMessageFromWeb(result)
36
+ const messageEvent: TaroEvent = createTaroEvent('message', { detail: { data: message } }, this.node)
37
+
38
+ eventHandler(messageEvent, 'message', this.node)
45
39
  })
46
- .onErrorReceive(shouldBindEvent((e: IError) => {
47
- const event: TaroEvent = createTaroEvent('error', { detail: { url: this.node._attrs.src, fullUrl: e.request.getRequestUrl() } }, this.node)
48
-
49
- eventHandler(event, 'error', this.node)
50
- }, this.node, ['error']))
51
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
52
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
53
- this.node._nodeInfo.areaInfo = res[1]
54
- }))
55
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
56
- }
40
+
41
+ const onLoadEvent: TaroEvent = createTaroEvent('load', { detail: { src: this.node._attrs.src } }, this.node)
42
+
43
+ eventHandler(onLoadEvent, 'load', this.node)
44
+ })
45
+ .onErrorReceive(shouldBindEvent((e: IError) => {
46
+ const event: TaroEvent = createTaroEvent('error', { detail: { url: this.node._attrs.src, fullUrl: e.request.getRequestUrl() } }, this.node)
47
+
48
+ eventHandler(event, 'error', this.node)
49
+ }, this.node, ['error']))
50
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
51
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
52
+ this.node._nodeInfo.areaInfo = res[1]
53
+ }))
54
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
57
55
  }
58
56
  }
@@ -19,6 +19,8 @@ class TaroDocument extends TaroNode {
19
19
 
20
20
  // 浮动层
21
21
  public fixedLayer: FixedLayer
22
+ // 浮层的父节点关系
23
+ public layerParents: Record<string, Record<string, true>> = {}
22
24
 
23
25
  constructor(window: Window) {
24
26
  super('#document', NodeType.DOCUMENT_NODE)
@@ -243,17 +243,27 @@ export class TaroElement<
243
243
  }
244
244
 
245
245
  // 设置渲染层级,0为正常层级,大于0为固定层级
246
+ // 1、appendChild的时候会判断是否需要设置层级
247
+ // 2、taro-react的setProperty,在处理属性变化的时候,会判断是否需要设置层级
248
+ // 3、removeChild的时候,会判断是否需要移除层级
246
249
  public setLayer (value: number) {
250
+ if (!this.parentNode) return // 没有父节点,不需要设置层级关系
247
251
  this._nodeInfo.layer = value
248
252
 
249
253
  if (value > 0) {
250
- // 插入到root层
254
+ // 插入到固定浮层
251
255
  document.fixedLayer.childNodes.push(this)
252
256
  document.fixedLayer.notifyDataAdd(document.fixedLayer.childNodes.length - 1)
257
+ // 绑定祖先的节点id,建立关系,方便在祖先卸载(removeChild)的时候,能够找到该节点使其卸载
258
+ const _parentRecord = {}
259
+ generateLayerParentIds(_parentRecord, this)
260
+ document.layerParents[this._nid] = _parentRecord
253
261
  } else {
254
262
  const idx = document.fixedLayer.childNodes.findIndex(n => n._nid === this._nid)
255
263
  document.fixedLayer.childNodes.splice(idx, 1)
256
264
  document.fixedLayer.notifyDataDelete(idx)
265
+
266
+ delete document.layerParents[this._nid]
257
267
  }
258
268
 
259
269
  if (this.parentNode) {
@@ -261,4 +271,38 @@ export class TaroElement<
261
271
  this.updateComponent()
262
272
  }
263
273
  }
274
+
275
+ protected toggleLayer(add: boolean) {
276
+ if (add) {
277
+ if (this._st?.hmStyle.position === 'fixed') {
278
+ this.setLayer(1)
279
+ }
280
+ } else {
281
+ // 识别document.layerParents里面是否有需要移除的固定元素
282
+ if (this._nodeInfo?.layer > 0) {
283
+ // @ts-ignore
284
+ delete document.layerParents[this._nid]
285
+ this.setLayer(0)
286
+ } else {
287
+ Object.keys(document.layerParents).forEach(fixedId => {
288
+ const parentIds = document.layerParents[fixedId]
289
+ if (parentIds[this._nid]) {
290
+ // 需要移除fixedId
291
+ delete document.layerParents[fixedId]
292
+ const fixedNode = eventSource.get(fixedId) as unknown as TaroElement
293
+ if (fixedNode) {
294
+ fixedNode.setLayer(0)
295
+ }
296
+ }
297
+ })
298
+ }
299
+ }
300
+ }
301
+ }
302
+
303
+ function generateLayerParentIds(ids: Record<string, true>, node?: TaroElement) {
304
+ if (node?.parentElement) {
305
+ ids[node.parentElement._nid] = true
306
+ generateLayerParentIds(ids, node.parentElement)
307
+ }
264
308
  }
@@ -22,6 +22,7 @@ import {
22
22
  TaroIconElement,
23
23
  TaroImageElement,
24
24
  TaroLabelElement,
25
+ TaroOtherElement,
25
26
  TaroRichTextElement,
26
27
  TaroSwiperElement,
27
28
  TaroSwiperItemElement,
@@ -63,7 +64,7 @@ export function initHarmonyElement () {
63
64
  case 'form': return new TaroFormElement()
64
65
  case 'web-view': return new TaroWebViewElement()
65
66
  case 'inner-html': return new TaroInnerHtmlElement()
66
- default: return new TaroElement(tagName)
67
+ default: return new TaroOtherElement(tagName)
67
68
  }
68
69
  }
69
70
 
@@ -88,6 +89,7 @@ export {
88
89
  TaroLabelElement,
89
90
  TaroMovableAreaElement,
90
91
  TaroMovableViewElement,
92
+ TaroOtherElement,
91
93
  TaroPickerElement,
92
94
  TaroProgressElement,
93
95
  TaroRadioElement,
@@ -102,4 +104,5 @@ export {
102
104
  TaroTextElement,
103
105
  TaroVideoElement,
104
106
  TaroViewElement,
105
- TaroWebViewElement }
107
+ TaroWebViewElement
108
+ }
@@ -12,6 +12,9 @@ import type {
12
12
  ViewProps
13
13
  } from '@tarojs/components/types'
14
14
 
15
+ @Observed
16
+ class TaroOtherElement extends TaroElement<ViewProps> {}
17
+
15
18
  @Observed
16
19
  class TaroViewElement extends TaroElement<ViewProps> {
17
20
  constructor() {
@@ -83,6 +86,7 @@ export {
83
86
  TaroIconElement,
84
87
  TaroImageElement,
85
88
  TaroLabelElement,
89
+ TaroOtherElement,
86
90
  TaroRichTextElement,
87
91
  TaroSwiperElement,
88
92
  TaroSwiperItemElement,
@@ -176,6 +176,9 @@ export class TaroNode extends TaroDataSourceElement {
176
176
  this.childNodes.push(child)
177
177
  this.notifyDataAdd(this.childNodes.length - 1)
178
178
 
179
+ // @ts-ignore
180
+ child.toggleLayer?.(true)
181
+
179
182
  checkIsCompileModeAndInstallAfterDOMAction(child, this)
180
183
  return child
181
184
  }
@@ -191,6 +194,9 @@ export class TaroNode extends TaroDataSourceElement {
191
194
  this.connectParentNode(newNode)
192
195
  // TODO: 优化
193
196
  this.notifyDataReload()
197
+
198
+ // @ts-ignore
199
+ newNode.toggleLayer?.(true)
194
200
  }
195
201
 
196
202
  checkIsCompileModeAndInstallAfterDOMAction(newNode, this)
@@ -220,13 +226,6 @@ export class TaroNode extends TaroDataSourceElement {
220
226
  const idx = this.findIndex(child)
221
227
  if (idx < 0) throw new Error('TaroNode:removeChild NotFoundError')
222
228
 
223
- // 渲染,层级大于0的节点需要让其回到正常层级,然后删掉
224
- // @ts-ignore
225
- if (child._nodeInfo?.layer > 0) {
226
- // @ts-ignore
227
- child.setLayer(0) // 删除固定层级上的节点
228
- }
229
-
230
229
  this.childNodes.splice(idx, 1)
231
230
  child.dispose()
232
231
  this.notifyDataDelete(idx)
@@ -237,9 +236,14 @@ export class TaroNode extends TaroDataSourceElement {
237
236
  }
238
237
 
239
238
  public dispose () {
239
+ // 渲染,层级大于0的节点需要让其回到正常层级,然后删掉
240
+ // @ts-ignore
241
+ this.toggleLayer?.(false)
242
+
240
243
  this.parentNode = null
241
244
  this.childNodes = []
242
245
  }
246
+
243
247
  }
244
248
 
245
249
  @Observed
@@ -32,6 +32,7 @@ export interface TaroStyleType {
32
32
  maxWidth?: Length
33
33
 
34
34
  display?: 'flex' | 'block' | 'none'
35
+ visibility?: 'visible' | 'hidden'
35
36
 
36
37
  // position
37
38
  position?: 'relative' | 'absolute' | 'fixed'
@@ -32,7 +32,7 @@ import dataPreferences from '@ohos.data.preferences';
32
32
  import hilog from '@ohos.hilog';
33
33
  import matrix4 from '@ohos.matrix4';
34
34
  import prompt from '@ohos.prompt';
35
- import { pxTransformHelper as pxTransformHelper$1 } from '@tarojs/taro';
35
+ import { pxTransformHelper } from '@tarojs/taro';
36
36
 
37
37
  class MethodHandler {
38
38
  constructor({ name, success, fail, complete }) {
@@ -3880,7 +3880,7 @@ const pageScrollTo = (options) => {
3880
3880
  scroller = getPageScrollerOrNode(scroller, page);
3881
3881
  const { yOffset } = scroller.currentOffset();
3882
3882
  if (areaInfo) {
3883
- scrollValue = areaInfo.globalPosition.y + yOffset + pxTransformHelper$1(offsetTop, 'px', true);
3883
+ scrollValue = areaInfo.globalPosition.y + yOffset + pxTransformHelper(offsetTop, 'px', true);
3884
3884
  }
3885
3885
  }
3886
3886
  const { xOffset } = scroller.currentOffset();
@@ -4880,49 +4880,7 @@ function initPxTransform({ designWidth = defaultDesignWidth, deviceRatio = defau
4880
4880
  }
4881
4881
  }
4882
4882
  const display = _display.getDefaultDisplaySync();
4883
- let displayWidth = display.width;
4884
- let ratioCache = false;
4885
- let designWidthFunc;
4886
- let designWidth = defaultDesignWidth;
4887
- let deviceRatio = defaultDesignRatio;
4888
- function getRatio(value) {
4889
- var _a;
4890
- // Note: 提前调用 display 可能无法获取正确值
4891
- if (ratioCache === false || displayWidth !== display.width) {
4892
- const config = ((_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config) || {};
4893
- if (!isFunction(designWidthFunc)) {
4894
- designWidthFunc = isFunction(config.designWidth)
4895
- ? config.designWidth
4896
- : () => config.designWidth;
4897
- designWidth = designWidthFunc(value) || defaultDesignWidth;
4898
- deviceRatio = config.deviceRatio || defaultDesignRatio;
4899
- if (!(designWidth in deviceRatio)) {
4900
- throw new Error(`deviceRatio 配置中不存在 ${designWidth} 的设置!`);
4901
- }
4902
- }
4903
- displayWidth = display.width;
4904
- ratioCache = Math.min(display.width, display.height) / designWidth / deviceRatio[designWidth];
4905
- }
4906
- return ratioCache;
4907
- }
4908
- // Note: 设置为 style 单位时会自动完成设计稿转换,设计开发者调用 API 时也许抹平差异,例如 pageScrollTo[option.offsetTop]
4909
- function pxTransformHelper(size, unit, isNumber = false) {
4910
- var _a;
4911
- const config = ((_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config) || {};
4912
- const targetUnit = unit || config.targetUnit || defaultTargetUnit;
4913
- if (targetUnit === 'PX') {
4914
- return px2vp(size * display.scaledDensity) + 'vp';
4915
- }
4916
- const ratio = getRatio(size);
4917
- let val = size * ratio;
4918
- switch (targetUnit) {
4919
- case 'vp':
4920
- // Note: 在应用创建前调用无效
4921
- val = px2vp(val);
4922
- break;
4923
- }
4924
- return isNumber ? val : val + targetUnit;
4925
- }
4883
+ display.width;
4926
4884
  function pxTransform(size) {
4927
4885
  var _a;
4928
4886
  const config = ((_a = Current.taro) === null || _a === void 0 ? void 0 : _a.config) || {};
@@ -4930,7 +4888,8 @@ function pxTransform(size) {
4930
4888
  const val = size;
4931
4889
  switch (targetUnit) {
4932
4890
  case 'vp':
4933
- return pxTransformHelper(size, 'px');
4891
+ // return pxTransformHelper(size, 'px')
4892
+ return `${size}lpx`;
4934
4893
  // NOTE: 鸿蒙环境下 style 会自动完成设计稿转换,无需在方法内二次调整
4935
4894
  }
4936
4895
  return val + targetUnit;