@tarojs/plugin-platform-harmony-ets 4.0.0-beta.13 → 4.0.0-beta.15

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.
@@ -5,38 +5,53 @@ import deviceInfo from '@ohos.deviceInfo'
5
5
  import _display from '@ohos.display'
6
6
  // 从 API Version 7 开始支持
7
7
  import i18n from '@ohos.i18n'
8
+ import { Current, window } from '@tarojs/runtime'
8
9
 
9
10
  import { callAsyncFail, callAsyncSuccess } from '../utils'
10
11
 
11
12
  import type Taro from '@tarojs/taro/types'
12
13
 
13
14
  let display
15
+ let navigationIndicatorRect
14
16
  let safeArea: TaroGeneral.SafeAreaResult | null = null
15
- try {
16
- display = _display.getDefaultDisplaySync()
17
- // @ts-ignore
18
- display.getCutoutInfo((err, { boundingRects = [], waterfallDisplayAreaRects = {} }: _display.CutoutInfo = {}) => {
19
- if (err?.code) {
20
- console.error('Failed to get cutout info', JSON.stringify(err))
21
- return
22
- }
17
+ let statusBarHeight
18
+ let windowRect
19
+
20
+ (Current as any).contextPromise.then((context) => {
21
+ const win = window.__ohos.getLastWindow(context)
22
+ win.then(mainWindow => {
23
+ const topRect = mainWindow.getWindowAvoidArea(window.__ohos.AvoidAreaType.TYPE_SYSTEM).topRect
24
+ navigationIndicatorRect = mainWindow.getWindowAvoidArea(window.__ohos.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect
25
+ statusBarHeight = topRect.top + topRect.height
26
+ windowRect = mainWindow.getWindowProperties().windowRect
23
27
 
24
- const top = Math.max(...boundingRects.map(rect => rect.top * 2 + rect.height), waterfallDisplayAreaRects.top?.top + waterfallDisplayAreaRects.top?.height)
25
- const bottom = (waterfallDisplayAreaRects.bottom?.top + waterfallDisplayAreaRects.bottom?.height) || display.height
26
- const left = waterfallDisplayAreaRects.left?.left + waterfallDisplayAreaRects.left?.width
27
- const right = (waterfallDisplayAreaRects.right?.left + waterfallDisplayAreaRects.right?.width) || display.width
28
- safeArea = {
29
- top,
30
- bottom,
31
- left,
32
- right,
33
- height: bottom - top,
34
- width: right - left,
28
+ try {
29
+ display = _display.getDefaultDisplaySync()
30
+ // @ts-ignore
31
+ display.getCutoutInfo((err, { boundingRects = [], waterfallDisplayAreaRects = {} }: _display.CutoutInfo = {}) => {
32
+ if (err?.code) {
33
+ console.error('Failed to get cutout info', JSON.stringify(err))
34
+ return
35
+ }
36
+
37
+ const top = Math.max(...boundingRects.map(rect => rect.top + rect.height), waterfallDisplayAreaRects.top?.top + waterfallDisplayAreaRects.top?.height, statusBarHeight)
38
+ const bottom = display.height - Math.min(waterfallDisplayAreaRects.bottom?.top, navigationIndicatorRect?.top)
39
+ const left = waterfallDisplayAreaRects.left?.left + waterfallDisplayAreaRects.left?.width
40
+ const right = display.width - waterfallDisplayAreaRects.right?.left
41
+ safeArea = {
42
+ top,
43
+ bottom,
44
+ left,
45
+ right,
46
+ height: bottom - top,
47
+ width: right - left,
48
+ }
49
+ })
50
+ } catch (e) {
51
+ console.error('Failed to get display', e)
35
52
  }
36
53
  })
37
- } catch (e) {
38
- console.error('Failed to get display', e)
39
- }
54
+ })
40
55
 
41
56
  /* 同步版本 */
42
57
  export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
@@ -65,12 +80,12 @@ export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
65
80
  res.safeArea = safeArea // 在竖屏正方向下的安全区域 General.SafeAreaResult
66
81
  res.screenHeight = display?.height // 屏幕高度,单位px number
67
82
  res.screenWidth = display?.width // 屏幕宽度,单位px number
68
- res.statusBarHeight = safeArea?.top // 状态栏的高度,单位px number
83
+ res.statusBarHeight = statusBarHeight // 状态栏的高度,单位px number
69
84
  res.system = deviceInfo?.osFullName // 操作系统及版本 string
70
85
  // Note: 更新配置时才能记录
71
86
  res.theme = AppStorage.get('__TARO_APP_CONFIG')?.colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK ? 'dark' : 'light' // 系统当前主题,取值为light或dark 'light' | 'dark'
72
- res.windowHeight = display?.height // 可使用窗口高度,单位px number
73
- res.windowWidth = display?.width // 可使用窗口宽度,单位px number
87
+ res.windowHeight = windowRect?.height // 可使用窗口高度,单位px number
88
+ res.windowWidth = windowRect?.width // 可使用窗口宽度,单位px number
74
89
  res.version = deviceInfo?.displayVersion // 版本号 string
75
90
 
76
91
  return res
@@ -1,4 +1,4 @@
1
- import type { TaroMovableAreaElement, TaroStyleType } from '@tarojs/runtime'
1
+ import type { TaroMovableAreaElement, TaroStyleType, TaroMovableViewElement} from '@tarojs/runtime'
2
2
  import commonStyleModify from './style'
3
3
  import { createLazyChildren } from './render'
4
4
 
@@ -30,9 +30,6 @@ function columnAttrs(style: TaroStyleType) {
30
30
  export default struct TaroMovableArea {
31
31
  @ObjectLink node: TaroMovableAreaElement
32
32
 
33
- @Provide areaWidth: Length = 0
34
- @Provide areaHeight: Length = 0
35
-
36
33
  build() {
37
34
  if (this.node) {
38
35
  if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node).direction !== FlexDirection.Column) {
@@ -45,9 +42,33 @@ export default struct TaroMovableArea {
45
42
  .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
46
43
  .clip(true)
47
44
  .onAreaChange((oldValue: Area, newValue: Area) => {
48
- this.areaWidth = newValue.width
49
- this.areaHeight = newValue.height
45
+ this.node.childNodes.forEach(item => {
46
+ if(item.nodeName === 'MOVABLE-VIEW') {
47
+ ;(item as TaroMovableViewElement).area = {
48
+ w: Number( newValue.width),
49
+ h: Number(newValue.height)
50
+ }
51
+ }
52
+ })
50
53
  })
54
+ .gesture(
55
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
56
+ this.node.childNodes.forEach(item => {
57
+ if(item.nodeName === 'MOVABLE-VIEW') {
58
+ ;(item as TaroMovableViewElement).startScale()
59
+ }
60
+ })
61
+ }).onActionUpdate((event) => {
62
+ const scaleArea = this.node.getAttribute('scaleArea')
63
+ if (scaleArea) {
64
+ this.node.childNodes.forEach(item => {
65
+ if(item.nodeName === 'MOVABLE-VIEW') {
66
+ ;(item as TaroMovableViewElement).doScale(event.scale)
67
+ }
68
+ })
69
+ }
70
+ })
71
+ )
51
72
  } else {
52
73
  Column() {
53
74
  createLazyChildren(this.node)
@@ -58,9 +79,33 @@ export default struct TaroMovableArea {
58
79
  .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
59
80
  .clip(true)
60
81
  .onAreaChange((oldValue: Area, newValue: Area) => {
61
- this.areaWidth = newValue.width
62
- this.areaHeight = newValue.height
82
+ this.node.childNodes.forEach(item => {
83
+ if(item.nodeName === 'MOVABLE-VIEW') {
84
+ ;(item as TaroMovableViewElement).area = {
85
+ w: Number( newValue.width),
86
+ h: Number(newValue.height)
87
+ }
88
+ }
89
+ })
63
90
  })
91
+ .gesture(
92
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
93
+ this.node.childNodes.forEach(item => {
94
+ if(item.nodeName === 'MOVABLE-VIEW') {
95
+ ;(item as TaroMovableViewElement).startScale()
96
+ }
97
+ })
98
+ }).onActionUpdate((event) => {
99
+ const scaleArea = this.node.getAttribute('scaleArea')
100
+ if (scaleArea) {
101
+ this.node.childNodes.forEach(item => {
102
+ if(item.nodeName === 'MOVABLE-VIEW') {
103
+ ;(item as TaroMovableViewElement).doScale(event.scale)
104
+ }
105
+ })
106
+ }
107
+ })
108
+ )
64
109
  }
65
110
  }
66
111
  }
@@ -1,10 +1,11 @@
1
- import type { TaroMovableViewElement, TaroStyleType } from '@tarojs/runtime'
1
+ import type { TaroMovableViewElement, TaroStyleType, TaroAny } from '@tarojs/runtime'
2
2
 
3
3
  import commonStyleModify from './style'
4
4
  import { createLazyChildren } from './render'
5
5
 
6
6
  import { FlexManager } from './utils/flexManager'
7
7
  import { getNormalAttributes, } from './utils/helper'
8
+
8
9
  @Extend(Row)
9
10
  function rowAttrs(style: TaroStyleType) {
10
11
  .constraintSize({
@@ -25,42 +26,65 @@ function columnAttrs(style: TaroStyleType) {
25
26
  })
26
27
  }
27
28
 
29
+
28
30
  @Component
29
- export default struct TaroMovableArea {
31
+ export default struct TaroMovableView {
30
32
  @ObjectLink node: TaroMovableViewElement
31
33
 
32
- @Provide areaWidth: Length = 0
33
- @Provide areaHeight: Length = 0
34
-
35
34
  build() {
36
35
  if (this.node) {
37
- if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node).direction !== FlexDirection.Column) {
38
- Row() {
39
- createLazyChildren(this.node)
40
- }
41
- .attributeModifier(commonStyleModify.setNode(this.node))
42
- .rowAttrs(getNormalAttributes(this.node))
43
- .alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
44
- .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
45
- .clip(true)
46
- .onAreaChange((oldValue: Area, newValue: Area) => {
47
- this.areaWidth = newValue.width
48
- this.areaHeight = newValue.height
49
- })
50
- } else {
51
- Column() {
52
- createLazyChildren(this.node)
36
+ Stack() {
37
+ if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node)
38
+ .direction !== FlexDirection.Column) {
39
+ Row() {
40
+ createLazyChildren(this.node)
41
+ }
42
+ .attributeModifier(commonStyleModify.setNode(this.node))
43
+ .rowAttrs(getNormalAttributes(this.node))
44
+ .alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
45
+ .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
46
+ } else {
47
+ Column() {
48
+ createLazyChildren(this.node)
49
+ }
50
+ .attributeModifier(commonStyleModify.setNode(this.node))
51
+ .columnAttrs(getNormalAttributes(this.node))
52
+ .alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
53
+ .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
53
54
  }
54
- .attributeModifier(commonStyleModify.setNode(this.node))
55
- .columnAttrs(getNormalAttributes(this.node))
56
- .alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
57
- .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
58
- .clip(true)
59
- .onAreaChange((oldValue: Area, newValue: Area) => {
60
- this.areaWidth = newValue.width
61
- this.areaHeight = newValue.height
62
- })
63
55
  }
56
+ .translate({ x: this.node.position.x, y: this.node.position.y })
57
+ .scale({ x: this.node.scaleValue, y: this.node.scaleValue })
58
+ .onAreaChange((oldValue: Area, newValue: Area) => {
59
+ this.node.selfSize = {w: Number(newValue.width), h: Number(newValue.height)}
60
+ })
61
+ .gesture(
62
+ GestureGroup(GestureMode.Exclusive,
63
+ PanGesture({fingers:1}).onActionStart((e: GestureEvent) => {
64
+
65
+ this.node.startMove()
66
+ }).onActionUpdate((e: GestureEvent) => {
67
+
68
+ this.node.doMove({
69
+ x: e.offsetX,
70
+ y: e.offsetY
71
+ })
72
+ // 事件处理
73
+ const bindchange = this.node.getAttribute('bindchange')
74
+ if (typeof bindchange === 'function') {
75
+ }
76
+
77
+ }).onActionEnd(() => {
78
+ // this.updatePosition()
79
+ this.node.checkPositionBoundary(this.node.position, this.node.scaleValue)
80
+ }),
81
+ PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
82
+ this.node.startScale()
83
+ }).onActionUpdate((event) => {
84
+ this.node.doScale(event.scale)
85
+ })
86
+ )
87
+ )
64
88
  }
65
89
  }
66
90
  }
@@ -60,7 +60,7 @@ class AttributeManager {
60
60
  const dataValue: string = AttributeManager.getNodeStyle(style, 'animation')
61
61
 
62
62
  if (dataValue) {
63
- let values: string[] = dataValue.trim().split(new RegExp("/\s+/"))
63
+ let values: string[] = dataValue.toString().trim().split(new RegExp("/\s+/"))
64
64
  switch (values.length) {
65
65
  case 4:
66
66
  res = { duration: values[0], curve: values[1], delay: values[2] }
@@ -30,7 +30,7 @@ export function getUnit (val) {
30
30
  function handleNodeStyleData (dataValue: string, handler: (values: string[]) => { [key: string]: string } | void) {
31
31
  let res: any = {}
32
32
  if (dataValue) {
33
- const values = dataValue.trim().split(/\s+/)
33
+ const values = dataValue.toString().trim().split(/\s+/)
34
34
  const data = handler(values)
35
35
 
36
36
  if (!data) return res
package/dist/index.js CHANGED
@@ -158,7 +158,7 @@ export {
158
158
  const PLATFORM_NAME = 'harmony';
159
159
  const PACKAGE_NAME = '@tarojs/plugin-platform-harmony-ets';
160
160
  const PLUGIN_NAME = 'TaroHarmony';
161
- const HARMONY_SCOPES = [/^@system\./, /^@ohos\./, /^@hmscore\//, /^@jd-oh\//];
161
+ const HARMONY_SCOPES = [/^@system\./, /^@ohos\./, /^@hmscore\//];
162
162
 
163
163
  function parseRelativePath(from, to) {
164
164
  const relativePath = path.relative(from, to).replace(/\\/g, '/');
@@ -1325,6 +1325,7 @@ function assertHarmonyConfig(ctx, config) {
1325
1325
  }
1326
1326
  }
1327
1327
 
1328
+ exports.HarmonyOS_ArkTS = Harmony$1;
1328
1329
  exports.HarmonyOS_JSUI = Harmony;
1329
1330
  exports.default = index;
1330
1331
  //# sourceMappingURL=index.js.map