@tarojs/plugin-platform-harmony-ets 4.0.0-beta.40 → 4.0.0-beta.41

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.
@@ -78,7 +78,7 @@ function getRatio (value: number) {
78
78
  }
79
79
  }
80
80
  displayWidth = display.width
81
- ratioCache = Math.min(display.width, display.height) / designWidth / deviceRatio[designWidth]
81
+ ratioCache = Math.min(display.width, display.height) / designWidth
82
82
  }
83
83
 
84
84
  return ratioCache
@@ -112,8 +112,8 @@ export function pxTransform (size: number): number | string {
112
112
  const val = size
113
113
  switch (targetUnit) {
114
114
  case 'vp':
115
- // return pxTransformHelper(size, 'px')
116
- return `${size}lpx`
115
+ return pxTransformHelper(size, 'px')
116
+ // return `${size}lpx`
117
117
  default:
118
118
  // NOTE: 鸿蒙环境下 style 会自动完成设计稿转换,无需在方法内二次调整
119
119
  }
@@ -3,8 +3,7 @@
3
3
  * https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-data-preferences-0000001427745052-V3
4
4
  */
5
5
  import bundleManager from '@ohos.bundle.bundleManager'
6
- import dataPreferences from '@ohos.data.preferences'
7
- import hilog from '@ohos.hilog'
6
+ import distributedKVStore from '@ohos.data.distributedKVStore'
8
7
  import { Current } from '@tarojs/runtime'
9
8
 
10
9
  import { temporarilyNotSupport, validateParams } from '../utils'
@@ -13,32 +12,53 @@ import { MethodHandler } from '../utils/handler'
13
12
  import type Taro from '@tarojs/taro/types'
14
13
 
15
14
  let context
16
- let preferences: any
15
+ let kvManager: distributedKVStore.KVManager
16
+ let kvStore: distributedKVStore.SingleKVStore
17
17
 
18
18
  (Current as any).contextPromise.then((ctx) => {
19
19
  context = ctx
20
- return context
21
- })
20
+ const kvManagerConfig: distributedKVStore.KVManagerConfig = {
21
+ context: context,
22
+ bundleName: 'com.example.taro'
23
+ }
22
24
 
23
- function getPreferences () {
24
25
  try {
25
- if (!preferences && context) {
26
- const data = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION)
27
- preferences = dataPreferences.getPreferencesSync(context, { name: `${data.appInfo.uid}Store` })
26
+ // 创建KVManager实例
27
+ kvManager = distributedKVStore.createKVManager(kvManagerConfig)
28
+ // 继续创建获取数据库
29
+ const options: distributedKVStore.Options = {
30
+ createIfMissing: true,
31
+ encrypt: false,
32
+ backup: false,
33
+ autoSync: false,
34
+ // kvStoreType不填时,默认创建多设备协同数据库
35
+ kvStoreType: distributedKVStore.KVStoreType.SINGLE_VERSION,
36
+ // 多设备协同数据库:kvStoreType: distributedKVStore.KVStoreType.DEVICE_COLLABORATION,
37
+ securityLevel: distributedKVStore.SecurityLevel.S1
28
38
  }
29
- } catch (error) {
30
- hilog.error(0x0000, 'TaroFailedTag', 'Failed to load the storage. Cause: %{public}s', error.code ? JSON.stringify(error) : error.message || error)
39
+
40
+ const data = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION)
41
+ kvManager.getKVStore<distributedKVStore.SingleKVStore>(`${data.appInfo.uid}Store`, options, (err, store: distributedKVStore.SingleKVStore) => {
42
+ if (err) {
43
+ console.error(`Failed to get KVStore: Code:${err.code},message:${err.message}`)
44
+ return
45
+ }
46
+ kvStore = store
47
+ // 请确保获取到键值数据库实例后,再进行相关数据操作
48
+ })
49
+ } catch (e) {
50
+ console.error(`Failed to create KVManager. Code:${e.code},message:${e.message}`)
31
51
  }
32
52
 
33
- return preferences
34
- }
53
+ return context
54
+ })
35
55
 
36
56
  const storageSchema = {
37
57
  key: 'String'
38
58
  }
39
59
 
40
60
  function checkContextExist (api: string, isAsync = false) {
41
- if (!context) {
61
+ if (!context || !kvStore) {
42
62
  const message = `${api} 调用失败,Taro 不支持过早地调用 ${api},请确保页面已经渲染完成再调用此 API`
43
63
  if (isAsync) {
44
64
  return {
@@ -78,45 +98,18 @@ export function getStorage<T = any> (options: Taro.getStorage.Option<T>) {
78
98
  return handle.fail(res, { resolve, reject })
79
99
  }
80
100
 
81
- const preferences = getPreferences()
82
-
83
- if (!preferences) return handle.fail({}, { resolve, reject })
101
+ kvStore = kvStore as distributedKVStore.SingleKVStore
102
+ kvStore.get(key, (err, data) => {
103
+ if (!err) {
104
+ handle.fail({ errMsg: `Failed to get data. Code:${err.code},message:${err.message}` }, { resolve, reject })
105
+ return
106
+ }
84
107
 
85
- const data = preferences.getSync(key, null)
86
- if (data) {
87
- return handle.success({ data }, { resolve, reject })
88
- } else {
89
- return handle.success({ errMsg: 'data not found' }, { resolve, reject })
90
- }
108
+ handle.success({ data }, { resolve, reject })
109
+ })
91
110
  })
92
111
  }
93
112
 
94
- export function getStorageSync (key: string) {
95
- const name = 'getStorageSync'
96
- const { isExist, error } = checkContextExist(name, false)
97
-
98
- if (!isExist) {
99
- return error
100
- }
101
-
102
- if (!key) {
103
- throw new Error(`${name}:fail parameter error: parameter should be String`)
104
- }
105
-
106
- const preferences = getPreferences()
107
-
108
- if (!preferences) {
109
- throw new Error(`${name}:fail:preferences is null`)
110
- }
111
-
112
- const data = preferences.getSync(key, null)
113
- if (data) {
114
- return data
115
- } else {
116
- throw new Error('data not found')
117
- }
118
- }
119
-
120
113
  export function setStorage (options: Taro.setStorage.Option) {
121
114
  const name = 'setStorage'
122
115
  const { isExist, error } = checkContextExist(name, true)
@@ -136,39 +129,18 @@ export function setStorage (options: Taro.setStorage.Option) {
136
129
  return handle.fail(res, { resolve, reject })
137
130
  }
138
131
 
139
- const preferences = getPreferences()
140
-
141
- if (!preferences) return handle.fail({}, { resolve, reject })
142
-
143
- preferences.putSync(key, data)
144
- preferences.flush()
132
+ kvStore = kvStore as distributedKVStore.SingleKVStore
133
+ kvStore.put(key, data, (err) => {
134
+ if (!err) {
135
+ handle.fail({ errMsg: `Failed to put data. Code:${err.code},message:${err.message}` }, { resolve, reject })
136
+ return
137
+ }
145
138
 
146
- return handle.success({}, { resolve, reject })
139
+ handle.success({}, { resolve, reject })
140
+ })
147
141
  })
148
142
  }
149
143
 
150
- export function setStorageSync (key: string, data: any) {
151
- const name = 'setStorageSync'
152
- const { isExist, error } = checkContextExist(name, false)
153
-
154
- if (!isExist) {
155
- return error
156
- }
157
-
158
- if (!key) {
159
- throw new Error(`${name}:fail key error: key should be String`)
160
- }
161
-
162
- const preferences = getPreferences()
163
-
164
- if (!preferences) {
165
- throw new Error(`${name}:fail:preferences is null`)
166
- }
167
-
168
- preferences.putSync(key, data)
169
- preferences.flush()
170
- }
171
-
172
144
  export function removeStorage (options: Taro.removeStorage.Option) {
173
145
  const name = 'removeStorage'
174
146
  const { isExist, error } = checkContextExist(name, true)
@@ -188,80 +160,18 @@ export function removeStorage (options: Taro.removeStorage.Option) {
188
160
  return handle.fail(res, { resolve, reject })
189
161
  }
190
162
 
191
- const preferences = getPreferences()
192
-
193
- if (!preferences) return handle.fail({}, { resolve, reject })
194
-
195
- preferences.deleteSync(key)
196
- preferences.flush()
197
-
198
- return handle.success({}, { resolve, reject })
199
- })
200
- }
201
-
202
- export function removeStorageSync (key: string) {
203
- const name = 'removeStorageSync'
204
- const { isExist, error } = checkContextExist(name, false)
205
-
206
- if (!isExist) {
207
- return error
208
- }
209
-
210
- if (!key) {
211
- throw new Error(`${name}:fail key error: key should be String`)
212
- }
213
-
214
- const preferences = getPreferences()
215
-
216
- if (!preferences) {
217
- throw new Error(`${name}:fail:preferences is null`)
218
- }
219
-
220
- preferences.deleteSync(key)
221
- preferences.flush()
222
- }
223
-
224
- export function clearStorage (options: Taro.clearStorage.Option) {
225
- const name = 'clearStorage'
226
- const { isExist, error } = checkContextExist(name, true)
227
-
228
- if (!isExist) {
229
- return error
230
- }
231
-
232
- const { success, fail, complete } = options || {}
233
- const handle = new MethodHandler({ name, success, fail, complete })
234
-
235
- return new Promise((resolve, reject) => {
236
- const preferences = getPreferences()
237
-
238
- if (!preferences) return handle.fail({}, { resolve, reject })
163
+ kvStore = kvStore as distributedKVStore.SingleKVStore
164
+ kvStore.delete(key, (err) => {
165
+ if (!err) {
166
+ handle.fail({ errMsg: `Failed to delete data. Code:${err.code},message:${err.message}` }, { resolve, reject })
167
+ return
168
+ }
239
169
 
240
- preferences.clearSync()
241
- preferences.flush()
242
-
243
- return handle.success({}, { resolve, reject })
170
+ handle.success({}, { resolve, reject })
171
+ })
244
172
  })
245
173
  }
246
174
 
247
- export function clearStorageSync () {
248
- const name = 'clearStorageSync'
249
- const { isExist, error } = checkContextExist(name, false)
250
-
251
- if (!isExist) {
252
- return error
253
- }
254
-
255
- const preferences = getPreferences()
256
-
257
- if (!preferences) {
258
- throw new Error(`${name}:fail:preferences is null`)
259
- }
260
-
261
- preferences.clearSync()
262
- preferences.flush()
263
- }
264
-
265
175
  export const getStorageInfoSync = temporarilyNotSupport('getStorageInfoSync')
266
176
  export const getStorageInfo = temporarilyNotSupport('getStorageInfo')
267
177
 
@@ -273,5 +183,11 @@ export const batchSetStorage = /* @__PURE__ */ temporarilyNotSupport('batchSetSt
273
183
  export const batchGetStorageSync = /* @__PURE__ */ temporarilyNotSupport('batchGetStorageSync')
274
184
  export const batchGetStorage = /* @__PURE__ */ temporarilyNotSupport('batchGetStorage')
275
185
 
186
+ export const clearStorage = temporarilyNotSupport('removeStorageSync')
187
+ export const getStorageSync = temporarilyNotSupport('getStorageSync', 'getStorage')
188
+ export const setStorageSync = temporarilyNotSupport('setStorageSync', 'setStorage')
189
+ export const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clearStorage')
190
+ export const removeStorageSync = temporarilyNotSupport('removeStorageSync', 'removeStorage')
191
+
276
192
  export * from './background-fetch'
277
193
  export * from './cache-manager'
@@ -1,6 +1,6 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
- import { rowModify, columnModify } from './style'
3
+ import commonStyleModify from './style'
4
4
  import PseduoChildren from './pseudo'
5
5
  import { FlexManager } from './utils/flexManager'
6
6
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
@@ -70,9 +70,13 @@ export default struct TaroScrollView {
70
70
  }
71
71
  }
72
72
 
73
+ isScrollX() {
74
+ return this.node._attrs.scrollX || getStyleAttr(this.node, 'overflow') === 'scroll' && getStyleAttr(this.node, 'flexDirection') === FlexDirection.Row
75
+ }
76
+
73
77
  build () {
74
78
  Scroll(this.node.scroller) {
75
- if (this.node._attrs.scrollX) {
79
+ if (this.isScrollX()) {
76
80
  Row() {
77
81
  if (this.node._pseudo_before || this.node._pseudo_after) {
78
82
  PseduoChildren({ node: this.node, createLazyChildren: this.createLazyChildren })
@@ -80,7 +84,9 @@ export default struct TaroScrollView {
80
84
  this.createLazyChildren(this.node)
81
85
  }
82
86
  }
83
- .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
87
+ .alignItems(FlexManager.alignItems<VerticalAlign>(this.node))
88
+ .justifyContent(FlexManager.justifyContent(this.node))
89
+ .height(getStyleAttr(this.node, 'height'))
84
90
  .width(null)
85
91
  .onAreaChange(shouldBindEvent((_: Area, areaResult: Area) => {
86
92
  this.node._nodeInfo._scroll = areaResult
@@ -94,20 +100,21 @@ export default struct TaroScrollView {
94
100
  this.createLazyChildren(this.node)
95
101
  }
96
102
  }
97
- .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
103
+ .alignItems(FlexManager.alignItems<HorizontalAlign>(this.node))
104
+ .justifyContent(FlexManager.justifyContent(this.node))
105
+ .width(getStyleAttr(this.node, 'width'))
98
106
  .height(null)
99
- .alignItems(HorizontalAlign.Start)
100
107
  .onAreaChange(shouldBindEvent((_: Area, areaResult: Area) => {
101
108
  this.node._nodeInfo._scroll = areaResult
102
109
  }, this.node, ['scroll', 'scrollstart', 'scrollend']))
103
110
  .flexGrow(0).flexShrink(0)
104
111
  }
105
112
  }
106
- .width(getStyleAttr(this.node, 'width'))
107
- .height(getStyleAttr(this.node, 'height'))
113
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
114
+ .width(this.isScrollX() ? getStyleAttr(this.node, 'width') : undefined)
115
+ .height(!this.isScrollX() ? getStyleAttr(this.node, 'height') : undefined)
108
116
  .align(Alignment.TopStart)
109
- .flexGrow(this.node.hmStyle?.flexGrow)
110
- .flexShrink(this.node.hmStyle?.flexShrink)
117
+ .clip(true)
111
118
  .scrollable(getScrollable(this.node))
112
119
  .scrollBar(getAttributes(this.node).scrollBar)
113
120
  .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
@@ -116,9 +116,6 @@ class RowStyleModify extends CommonStyleModify {
116
116
  if (this.node) {
117
117
  instance.alignItems(FlexManager.alignItems<VerticalAlign>(this.node))
118
118
  instance.justifyContent(FlexManager.justifyContent(this.node))
119
- if (this.node._st.hmStyle.overflow === 'scroll') {
120
- instance.height('100%')
121
- }
122
119
  }
123
120
  }
124
121
 
@@ -139,9 +136,6 @@ class ColumnStyleModify extends CommonStyleModify {
139
136
  if (this.node) {
140
137
  instance.alignItems(FlexManager.alignItems<HorizontalAlign>(this.node))
141
138
  instance.justifyContent(FlexManager.justifyContent(this.node))
142
- if (this.node._st.hmStyle.overflow === 'scroll') {
143
- instance.width('100%')
144
- }
145
139
  }
146
140
  }
147
141
 
@@ -346,39 +340,6 @@ export function setNormalAttributeIntoInstance(instance: CommonAttribute, style:
346
340
  if (!isUndefined(style.overflow)) {
347
341
  instance.clip(style.overflow === 'hidden')
348
342
  }
349
- // if (!isUndefined(style.transformOrigin)) {
350
- // instance.rotate({ centerX: style.transformOrigin.x, centerY: style.transformOrigin.y, angle: 0 })
351
- // instance.scale({ centerX: style.transformOrigin.x, centerY: style.transformOrigin.y })
352
- // }
353
- // // Note: 移植到setAnimationAttributeIntoInstance设置
354
- // if (!isUndefined(style.transform)) {
355
- // if (style.transform.Translate) {
356
- // instance.translate({
357
- // x: style.transform.Translate.x || 0,
358
- // y: style.transform.Translate.y || 0,
359
- // z: style.transform.Translate.z || 0,
360
- // })
361
- // }
362
- // if (style.transform.Scale) {
363
- // instance.scale({
364
- // x: style.transform.Scale.x || 0,
365
- // y: style.transform.Scale.y || 0,
366
- // z: style.transform.Scale.z || 0,
367
- // centerX: style.transformOrigin?.x || 0,
368
- // centerY: style.transformOrigin?.y || 0,
369
- // })
370
- // }
371
- // if (style.transform.Rotate) {
372
- // instance.rotate({
373
- // x: style.transform.Rotate.x || 0,
374
- // y: style.transform.Rotate.y || 0,
375
- // z: style.transform.Rotate.z || 0,
376
- // centerX: style.transformOrigin?.x || 0,
377
- // centerY: style.transformOrigin?.y || 0,
378
- // angle: 0
379
- // })
380
- // }
381
- // }
382
343
  if (style.position === 'absolute' || style.position === 'fixed') {
383
344
  instance.position({
384
345
  x: style.left || 0,
@@ -13,6 +13,8 @@ interface SwiperAttrs {
13
13
  vertical?: boolean
14
14
  autoPlay?: boolean
15
15
  indicator?: boolean
16
+ nextMargin?: Length
17
+ prevMargin?: Length
16
18
  }
17
19
 
18
20
  @Extend(Swiper)
@@ -24,6 +26,8 @@ function swiperAttr (attr: SwiperAttrs) {
24
26
  .vertical(attr.vertical)
25
27
  .autoPlay(attr.autoPlay)
26
28
  .indicator(attr.indicator)
29
+ .nextMargin(attr.nextMargin)
30
+ .prevMargin(attr.prevMargin)
27
31
  }
28
32
 
29
33
  function getSwiperAttributes (node: TaroSwiperElement): SwiperAttrs {
@@ -36,6 +40,8 @@ function getSwiperAttributes (node: TaroSwiperElement): SwiperAttrs {
36
40
  swiperAttrs.vertical = _attrs.vertical || false
37
41
  swiperAttrs.autoPlay = _attrs.autoplay || false
38
42
  swiperAttrs.indicator = _attrs.indicatorDots || false
43
+ swiperAttrs.nextMargin = _attrs.nextMargin || 0
44
+ swiperAttrs.prevMargin = _attrs.previousMargin || 0
39
45
  return swiperAttrs
40
46
  }
41
47
 
@@ -1,5 +1,5 @@
1
- import { TaroElement } from '../dom/element/element'
1
+ // import { TaroElement } from '../dom/element/element'
2
2
 
3
- export function getComputedStyle (node: TaroElement) {
3
+ export function getComputedStyle (node: any) {
4
4
  return node._st
5
5
  }
@@ -132,7 +132,7 @@ export namespace HarmonyType {
132
132
  repeating?: boolean
133
133
  }
134
134
  export interface RadialGradient {
135
- center: Point
135
+ center: any
136
136
  radius: number | string
137
137
  colors: Array<[ResourceColor, number]>
138
138
  repeating?: boolean
@@ -502,13 +502,8 @@ declare namespace apis {
502
502
  /** 验证私密消息。 */
503
503
  const authPrivateMessage: (option?: {}, ...args: any[]) => Promise<ICallbackResult & Record<string, unknown>>;
504
504
  function getStorage<T = any>(options: Taro.getStorage.Option<T>): Promise<unknown> | undefined;
505
- function getStorageSync(key: string): any;
506
505
  function setStorage(options: Taro.setStorage.Option): Promise<unknown> | undefined;
507
- function setStorageSync(key: string, data: any): Promise<never> | undefined;
508
506
  function removeStorage(options: Taro.removeStorage.Option): Promise<unknown> | undefined;
509
- function removeStorageSync(key: string): Promise<never> | undefined;
510
- function clearStorage(options: Taro.clearStorage.Option): Promise<unknown> | undefined;
511
- function clearStorageSync(): Promise<never> | undefined;
512
507
  const getStorageInfoSync: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
513
508
  const getStorageInfo: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
514
509
  const createBufferURL: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
@@ -517,6 +512,11 @@ declare namespace apis {
517
512
  const batchSetStorage: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
518
513
  const batchGetStorageSync: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
519
514
  const batchGetStorage: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
515
+ const clearStorage: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
516
+ const getStorageSync: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
517
+ const setStorageSync: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
518
+ const clearStorageSync: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
519
+ const removeStorageSync: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
520
520
  const setBackgroundFetchToken: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
521
521
  const onBackgroundFetchData: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
522
522
  const getBackgroundFetchToken: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;