@react-native-ohos/ting 1.2.4-rc.1 → 1.3.0-rc.2
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.
- package/LICENSE +20 -20
- package/README.OpenSource +10 -10
- package/README.md +14 -14
- package/harmony/ting/BuildProfile.ets +5 -5
- package/harmony/ting/build-profile.json5 +9 -9
- package/harmony/ting/hvigorfile.ts +2 -2
- package/harmony/ting/index.ets +6 -6
- package/harmony/ting/obfuscation-rules.txt +17 -17
- package/harmony/ting/oh-package.json5 +11 -11
- package/harmony/ting/src/main/cpp/CMakeLists.txt +7 -7
- package/harmony/ting/src/main/cpp/Ting.cpp +23 -23
- package/harmony/ting/src/main/cpp/Ting.h +18 -18
- package/harmony/ting/src/main/cpp/TingPackage.h +31 -31
- package/harmony/ting/src/main/ets/Logger.ets +63 -63
- package/harmony/ting/src/main/ets/TingPackage.ets +45 -45
- package/harmony/ting/src/main/ets/TingTurboModule.ets +531 -514
- package/harmony/ting/src/main/ets/Type.ets +138 -133
- package/harmony/ting/src/main/ets/generated/components/ts.ts +5 -5
- package/harmony/ting/src/main/ets/generated/index.ets +5 -5
- package/harmony/ting/src/main/ets/generated/ts.ts +6 -6
- package/harmony/ting/src/main/ets/generated/turboModules/Ting.ts +25 -25
- package/harmony/ting/src/main/ets/generated/turboModules/ts.ts +5 -5
- package/harmony/ting/src/main/module.json5 +6 -6
- package/harmony/ting/src/main/resources/base/element/color.json +7 -7
- package/harmony/ting/src/main/resources/base/element/string.json +15 -15
- package/harmony/ting/src/main/resources/base/profile/backup_config.json +2 -2
- package/harmony/ting/src/main/resources/base/profile/main_pages.json +5 -5
- package/harmony/ting/src/main/resources/en_US/element/string.json +15 -15
- package/harmony/ting/src/main/resources/zh_CN/element/string.json +15 -15
- package/harmony/ting.har +0 -0
- package/lib/commonjs/NativeTing.js +4 -4
- package/lib/commonjs/NativeTing.js.map +1 -1
- package/lib/commonjs/Type.js.map +1 -1
- package/lib/commonjs/index.js +4 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeTing.js +4 -4
- package/lib/module/NativeTing.js.map +1 -1
- package/lib/module/Type.js.map +1 -1
- package/lib/module/index.js +4 -4
- package/lib/module/index.js.map +1 -1
- package/package.json +158 -160
- package/src/NativeTing.ts +17 -17
- package/src/Type.ts +108 -108
- package/src/index.tsx +64 -64
|
@@ -1,514 +1,531 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (C) 2025 Huawei Device Co., Ltd.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { TurboModule } from '@rnoh/react-native-openharmony/ts';
|
|
26
|
-
import { TM } from "../ets/generated/ts";
|
|
27
|
-
import { ComponentContent, PromptAction, promptAction, window } from '@kit.ArkUI';
|
|
28
|
-
import { ToastOptions, AlertOptions, Options } from './Type';
|
|
29
|
-
import { vibrator } from '@kit.SensorServiceKit';
|
|
30
|
-
import { common2D, drawing } from '@kit.ArkGraphics2D';
|
|
31
|
-
|
|
32
|
-
@Builder
|
|
33
|
-
function buildToast(toastOptions: ToastOptions) {
|
|
34
|
-
Row() {
|
|
35
|
-
if (!toastOptions.icon?.uri) {
|
|
36
|
-
if (toastOptions.preset === 'spinner') {
|
|
37
|
-
Progress({ value: 0, total: 100, type: ProgressType.Ring })
|
|
38
|
-
.width('100px')
|
|
39
|
-
.height('100px')
|
|
40
|
-
.color(toastOptions.progressColor || '#008080')
|
|
41
|
-
.style({ strokeWidth: 5, status: ProgressStatus.LOADING })
|
|
42
|
-
.margin({ left: 7 })
|
|
43
|
-
} else if (toastOptions.preset === 'error') {
|
|
44
|
-
Path()
|
|
45
|
-
.commands('M52.5 44.17 L81.67 15 L90 23.33 L60.83 52.5 L90 81.67 L81.67 90 L52.5 60.83 L23.33 90 ' +
|
|
46
|
-
'L15 81.67 L44.17 52.5 L15 23.33 L23.33 15 L52.5 44.17 Z')
|
|
47
|
-
.width('100px')
|
|
48
|
-
.height('100px')
|
|
49
|
-
.fill(Color.Red)
|
|
50
|
-
.stroke(Color.Red)
|
|
51
|
-
.margin({ left: 7 })
|
|
52
|
-
} else if (toastOptions.preset === 'done') {
|
|
53
|
-
Polyline()
|
|
54
|
-
.width('100px')
|
|
55
|
-
.height('100px')
|
|
56
|
-
.points([[9.1787, 15.0323], [18.086, 23.9397], [34.847, 7.1787]])
|
|
57
|
-
.fillOpacity(0)
|
|
58
|
-
.stroke(Color.Green)
|
|
59
|
-
.strokeWidth(4)
|
|
60
|
-
} else if (toastOptions.preset === 'none') {
|
|
61
|
-
// there is no component.
|
|
62
|
-
} else {
|
|
63
|
-
Polyline()
|
|
64
|
-
.width('100px')
|
|
65
|
-
.height('100px')
|
|
66
|
-
.points([[9.1787, 15.0323], [18.086, 23.9397], [34.847, 7.1787]])
|
|
67
|
-
.fillOpacity(0)
|
|
68
|
-
.stroke(Color.Green)
|
|
69
|
-
.strokeWidth(4)
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
if (typeof toastOptions.icon?.uri === 'string') {
|
|
73
|
-
if (!toastOptions.icon?.tintColor) {
|
|
74
|
-
Image(toastOptions.icon.uri as string)
|
|
75
|
-
.objectFit(ImageFit.Contain)
|
|
76
|
-
.autoResize(true)
|
|
77
|
-
.width(toastOptions.icon.size || '100px')
|
|
78
|
-
.height(toastOptions.icon.size || '100px')
|
|
79
|
-
.borderRadius(17.5)
|
|
80
|
-
.margin({ left: 7 })
|
|
81
|
-
} else {
|
|
82
|
-
Image(toastOptions.icon?.uri as string)
|
|
83
|
-
.objectFit(ImageFit.Contain)
|
|
84
|
-
.autoResize(true)
|
|
85
|
-
.width(toastOptions.icon.size || '100px')
|
|
86
|
-
.height(toastOptions.icon.size || '100px')
|
|
87
|
-
.colorFilter(drawing.ColorFilter.createBlendModeColorFilter(toastOptions.icon.tintColor as common2D.Color
|
|
88
|
-
, drawing.BlendMode.SRC_IN))
|
|
89
|
-
.borderRadius(17.5)
|
|
90
|
-
.margin({ left: 7 })
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
Column() {
|
|
96
|
-
Text(toastOptions.title || '')
|
|
97
|
-
.fontSize(13)
|
|
98
|
-
.fontColor(toastOptions.titleColor || '#000000')
|
|
99
|
-
.alignSelf(ItemAlign.Center)
|
|
100
|
-
.maxLines(1)
|
|
101
|
-
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
|
102
|
-
.margin({ bottom: 5 })
|
|
103
|
-
|
|
104
|
-
Text(toastOptions.message || '')
|
|
105
|
-
.fontSize(12)
|
|
106
|
-
.fontColor(toastOptions.messageColor || '#BEBEBE')
|
|
107
|
-
.alignSelf(ItemAlign.Center)
|
|
108
|
-
.maxLines(1)
|
|
109
|
-
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
|
110
|
-
}
|
|
111
|
-
.constraintSize({ minWidth: '0px', maxWidth: '830px' })
|
|
112
|
-
.margin({
|
|
113
|
-
right: 14,
|
|
114
|
-
left: 14,
|
|
115
|
-
top: 5,
|
|
116
|
-
bottom: 5
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
.height('auto')
|
|
120
|
-
.width('auto')
|
|
121
|
-
.borderRadius('50%')
|
|
122
|
-
.backgroundColor(toastOptions.backgroundColor || '#FFFFFF')
|
|
123
|
-
.padding(5)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
@Builder
|
|
127
|
-
function buildAlert(
|
|
128
|
-
Column() {
|
|
129
|
-
if (!alertOptions.icon?.uri) {
|
|
130
|
-
if (alertOptions.preset === 'spinner') {
|
|
131
|
-
Progress({ value: 0, total: 100, type: ProgressType.Ring })
|
|
132
|
-
.width('150px')
|
|
133
|
-
.height('150px')
|
|
134
|
-
.color(alertOptions.progressColor || '#008080')
|
|
135
|
-
.alignSelf(ItemAlign.Center)
|
|
136
|
-
.style({ strokeWidth: 5, status: ProgressStatus.LOADING })
|
|
137
|
-
.margin({ top: 30 })
|
|
138
|
-
} else if (alertOptions.preset === 'error') {
|
|
139
|
-
Path()
|
|
140
|
-
.commands('M 107 140 L 165.34 82.00 L 182.00 98.32 L 123.67 156.67 L 182.00 215.00 L 165.34 231.67 ' +
|
|
141
|
-
'L 107.00 173.33 L 49.33 231.67 L 32 215.00 L 90.34 156.67 L 32 98.32 L 49.33 82.00 L 107.00 140.00 Z')
|
|
142
|
-
.width('225px')
|
|
143
|
-
.height('225px')
|
|
144
|
-
.fill(Color.Red)
|
|
145
|
-
.stroke(Color.Red)
|
|
146
|
-
.margin({ top: 20 })
|
|
147
|
-
} else if (alertOptions.preset === 'done') {
|
|
148
|
-
Polyline()
|
|
149
|
-
.width('225px')
|
|
150
|
-
.height('225px')
|
|
151
|
-
.points([[5.1995, 47.06425], [25.991, 67.1065], [62.95325, 29.39425]])
|
|
152
|
-
.fillOpacity(0)
|
|
153
|
-
.stroke(Color.Green)
|
|
154
|
-
.strokeWidth(7)
|
|
155
|
-
.margin({ top: 15 })
|
|
156
|
-
} else if (alertOptions.preset === 'none') {
|
|
157
|
-
Blank()
|
|
158
|
-
.height('25px')
|
|
159
|
-
.margin({ top: 15 })
|
|
160
|
-
} else {
|
|
161
|
-
Polyline()
|
|
162
|
-
.width('225px')
|
|
163
|
-
.height('225px')
|
|
164
|
-
.points([[5.1995, 47.06425], [25.991, 67.1065], [62.95325, 29.39425]])
|
|
165
|
-
.fillOpacity(0)
|
|
166
|
-
.stroke(Color.Green)
|
|
167
|
-
.strokeWidth(7)
|
|
168
|
-
.margin({ top: 15 })
|
|
169
|
-
}
|
|
170
|
-
} else {
|
|
171
|
-
if (typeof alertOptions.icon?.uri === 'string') {
|
|
172
|
-
if (!alertOptions.icon.tintColor) {
|
|
173
|
-
Image(alertOptions.icon.uri as string)
|
|
174
|
-
.objectFit(ImageFit.Contain)
|
|
175
|
-
.autoResize(true)
|
|
176
|
-
.width(alertOptions.icon.size || '225px')
|
|
177
|
-
.height(alertOptions.icon.size || '225px')
|
|
178
|
-
.margin({ top: 20 })
|
|
179
|
-
} else {
|
|
180
|
-
Image(alertOptions.icon.uri as string)
|
|
181
|
-
.objectFit(ImageFit.Contain)
|
|
182
|
-
.autoResize(true)
|
|
183
|
-
.width(alertOptions.icon.size || '225px')
|
|
184
|
-
.height(alertOptions.icon.size || '225px')
|
|
185
|
-
.colorFilter(drawing.ColorFilter.createBlendModeColorFilter(alertOptions.icon.tintColor as common2D.Color
|
|
186
|
-
, drawing.BlendMode.SRC_IN))
|
|
187
|
-
.margin({ top: 20 })
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
Column() {
|
|
193
|
-
Text(alertOptions.title || '')
|
|
194
|
-
.fontSize(16)
|
|
195
|
-
.fontColor(alertOptions.titleColor || '#000000')
|
|
196
|
-
.alignSelf(ItemAlign.Center)
|
|
197
|
-
.maxLines(1)
|
|
198
|
-
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
|
199
|
-
.margin({ bottom: 5 })
|
|
200
|
-
|
|
201
|
-
Text(alertOptions.message || '')
|
|
202
|
-
.fontSize(14)
|
|
203
|
-
.fontColor(alertOptions.messageColor || '#BEBEBE')
|
|
204
|
-
.alignSelf(ItemAlign.Center)
|
|
205
|
-
.maxLines(1)
|
|
206
|
-
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
|
207
|
-
}
|
|
208
|
-
.constraintSize({ minWidth: '0px', maxWidth: '830px' })
|
|
209
|
-
.margin({
|
|
210
|
-
right: 18,
|
|
211
|
-
left: 18,
|
|
212
|
-
top: 25,
|
|
213
|
-
bottom: 30
|
|
214
|
-
})
|
|
215
|
-
}
|
|
216
|
-
.constraintSize({
|
|
217
|
-
minWidth: '550px',
|
|
218
|
-
maxWidth: Infinity,
|
|
219
|
-
minHeight: '200px',
|
|
220
|
-
maxHeight: Infinity
|
|
221
|
-
})
|
|
222
|
-
.backgroundColor(alertOptions.backgroundColor || '#FFFFFF')
|
|
223
|
-
.borderRadius(alertOptions.borderRadius || '24')
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
private
|
|
234
|
-
private
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
option.
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
this.
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
this.
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
map.
|
|
418
|
-
map.
|
|
419
|
-
map.
|
|
420
|
-
map.
|
|
421
|
-
map.
|
|
422
|
-
|
|
423
|
-
map.
|
|
424
|
-
map.
|
|
425
|
-
|
|
426
|
-
map.
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
if (
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2025 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { TurboModule } from '@rnoh/react-native-openharmony/ts';
|
|
26
|
+
import { TM } from "../ets/generated/ts";
|
|
27
|
+
import { ComponentContent, PromptAction, promptAction, window } from '@kit.ArkUI';
|
|
28
|
+
import { ToastOptions, AlertOptions, Options, AlertBuilderData } from './Type';
|
|
29
|
+
import { vibrator } from '@kit.SensorServiceKit';
|
|
30
|
+
import { common2D, drawing } from '@kit.ArkGraphics2D';
|
|
31
|
+
|
|
32
|
+
@Builder
|
|
33
|
+
function buildToast(toastOptions: ToastOptions) {
|
|
34
|
+
Row() {
|
|
35
|
+
if (!toastOptions.icon?.uri) {
|
|
36
|
+
if (toastOptions.preset === 'spinner') {
|
|
37
|
+
Progress({ value: 0, total: 100, type: ProgressType.Ring })
|
|
38
|
+
.width('100px')
|
|
39
|
+
.height('100px')
|
|
40
|
+
.color(toastOptions.progressColor || '#008080')
|
|
41
|
+
.style({ strokeWidth: 5, status: ProgressStatus.LOADING })
|
|
42
|
+
.margin({ left: 7 })
|
|
43
|
+
} else if (toastOptions.preset === 'error') {
|
|
44
|
+
Path()
|
|
45
|
+
.commands('M52.5 44.17 L81.67 15 L90 23.33 L60.83 52.5 L90 81.67 L81.67 90 L52.5 60.83 L23.33 90 ' +
|
|
46
|
+
'L15 81.67 L44.17 52.5 L15 23.33 L23.33 15 L52.5 44.17 Z')
|
|
47
|
+
.width('100px')
|
|
48
|
+
.height('100px')
|
|
49
|
+
.fill(Color.Red)
|
|
50
|
+
.stroke(Color.Red)
|
|
51
|
+
.margin({ left: 7 })
|
|
52
|
+
} else if (toastOptions.preset === 'done') {
|
|
53
|
+
Polyline()
|
|
54
|
+
.width('100px')
|
|
55
|
+
.height('100px')
|
|
56
|
+
.points([[9.1787, 15.0323], [18.086, 23.9397], [34.847, 7.1787]])
|
|
57
|
+
.fillOpacity(0)
|
|
58
|
+
.stroke(Color.Green)
|
|
59
|
+
.strokeWidth(4)
|
|
60
|
+
} else if (toastOptions.preset === 'none') {
|
|
61
|
+
// there is no component.
|
|
62
|
+
} else {
|
|
63
|
+
Polyline()
|
|
64
|
+
.width('100px')
|
|
65
|
+
.height('100px')
|
|
66
|
+
.points([[9.1787, 15.0323], [18.086, 23.9397], [34.847, 7.1787]])
|
|
67
|
+
.fillOpacity(0)
|
|
68
|
+
.stroke(Color.Green)
|
|
69
|
+
.strokeWidth(4)
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
if (typeof toastOptions.icon?.uri === 'string') {
|
|
73
|
+
if (!toastOptions.icon?.tintColor) {
|
|
74
|
+
Image(toastOptions.icon.uri as string)
|
|
75
|
+
.objectFit(ImageFit.Contain)
|
|
76
|
+
.autoResize(true)
|
|
77
|
+
.width(toastOptions.icon.size || '100px')
|
|
78
|
+
.height(toastOptions.icon.size || '100px')
|
|
79
|
+
.borderRadius(17.5)
|
|
80
|
+
.margin({ left: 7 })
|
|
81
|
+
} else {
|
|
82
|
+
Image(toastOptions.icon?.uri as string)
|
|
83
|
+
.objectFit(ImageFit.Contain)
|
|
84
|
+
.autoResize(true)
|
|
85
|
+
.width(toastOptions.icon.size || '100px')
|
|
86
|
+
.height(toastOptions.icon.size || '100px')
|
|
87
|
+
.colorFilter(drawing.ColorFilter.createBlendModeColorFilter(toastOptions.icon.tintColor as common2D.Color
|
|
88
|
+
, drawing.BlendMode.SRC_IN))
|
|
89
|
+
.borderRadius(17.5)
|
|
90
|
+
.margin({ left: 7 })
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
Column() {
|
|
96
|
+
Text(toastOptions.title || '')
|
|
97
|
+
.fontSize(13)
|
|
98
|
+
.fontColor(toastOptions.titleColor || '#000000')
|
|
99
|
+
.alignSelf(ItemAlign.Center)
|
|
100
|
+
.maxLines(1)
|
|
101
|
+
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
|
102
|
+
.margin({ bottom: 5 })
|
|
103
|
+
|
|
104
|
+
Text(toastOptions.message || '')
|
|
105
|
+
.fontSize(12)
|
|
106
|
+
.fontColor(toastOptions.messageColor || '#BEBEBE')
|
|
107
|
+
.alignSelf(ItemAlign.Center)
|
|
108
|
+
.maxLines(1)
|
|
109
|
+
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
|
110
|
+
}
|
|
111
|
+
.constraintSize({ minWidth: '0px', maxWidth: '830px' })
|
|
112
|
+
.margin({
|
|
113
|
+
right: 14,
|
|
114
|
+
left: 14,
|
|
115
|
+
top: 5,
|
|
116
|
+
bottom: 5
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
.height('auto')
|
|
120
|
+
.width('auto')
|
|
121
|
+
.borderRadius('50%')
|
|
122
|
+
.backgroundColor(toastOptions.backgroundColor || '#FFFFFF')
|
|
123
|
+
.padding(5)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@Builder
|
|
127
|
+
function buildAlert(alertBuilderData: AlertBuilderData) {
|
|
128
|
+
Column() {
|
|
129
|
+
if (!alertBuilderData.alertOptions.icon?.uri) {
|
|
130
|
+
if (alertBuilderData.alertOptions.preset === 'spinner') {
|
|
131
|
+
Progress({ value: 0, total: 100, type: ProgressType.Ring })
|
|
132
|
+
.width('150px')
|
|
133
|
+
.height('150px')
|
|
134
|
+
.color(alertBuilderData.alertOptions.progressColor || '#008080')
|
|
135
|
+
.alignSelf(ItemAlign.Center)
|
|
136
|
+
.style({ strokeWidth: 5, status: ProgressStatus.LOADING })
|
|
137
|
+
.margin({ top: 30 })
|
|
138
|
+
} else if (alertBuilderData.alertOptions.preset === 'error') {
|
|
139
|
+
Path()
|
|
140
|
+
.commands('M 107 140 L 165.34 82.00 L 182.00 98.32 L 123.67 156.67 L 182.00 215.00 L 165.34 231.67 ' +
|
|
141
|
+
'L 107.00 173.33 L 49.33 231.67 L 32 215.00 L 90.34 156.67 L 32 98.32 L 49.33 82.00 L 107.00 140.00 Z')
|
|
142
|
+
.width('225px')
|
|
143
|
+
.height('225px')
|
|
144
|
+
.fill(Color.Red)
|
|
145
|
+
.stroke(Color.Red)
|
|
146
|
+
.margin({ top: 20 })
|
|
147
|
+
} else if (alertBuilderData.alertOptions.preset === 'done') {
|
|
148
|
+
Polyline()
|
|
149
|
+
.width('225px')
|
|
150
|
+
.height('225px')
|
|
151
|
+
.points([[5.1995, 47.06425], [25.991, 67.1065], [62.95325, 29.39425]])
|
|
152
|
+
.fillOpacity(0)
|
|
153
|
+
.stroke(Color.Green)
|
|
154
|
+
.strokeWidth(7)
|
|
155
|
+
.margin({ top: 15 })
|
|
156
|
+
} else if (alertBuilderData.alertOptions.preset === 'none') {
|
|
157
|
+
Blank()
|
|
158
|
+
.height('25px')
|
|
159
|
+
.margin({ top: 15 })
|
|
160
|
+
} else {
|
|
161
|
+
Polyline()
|
|
162
|
+
.width('225px')
|
|
163
|
+
.height('225px')
|
|
164
|
+
.points([[5.1995, 47.06425], [25.991, 67.1065], [62.95325, 29.39425]])
|
|
165
|
+
.fillOpacity(0)
|
|
166
|
+
.stroke(Color.Green)
|
|
167
|
+
.strokeWidth(7)
|
|
168
|
+
.margin({ top: 15 })
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
if (typeof alertBuilderData.alertOptions.icon?.uri === 'string') {
|
|
172
|
+
if (!alertBuilderData.alertOptions.icon.tintColor) {
|
|
173
|
+
Image(alertBuilderData.alertOptions.icon.uri as string)
|
|
174
|
+
.objectFit(ImageFit.Contain)
|
|
175
|
+
.autoResize(true)
|
|
176
|
+
.width(alertBuilderData.alertOptions.icon.size || '225px')
|
|
177
|
+
.height(alertBuilderData.alertOptions.icon.size || '225px')
|
|
178
|
+
.margin({ top: 20 })
|
|
179
|
+
} else {
|
|
180
|
+
Image(alertBuilderData.alertOptions.icon.uri as string)
|
|
181
|
+
.objectFit(ImageFit.Contain)
|
|
182
|
+
.autoResize(true)
|
|
183
|
+
.width(alertBuilderData.alertOptions.icon.size || '225px')
|
|
184
|
+
.height(alertBuilderData.alertOptions.icon.size || '225px')
|
|
185
|
+
.colorFilter(drawing.ColorFilter.createBlendModeColorFilter(alertBuilderData.alertOptions.icon.tintColor as common2D.Color
|
|
186
|
+
, drawing.BlendMode.SRC_IN))
|
|
187
|
+
.margin({ top: 20 })
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
Column() {
|
|
193
|
+
Text(alertBuilderData.alertOptions.title || '')
|
|
194
|
+
.fontSize(16)
|
|
195
|
+
.fontColor(alertBuilderData.alertOptions.titleColor || '#000000')
|
|
196
|
+
.alignSelf(ItemAlign.Center)
|
|
197
|
+
.maxLines(1)
|
|
198
|
+
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
|
199
|
+
.margin({ bottom: 5 })
|
|
200
|
+
|
|
201
|
+
Text(alertBuilderData.alertOptions.message || '')
|
|
202
|
+
.fontSize(14)
|
|
203
|
+
.fontColor(alertBuilderData.alertOptions.messageColor || '#BEBEBE')
|
|
204
|
+
.alignSelf(ItemAlign.Center)
|
|
205
|
+
.maxLines(1)
|
|
206
|
+
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
|
207
|
+
}
|
|
208
|
+
.constraintSize({ minWidth: '0px', maxWidth: '830px' })
|
|
209
|
+
.margin({
|
|
210
|
+
right: 18,
|
|
211
|
+
left: 18,
|
|
212
|
+
top: 25,
|
|
213
|
+
bottom: 30
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
.constraintSize({
|
|
217
|
+
minWidth: '550px',
|
|
218
|
+
maxWidth: Infinity,
|
|
219
|
+
minHeight: '200px',
|
|
220
|
+
maxHeight: Infinity
|
|
221
|
+
})
|
|
222
|
+
.backgroundColor(alertBuilderData.alertOptions.backgroundColor || '#FFFFFF')
|
|
223
|
+
.borderRadius(alertBuilderData.alertOptions.borderRadius || '24')
|
|
224
|
+
// 添加点击事件 - 当 shouldDismissByTap 为 true 时,点击弹窗内容区域关闭弹窗
|
|
225
|
+
.onClick(() => {
|
|
226
|
+
if (alertBuilderData.alertOptions.shouldDismissByTap && alertBuilderData.onDismiss) {
|
|
227
|
+
alertBuilderData.onDismiss();
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export class TingTurboModule extends TurboModule implements TM.Ting.Spec {
|
|
233
|
+
private alertPromptAction: PromptAction | null = null;
|
|
234
|
+
private alertComponentContent: ComponentContent<object> | null = null;
|
|
235
|
+
private timeoutId: number | null = null;
|
|
236
|
+
private isCancelled: boolean = false;
|
|
237
|
+
private toastOptionInit: ToastOptions | undefined = undefined;
|
|
238
|
+
private alertOptionInit: AlertOptions | undefined = undefined;
|
|
239
|
+
private PREFIX = "asset://";
|
|
240
|
+
private RAWFILE_PREFIX = "resource://RAWFILE/assets/";
|
|
241
|
+
|
|
242
|
+
async showToast(toastOptions: ToastOptions) {
|
|
243
|
+
if (this.toastOptionInit) {
|
|
244
|
+
toastOptions = this.mergeToastOptions(this.toastOptionInit, toastOptions);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const windowValue = await window.getLastWindow(this.ctx.uiAbilityContext);
|
|
248
|
+
const uiContext = windowValue?.getUIContext();
|
|
249
|
+
const promptAction = uiContext?.getPromptAction();
|
|
250
|
+
|
|
251
|
+
let option: promptAction.BaseDialogOptions = {
|
|
252
|
+
alignment: DialogAlignment.Top,
|
|
253
|
+
autoCancel: true,
|
|
254
|
+
offset: { dx: 0, dy: 50 },
|
|
255
|
+
isModal: true,
|
|
256
|
+
maskColor: '#00FF0000',
|
|
257
|
+
transition: TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.TOP)
|
|
258
|
+
.animation({ curve: Curve.Sharp }),
|
|
259
|
+
TransitionEffect.move(TransitionEdge.TOP).animation({ curve: Curve.Sharp })),
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
if (toastOptions.position === "bottom") {
|
|
263
|
+
option.alignment = DialogAlignment.Bottom;
|
|
264
|
+
option.offset = { dx: 0, dy: -50 };
|
|
265
|
+
option.transition = TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.BOTTOM)
|
|
266
|
+
.animation({ curve: Curve.Sharp }),
|
|
267
|
+
TransitionEffect.move(TransitionEdge.BOTTOM).animation({ curve: Curve.Sharp }));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (toastOptions.shouldDismissByDrag === false) {
|
|
271
|
+
option.autoCancel = false;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (toastOptions.duration && toastOptions.duration !== 3000) {
|
|
275
|
+
toastOptions.duration = toastOptions.duration * 1000;
|
|
276
|
+
if (toastOptions.duration > 0 && toastOptions.duration <= 1000) {
|
|
277
|
+
toastOptions.duration += 500;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (toastOptions.haptic) {
|
|
282
|
+
option.onDidAppear = () => this.vibrator(toastOptions.haptic as string);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const contentNode = new ComponentContent(uiContext!, wrapBuilder(buildToast), toastOptions);
|
|
286
|
+
|
|
287
|
+
try {
|
|
288
|
+
promptAction?.openCustomDialog(contentNode, option);
|
|
289
|
+
|
|
290
|
+
setTimeout(() => {
|
|
291
|
+
promptAction?.closeCustomDialog(contentNode);
|
|
292
|
+
}, toastOptions.duration || 3000);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
throw new Error('Can\'t open CustomDialog: ' + error);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async showAlert(alertOptions: AlertOptions) {
|
|
299
|
+
if (this.alertOptionInit) {
|
|
300
|
+
alertOptions = this.mergeAlertOptions(this.alertOptionInit, alertOptions);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const windowValue = await window.getLastWindow(this.ctx.uiAbilityContext);
|
|
304
|
+
const uiContext = windowValue?.getUIContext();
|
|
305
|
+
this.alertPromptAction = uiContext?.getPromptAction();
|
|
306
|
+
|
|
307
|
+
let option: promptAction.BaseDialogOptions = {
|
|
308
|
+
alignment: DialogAlignment.Center,
|
|
309
|
+
autoCancel: true,
|
|
310
|
+
isModal: true,
|
|
311
|
+
maskColor: '#00FF0000'
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
if (alertOptions.shouldDismissByTap === false) {
|
|
315
|
+
option.autoCancel = false;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (alertOptions.backdropOpacity && alertOptions.backdropOpacity >= 1) {
|
|
319
|
+
option.maskColor = '#000000';
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (alertOptions.duration && alertOptions.duration !== 3000) {
|
|
323
|
+
alertOptions.duration = alertOptions.duration * 1000;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (this.timeoutId) {
|
|
327
|
+
clearTimeout(this.timeoutId);
|
|
328
|
+
this.isCancelled = true; // 标记为取消状态
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
this.isCancelled = false;
|
|
332
|
+
|
|
333
|
+
if (alertOptions.haptic) {
|
|
334
|
+
option.onDidAppear = () => this.vibrator(alertOptions.haptic as string);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// 创建关闭函数
|
|
338
|
+
const dismissAlert = () => {
|
|
339
|
+
this.dismissAlert();
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const alertBuilderData: AlertBuilderData = {
|
|
343
|
+
alertOptions: alertOptions,
|
|
344
|
+
onDismiss: dismissAlert
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
this.alertComponentContent = new ComponentContent(uiContext!, wrapBuilder(buildAlert), alertBuilderData);
|
|
349
|
+
|
|
350
|
+
try {
|
|
351
|
+
this.alertPromptAction?.openCustomDialog(this.alertComponentContent, option);
|
|
352
|
+
|
|
353
|
+
this.timeoutId = setTimeout(async () => {
|
|
354
|
+
await this.alertPromptAction?.closeCustomDialog(this.alertComponentContent);
|
|
355
|
+
}, alertOptions.duration || 3000);
|
|
356
|
+
|
|
357
|
+
} catch (error) {
|
|
358
|
+
throw new Error('Can\'t open CustomDialog: ' + error);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
toast(options: Object): void {
|
|
363
|
+
if (options && typeof options === 'object') {
|
|
364
|
+
const toastOptions = options as ToastOptions;
|
|
365
|
+
|
|
366
|
+
if (toastOptions.icon?.tintColor) {
|
|
367
|
+
toastOptions.icon.tintColor = this.hexToRGBA(toastOptions.icon?.tintColor as string);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (toastOptions.icon?.uri) {
|
|
371
|
+
toastOptions.icon!.uri = this.modifyPathIfNeeded(toastOptions.icon?.uri as string);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
this.showToast(toastOptions);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
alert(options: Object): void {
|
|
379
|
+
if (options && typeof options === 'object') {
|
|
380
|
+
const alertOptions = options as AlertOptions;
|
|
381
|
+
|
|
382
|
+
if (alertOptions.icon?.tintColor) {
|
|
383
|
+
alertOptions.icon.tintColor = this.hexToRGBA(alertOptions.icon?.tintColor as string);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (alertOptions.icon?.uri) {
|
|
387
|
+
alertOptions.icon!.uri = this.modifyPathIfNeeded(alertOptions.icon?.uri as string);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
this.showAlert(alertOptions);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
dismissAlert(): void {
|
|
395
|
+
if (this.timeoutId) {
|
|
396
|
+
clearTimeout(this.timeoutId);
|
|
397
|
+
this.timeoutId = null;
|
|
398
|
+
this.isCancelled = true;
|
|
399
|
+
|
|
400
|
+
if (this.alertPromptAction && this.alertComponentContent) {
|
|
401
|
+
this.alertPromptAction.closeCustomDialog(this.alertComponentContent);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
setup(options: Object): void {
|
|
407
|
+
const opts = options as Options;
|
|
408
|
+
this.alertOptionInit = opts.alert;
|
|
409
|
+
this.toastOptionInit = opts.toast;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
mergeToastOptions(mapInit: ToastOptions, map: ToastOptions): ToastOptions {
|
|
413
|
+
if (mapInit) {
|
|
414
|
+
map.title = map.title !== undefined ? map.title : mapInit.title;
|
|
415
|
+
map.message = map.message !== undefined ? map.message : mapInit.message;
|
|
416
|
+
map.titleColor = map.titleColor !== undefined ? map.titleColor : mapInit.titleColor;
|
|
417
|
+
map.messageColor = map.messageColor !== undefined ? map.messageColor : mapInit.messageColor;
|
|
418
|
+
map.preset = map.preset !== undefined ? map.preset : mapInit.preset;
|
|
419
|
+
map.duration = map.duration !== undefined ? map.duration : mapInit.duration;
|
|
420
|
+
map.haptic = map.haptic !== undefined ? map.haptic : mapInit.haptic;
|
|
421
|
+
map.shouldDismissByDrag =
|
|
422
|
+
map.shouldDismissByDrag !== undefined ? map.shouldDismissByDrag : mapInit.shouldDismissByDrag;
|
|
423
|
+
map.position = map.position !== undefined ? map.position : mapInit.position;
|
|
424
|
+
map.backgroundColor = map.backgroundColor !== undefined ? map.backgroundColor : mapInit.backgroundColor;
|
|
425
|
+
map.icon = map.icon !== undefined ? map.icon : mapInit.icon;
|
|
426
|
+
map.progressColor = map.progressColor !== undefined ? map.progressColor : mapInit.progressColor;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return map;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
mergeAlertOptions(mapInit: AlertOptions, map: AlertOptions): AlertOptions {
|
|
433
|
+
if (mapInit) {
|
|
434
|
+
map.title = map.title !== undefined ? map.title : mapInit.title;
|
|
435
|
+
map.message = map.message !== undefined ? map.message : mapInit.message;
|
|
436
|
+
map.titleColor = map.titleColor !== undefined ? map.titleColor : mapInit.titleColor;
|
|
437
|
+
map.messageColor = map.messageColor !== undefined ? map.messageColor : mapInit.messageColor;
|
|
438
|
+
map.preset = map.preset !== undefined ? map.preset : mapInit.preset;
|
|
439
|
+
map.duration = map.duration !== undefined ? map.duration : mapInit.duration;
|
|
440
|
+
map.haptic = map.haptic !== undefined ? map.haptic : mapInit.haptic;
|
|
441
|
+
map.shouldDismissByTap =
|
|
442
|
+
map.shouldDismissByTap !== undefined ? map.shouldDismissByTap : mapInit.shouldDismissByTap;
|
|
443
|
+
map.backgroundColor = map.backgroundColor !== undefined ? map.backgroundColor : mapInit.backgroundColor;
|
|
444
|
+
map.borderRadius = map.borderRadius !== undefined ? map.borderRadius : mapInit.borderRadius;
|
|
445
|
+
map.blurBackdrop = map.blurBackdrop !== undefined ? map.blurBackdrop : mapInit.blurBackdrop;
|
|
446
|
+
map.backdropOpacity = map.backdropOpacity !== undefined ? map.backdropOpacity : mapInit.backdropOpacity;
|
|
447
|
+
map.icon = map.icon !== undefined ? map.icon : mapInit.icon;
|
|
448
|
+
map.progressColor = map.progressColor !== undefined ? map.progressColor : mapInit.progressColor;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return map;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
vibrator(haptic: string) {
|
|
455
|
+
if (haptic === 'success') {
|
|
456
|
+
vibrator.startVibration({
|
|
457
|
+
type: 'preset',
|
|
458
|
+
effectId: 'haptic.clock.timer',
|
|
459
|
+
count: 1,
|
|
460
|
+
intensity: 30
|
|
461
|
+
}, {
|
|
462
|
+
id: 0,
|
|
463
|
+
usage: 'alarm'
|
|
464
|
+
})
|
|
465
|
+
} else if (haptic === 'warning') {
|
|
466
|
+
vibrator.startVibration({
|
|
467
|
+
type: 'preset',
|
|
468
|
+
effectId: 'haptic.clock.timer',
|
|
469
|
+
count: 1,
|
|
470
|
+
intensity: 30
|
|
471
|
+
}, {
|
|
472
|
+
id: 0,
|
|
473
|
+
usage: 'alarm'
|
|
474
|
+
})
|
|
475
|
+
} else if (haptic === 'error') {
|
|
476
|
+
vibrator.startVibration({
|
|
477
|
+
type: 'preset',
|
|
478
|
+
effectId: 'haptic.clock.timer',
|
|
479
|
+
count: 7,
|
|
480
|
+
intensity: 30
|
|
481
|
+
}, {
|
|
482
|
+
id: 0,
|
|
483
|
+
usage: 'alarm'
|
|
484
|
+
})
|
|
485
|
+
} else {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
hexToRGBA(hex: string): common2D.Color {
|
|
491
|
+
hex = hex.replace(/^#/, '');
|
|
492
|
+
|
|
493
|
+
if (hex.length === 3) {
|
|
494
|
+
hex = hex.split('').map(char => char + char).join('');
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
if (hex.length === 6) {
|
|
498
|
+
const red = parseInt(hex.substring(0, 2), 16);
|
|
499
|
+
const green = parseInt(hex.substring(2, 4), 16);
|
|
500
|
+
const blue = parseInt(hex.substring(4, 6), 16);
|
|
501
|
+
return {
|
|
502
|
+
alpha: 255,
|
|
503
|
+
red,
|
|
504
|
+
green,
|
|
505
|
+
blue
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
if (hex.length === 8) {
|
|
510
|
+
const alpha = parseInt(hex.substring(0, 2), 16);
|
|
511
|
+
const red = parseInt(hex.substring(2, 4), 16);
|
|
512
|
+
const green = parseInt(hex.substring(4, 6), 16);
|
|
513
|
+
const blue = parseInt(hex.substring(6, 8), 16);
|
|
514
|
+
return {
|
|
515
|
+
alpha,
|
|
516
|
+
red,
|
|
517
|
+
green,
|
|
518
|
+
blue
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
throw new Error('Invalid hex color');
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
modifyPathIfNeeded(path: string): string {
|
|
526
|
+
if (path.startsWith(this.PREFIX)) {
|
|
527
|
+
return this.RAWFILE_PREFIX + path.slice(this.PREFIX.length);
|
|
528
|
+
}
|
|
529
|
+
return path;
|
|
530
|
+
}
|
|
531
|
+
}
|