@react-native-ohos/ting 1.2.3-rc.1
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 -0
- package/README.OpenSource +11 -0
- package/README.md +14 -0
- package/harmony/ting/build-profile.json5 +9 -0
- package/harmony/ting/hvigorfile.ts +2 -0
- package/harmony/ting/index.ets +3 -0
- package/harmony/ting/obfuscation-rules.txt +18 -0
- package/harmony/ting/oh-package.json5 +12 -0
- package/harmony/ting/src/main/cpp/CMakeLists.txt +9 -0
- package/harmony/ting/src/main/cpp/TingPackage.h +36 -0
- package/harmony/ting/src/main/cpp/generated/RNOH/generated/BaseTingPackage.h +65 -0
- package/harmony/ting/src/main/cpp/generated/RNOH/generated/turbo_modules/Ting.cpp +19 -0
- package/harmony/ting/src/main/cpp/generated/RNOH/generated/turbo_modules/Ting.h +16 -0
- package/harmony/ting/src/main/ets/Logger.ets +64 -0
- package/harmony/ting/src/main/ets/TingPackage.ets +47 -0
- package/harmony/ting/src/main/ets/TingTurboModule.ets +514 -0
- package/harmony/ting/src/main/ets/Type.ets +133 -0
- package/harmony/ting/src/main/ets/generated/components/ts.ts +5 -0
- package/harmony/ting/src/main/ets/generated/index.ets +5 -0
- package/harmony/ting/src/main/ets/generated/ts.ts +6 -0
- package/harmony/ting/src/main/ets/generated/turboModules/Ting.ts +20 -0
- package/harmony/ting/src/main/ets/generated/turboModules/ts.ts +5 -0
- package/harmony/ting/src/main/module.json5 +7 -0
- package/harmony/ting/src/main/resources/base/element/color.json +8 -0
- package/harmony/ting/src/main/resources/base/element/string.json +16 -0
- package/harmony/ting/src/main/resources/base/profile/backup_config.json +3 -0
- package/harmony/ting/src/main/resources/base/profile/main_pages.json +5 -0
- package/harmony/ting/src/main/resources/en_US/element/string.json +16 -0
- package/harmony/ting/src/main/resources/zh_CN/element/string.json +16 -0
- package/harmony/ting/ts.ets +7 -0
- package/harmony/ting.har +0 -0
- package/lib/commonjs/NativeTing.js +14 -0
- package/lib/commonjs/NativeTing.js.map +1 -0
- package/lib/commonjs/Type.js +2 -0
- package/lib/commonjs/Type.js.map +1 -0
- package/lib/commonjs/index.js +73 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/NativeTing.js +9 -0
- package/lib/module/NativeTing.js.map +1 -0
- package/lib/module/Type.js +2 -0
- package/lib/module/Type.js.map +1 -0
- package/lib/module/index.js +47 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/NativeTing.d.ts +10 -0
- package/lib/typescript/NativeTing.d.ts.map +1 -0
- package/lib/typescript/Type.d.ts +98 -0
- package/lib/typescript/Type.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +10 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/package.json +165 -0
- package/src/NativeTing.ts +17 -0
- package/src/Type.ts +108 -0
- package/src/index.tsx +64 -0
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 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 './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(alertOptions: AlertOptions) {
|
|
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
|
+
export class TingTurboModule extends TurboModule implements TM.Ting.Spec {
|
|
227
|
+
private alertPromptAction: PromptAction | null = null;
|
|
228
|
+
private alertComponentContent: ComponentContent<object> | null = null;
|
|
229
|
+
private timeoutId: number | null = null;
|
|
230
|
+
private isCancelled: boolean = false;
|
|
231
|
+
private toastOptionInit: ToastOptions | undefined = undefined;
|
|
232
|
+
private alertOptionInit: AlertOptions | undefined = undefined;
|
|
233
|
+
private PREFIX = "asset://";
|
|
234
|
+
private RAWFILE_PREFIX = "resource://RAWFILE/assets/";
|
|
235
|
+
|
|
236
|
+
async showToast(toastOptions: ToastOptions) {
|
|
237
|
+
if (this.toastOptionInit) {
|
|
238
|
+
toastOptions = this.mergeToastOptions(this.toastOptionInit, toastOptions);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const windowValue = await window.getLastWindow(this.ctx.uiAbilityContext);
|
|
242
|
+
const uiContext = windowValue?.getUIContext();
|
|
243
|
+
const promptAction = uiContext?.getPromptAction();
|
|
244
|
+
|
|
245
|
+
let option: promptAction.BaseDialogOptions = {
|
|
246
|
+
alignment: DialogAlignment.Top,
|
|
247
|
+
autoCancel: true,
|
|
248
|
+
offset: { dx: 0, dy: 50 },
|
|
249
|
+
isModal: true,
|
|
250
|
+
maskColor: '#00FF0000',
|
|
251
|
+
transition: TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.TOP)
|
|
252
|
+
.animation({ curve: Curve.Sharp }),
|
|
253
|
+
TransitionEffect.move(TransitionEdge.TOP).animation({ curve: Curve.Sharp })),
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
if (toastOptions.position === "bottom") {
|
|
257
|
+
option.alignment = DialogAlignment.Bottom;
|
|
258
|
+
option.offset = { dx: 0, dy: -50 };
|
|
259
|
+
option.transition = TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.BOTTOM)
|
|
260
|
+
.animation({ curve: Curve.Sharp }),
|
|
261
|
+
TransitionEffect.move(TransitionEdge.BOTTOM).animation({ curve: Curve.Sharp }));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (toastOptions.shouldDismissByDrag === false) {
|
|
265
|
+
option.autoCancel = false;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (toastOptions.duration && toastOptions.duration !== 3000) {
|
|
269
|
+
toastOptions.duration = toastOptions.duration * 1000;
|
|
270
|
+
if (toastOptions.duration > 0 && toastOptions.duration <= 1000) {
|
|
271
|
+
toastOptions.duration += 500;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (toastOptions.haptic) {
|
|
276
|
+
option.onDidAppear = () => this.vibrator(toastOptions.haptic as string);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const contentNode = new ComponentContent(uiContext!, wrapBuilder(buildToast), toastOptions);
|
|
280
|
+
|
|
281
|
+
try {
|
|
282
|
+
promptAction?.openCustomDialog(contentNode, option);
|
|
283
|
+
|
|
284
|
+
setTimeout(() => {
|
|
285
|
+
promptAction?.closeCustomDialog(contentNode);
|
|
286
|
+
}, toastOptions.duration || 3000);
|
|
287
|
+
} catch (error) {
|
|
288
|
+
throw new Error('Can\'t open CustomDialog: ' + error);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async showAlert(alertOptions: AlertOptions) {
|
|
293
|
+
if (this.alertOptionInit) {
|
|
294
|
+
alertOptions = this.mergeAlertOptions(this.alertOptionInit, alertOptions);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const windowValue = await window.getLastWindow(this.ctx.uiAbilityContext);
|
|
298
|
+
const uiContext = windowValue?.getUIContext();
|
|
299
|
+
this.alertPromptAction = uiContext?.getPromptAction();
|
|
300
|
+
|
|
301
|
+
let option: promptAction.BaseDialogOptions = {
|
|
302
|
+
alignment: DialogAlignment.Center,
|
|
303
|
+
autoCancel: true,
|
|
304
|
+
isModal: true,
|
|
305
|
+
maskColor: '#00FF0000'
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
if (alertOptions.shouldDismissByTap === false) {
|
|
309
|
+
option.autoCancel = false;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (alertOptions.backdropOpacity && alertOptions.backdropOpacity >= 1) {
|
|
313
|
+
option.maskColor = '#000000';
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (alertOptions.duration && alertOptions.duration !== 3000) {
|
|
317
|
+
alertOptions.duration = alertOptions.duration * 1000;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (this.timeoutId) {
|
|
321
|
+
clearTimeout(this.timeoutId);
|
|
322
|
+
this.isCancelled = true; // 标记为取消状态
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
this.isCancelled = false;
|
|
326
|
+
|
|
327
|
+
if (alertOptions.haptic) {
|
|
328
|
+
option.onDidAppear = () => this.vibrator(alertOptions.haptic as string);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
this.alertComponentContent = new ComponentContent(uiContext!, wrapBuilder(buildAlert), alertOptions);
|
|
332
|
+
|
|
333
|
+
try {
|
|
334
|
+
this.alertPromptAction?.openCustomDialog(this.alertComponentContent, option);
|
|
335
|
+
|
|
336
|
+
this.timeoutId = setTimeout(async () => {
|
|
337
|
+
await this.alertPromptAction?.closeCustomDialog(this.alertComponentContent);
|
|
338
|
+
}, alertOptions.duration || 3000);
|
|
339
|
+
|
|
340
|
+
} catch (error) {
|
|
341
|
+
throw new Error('Can\'t open CustomDialog: ' + error);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
toast(options: Object): void {
|
|
346
|
+
if (options && typeof options === 'object') {
|
|
347
|
+
const toastOptions = options as ToastOptions;
|
|
348
|
+
|
|
349
|
+
if (toastOptions.icon?.tintColor) {
|
|
350
|
+
toastOptions.icon.tintColor = this.hexToRGBA(toastOptions.icon?.tintColor as string);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (toastOptions.icon?.uri) {
|
|
354
|
+
toastOptions.icon!.uri = this.modifyPathIfNeeded(toastOptions.icon?.uri as string);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
this.showToast(toastOptions);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
alert(options: Object): void {
|
|
362
|
+
if (options && typeof options === 'object') {
|
|
363
|
+
const alertOptions = options as AlertOptions;
|
|
364
|
+
|
|
365
|
+
if (alertOptions.icon?.tintColor) {
|
|
366
|
+
alertOptions.icon.tintColor = this.hexToRGBA(alertOptions.icon?.tintColor as string);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (alertOptions.icon?.uri) {
|
|
370
|
+
alertOptions.icon!.uri = this.modifyPathIfNeeded(alertOptions.icon?.uri as string);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
this.showAlert(alertOptions);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
dismissAlert(): void {
|
|
378
|
+
if (this.timeoutId) {
|
|
379
|
+
clearTimeout(this.timeoutId);
|
|
380
|
+
this.timeoutId = null;
|
|
381
|
+
this.isCancelled = true;
|
|
382
|
+
|
|
383
|
+
if (this.alertPromptAction && this.alertComponentContent) {
|
|
384
|
+
this.alertPromptAction.closeCustomDialog(this.alertComponentContent);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
setup(options: Object): void {
|
|
390
|
+
const opts = options as Options;
|
|
391
|
+
this.alertOptionInit = opts.alert;
|
|
392
|
+
this.toastOptionInit = opts.toast;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
mergeToastOptions(mapInit: ToastOptions, map: ToastOptions): ToastOptions {
|
|
396
|
+
if (mapInit) {
|
|
397
|
+
map.title = map.title !== undefined ? map.title : mapInit.title;
|
|
398
|
+
map.message = map.message !== undefined ? map.message : mapInit.message;
|
|
399
|
+
map.titleColor = map.titleColor !== undefined ? map.titleColor : mapInit.titleColor;
|
|
400
|
+
map.messageColor = map.messageColor !== undefined ? map.messageColor : mapInit.messageColor;
|
|
401
|
+
map.preset = map.preset !== undefined ? map.preset : mapInit.preset;
|
|
402
|
+
map.duration = map.duration !== undefined ? map.duration : mapInit.duration;
|
|
403
|
+
map.haptic = map.haptic !== undefined ? map.haptic : mapInit.haptic;
|
|
404
|
+
map.shouldDismissByDrag =
|
|
405
|
+
map.shouldDismissByDrag !== undefined ? map.shouldDismissByDrag : mapInit.shouldDismissByDrag;
|
|
406
|
+
map.position = map.position !== undefined ? map.position : mapInit.position;
|
|
407
|
+
map.backgroundColor = map.backgroundColor !== undefined ? map.backgroundColor : mapInit.backgroundColor;
|
|
408
|
+
map.icon = map.icon !== undefined ? map.icon : mapInit.icon;
|
|
409
|
+
map.progressColor = map.progressColor !== undefined ? map.progressColor : mapInit.progressColor;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return map;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
mergeAlertOptions(mapInit: AlertOptions, map: AlertOptions): AlertOptions {
|
|
416
|
+
if (mapInit) {
|
|
417
|
+
map.title = map.title !== undefined ? map.title : mapInit.title;
|
|
418
|
+
map.message = map.message !== undefined ? map.message : mapInit.message;
|
|
419
|
+
map.titleColor = map.titleColor !== undefined ? map.titleColor : mapInit.titleColor;
|
|
420
|
+
map.messageColor = map.messageColor !== undefined ? map.messageColor : mapInit.messageColor;
|
|
421
|
+
map.preset = map.preset !== undefined ? map.preset : mapInit.preset;
|
|
422
|
+
map.duration = map.duration !== undefined ? map.duration : mapInit.duration;
|
|
423
|
+
map.haptic = map.haptic !== undefined ? map.haptic : mapInit.haptic;
|
|
424
|
+
map.shouldDismissByTap =
|
|
425
|
+
map.shouldDismissByTap !== undefined ? map.shouldDismissByTap : mapInit.shouldDismissByTap;
|
|
426
|
+
map.backgroundColor = map.backgroundColor !== undefined ? map.backgroundColor : mapInit.backgroundColor;
|
|
427
|
+
map.borderRadius = map.borderRadius !== undefined ? map.borderRadius : mapInit.borderRadius;
|
|
428
|
+
map.blurBackdrop = map.blurBackdrop !== undefined ? map.blurBackdrop : mapInit.blurBackdrop;
|
|
429
|
+
map.backdropOpacity = map.backdropOpacity !== undefined ? map.backdropOpacity : mapInit.backdropOpacity;
|
|
430
|
+
map.icon = map.icon !== undefined ? map.icon : mapInit.icon;
|
|
431
|
+
map.progressColor = map.progressColor !== undefined ? map.progressColor : mapInit.progressColor;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return map;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
vibrator(haptic: string) {
|
|
438
|
+
if (haptic === 'success') {
|
|
439
|
+
vibrator.startVibration({
|
|
440
|
+
type: 'preset',
|
|
441
|
+
effectId: 'haptic.clock.timer',
|
|
442
|
+
count: 1,
|
|
443
|
+
intensity: 30
|
|
444
|
+
}, {
|
|
445
|
+
id: 0,
|
|
446
|
+
usage: 'alarm'
|
|
447
|
+
})
|
|
448
|
+
} else if (haptic === 'warning') {
|
|
449
|
+
vibrator.startVibration({
|
|
450
|
+
type: 'preset',
|
|
451
|
+
effectId: 'haptic.clock.timer',
|
|
452
|
+
count: 1,
|
|
453
|
+
intensity: 30
|
|
454
|
+
}, {
|
|
455
|
+
id: 0,
|
|
456
|
+
usage: 'alarm'
|
|
457
|
+
})
|
|
458
|
+
} else if (haptic === 'error') {
|
|
459
|
+
vibrator.startVibration({
|
|
460
|
+
type: 'preset',
|
|
461
|
+
effectId: 'haptic.clock.timer',
|
|
462
|
+
count: 7,
|
|
463
|
+
intensity: 30
|
|
464
|
+
}, {
|
|
465
|
+
id: 0,
|
|
466
|
+
usage: 'alarm'
|
|
467
|
+
})
|
|
468
|
+
} else {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
hexToRGBA(hex: string): common2D.Color {
|
|
474
|
+
hex = hex.replace(/^#/, '');
|
|
475
|
+
|
|
476
|
+
if (hex.length === 3) {
|
|
477
|
+
hex = hex.split('').map(char => char + char).join('');
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (hex.length === 6) {
|
|
481
|
+
const red = parseInt(hex.substring(0, 2), 16);
|
|
482
|
+
const green = parseInt(hex.substring(2, 4), 16);
|
|
483
|
+
const blue = parseInt(hex.substring(4, 6), 16);
|
|
484
|
+
return {
|
|
485
|
+
alpha: 255,
|
|
486
|
+
red,
|
|
487
|
+
green,
|
|
488
|
+
blue
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (hex.length === 8) {
|
|
493
|
+
const alpha = parseInt(hex.substring(0, 2), 16);
|
|
494
|
+
const red = parseInt(hex.substring(2, 4), 16);
|
|
495
|
+
const green = parseInt(hex.substring(4, 6), 16);
|
|
496
|
+
const blue = parseInt(hex.substring(6, 8), 16);
|
|
497
|
+
return {
|
|
498
|
+
alpha,
|
|
499
|
+
red,
|
|
500
|
+
green,
|
|
501
|
+
blue
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
throw new Error('Invalid hex color');
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
modifyPathIfNeeded(path: string): string {
|
|
509
|
+
if (path.startsWith(this.PREFIX)) {
|
|
510
|
+
return this.RAWFILE_PREFIX + path.slice(this.PREFIX.length);
|
|
511
|
+
}
|
|
512
|
+
return path;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 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 { common2D } from '@kit.ArkGraphics2D';
|
|
26
|
+
|
|
27
|
+
export interface Icon {
|
|
28
|
+
size?: number;
|
|
29
|
+
uri?: string | number;
|
|
30
|
+
tintColor?: string | common2D.Color;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface Options {
|
|
34
|
+
alert?: AlertOptions;
|
|
35
|
+
toast?: ToastOptions;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ToastOptions {
|
|
39
|
+
title?: string;
|
|
40
|
+
message?: string;
|
|
41
|
+
titleColor?: string;
|
|
42
|
+
messageColor?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Defaults to `done`.
|
|
45
|
+
*/
|
|
46
|
+
preset?: 'done' | 'error' | 'none' | 'spinner';
|
|
47
|
+
/**
|
|
48
|
+
* Duration in seconds.
|
|
49
|
+
*/
|
|
50
|
+
duration?: number;
|
|
51
|
+
haptic?: 'success' | 'warning' | 'error' | 'none';
|
|
52
|
+
/**
|
|
53
|
+
* Defaults to `true`.
|
|
54
|
+
*/
|
|
55
|
+
shouldDismissByDrag?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Change the presentation side.
|
|
58
|
+
* Defaults to `top`.
|
|
59
|
+
*/
|
|
60
|
+
position?: 'top' | 'bottom';
|
|
61
|
+
/**
|
|
62
|
+
* backgroundColor for toastView
|
|
63
|
+
* Defaults to `null`.
|
|
64
|
+
*/
|
|
65
|
+
backgroundColor?: string;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* custom icon
|
|
69
|
+
* Defaults to `null`.
|
|
70
|
+
*/
|
|
71
|
+
icon?: Icon;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* progress color for spinner preset
|
|
75
|
+
* @platform android
|
|
76
|
+
*/
|
|
77
|
+
progressColor?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface AlertOptions {
|
|
81
|
+
title?: string;
|
|
82
|
+
message?: string;
|
|
83
|
+
titleColor?: string;
|
|
84
|
+
messageColor?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Defaults to `done`.
|
|
87
|
+
*/
|
|
88
|
+
preset?: 'done' | 'error' | 'none' | 'spinner';
|
|
89
|
+
/**
|
|
90
|
+
* Duration in seconds.
|
|
91
|
+
* Defaults to 3.
|
|
92
|
+
*/
|
|
93
|
+
duration?: number;
|
|
94
|
+
/**
|
|
95
|
+
* @platform ios
|
|
96
|
+
*/
|
|
97
|
+
haptic?: 'success' | 'warning' | 'error' | 'none';
|
|
98
|
+
/**
|
|
99
|
+
* Defaults to `true`.
|
|
100
|
+
*/
|
|
101
|
+
shouldDismissByTap?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* backgroundColor for alertView
|
|
104
|
+
* Defaults to `null`.
|
|
105
|
+
*/
|
|
106
|
+
backgroundColor?: string;
|
|
107
|
+
/**
|
|
108
|
+
* borderRadius for alertView
|
|
109
|
+
* Defaults to `24`.
|
|
110
|
+
*/
|
|
111
|
+
borderRadius?: number;
|
|
112
|
+
/**
|
|
113
|
+
* blur for backdrop
|
|
114
|
+
* @platform android
|
|
115
|
+
*/
|
|
116
|
+
blurBackdrop?: number;
|
|
117
|
+
/**
|
|
118
|
+
* @platform android
|
|
119
|
+
* 0 -> 1
|
|
120
|
+
* Defaults to 0.
|
|
121
|
+
*/
|
|
122
|
+
backdropOpacity?: number;
|
|
123
|
+
/**
|
|
124
|
+
* custom icon
|
|
125
|
+
*/
|
|
126
|
+
icon?: Icon;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* progress color for spinner preset
|
|
130
|
+
* @platform android
|
|
131
|
+
*/
|
|
132
|
+
progressColor?: string;
|
|
133
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Tag } from "@rnoh/react-native-openharmony/ts"
|
|
6
|
+
|
|
7
|
+
export namespace Ting {
|
|
8
|
+
export const NAME = 'Ting' as const
|
|
9
|
+
|
|
10
|
+
export interface Spec {
|
|
11
|
+
toast(options: Object): void;
|
|
12
|
+
|
|
13
|
+
alert(options: Object): void;
|
|
14
|
+
|
|
15
|
+
dismissAlert(): void;
|
|
16
|
+
|
|
17
|
+
setup(options: Object): void;
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
}
|