• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15class Font {
16    /**
17     * Construct new instance of Font.
18     * initialzie with instanceId.
19     * @param instanceId obtained on the c++ side.
20     * @since 10
21     */
22    constructor(instanceId) {
23        this.instanceId_ = instanceId;
24        this.ohos_font = globalThis.requireNapi('font');
25    }
26    registerFont(options) {
27        __JSScopeUtil__.syncInstanceId(this.instanceId_);
28        this.ohos_font.registerFont(options);
29        __JSScopeUtil__.restoreInstanceId();
30    }
31
32    getSystemFontList() {
33        __JSScopeUtil__.syncInstanceId(this.instanceId_);
34        let arrayResult_ = this.ohos_font.getSystemFontList();
35        __JSScopeUtil__.restoreInstanceId();
36        return arrayResult_;
37    }
38
39    getFontByName(fontName) {
40        __JSScopeUtil__.syncInstanceId(this.instanceId_);
41        let result_ = this.ohos_font.getFontByName(fontName);
42        __JSScopeUtil__.restoreInstanceId();
43        return result_;
44    }
45}
46
47class MediaQuery {
48    /**
49     * Construct new instance of MediaQuery.
50     * initialzie with instanceId.
51     * @param instanceId obtained on the c++ side.
52     * @since 10
53     */
54    constructor(instanceId) {
55        this.instanceId_ = instanceId;
56        this.ohos_mediaQuery = globalThis.requireNapi('mediaquery');
57    }
58    matchMediaSync(condition) {
59        __JSScopeUtil__.syncInstanceId(this.instanceId_);
60        let mediaQueryListener = this.ohos_mediaQuery.matchMediaSync(condition);
61        __JSScopeUtil__.restoreInstanceId();
62        return mediaQueryListener;
63    }
64}
65
66class UIInspector {
67    /**
68     * Construct new instance of ArkUIInspector.
69     * initialzie with instanceId.
70     * @param instanceId obtained on the c++ side.
71     * @since 10
72     */
73    constructor(instanceId) {
74        this.instanceId_ = instanceId;
75        this.ohos_UIInspector  = globalThis.requireNapi('arkui.inspector');
76    }
77    createComponentObserver(id) {
78        __JSScopeUtil__.syncInstanceId(this.instanceId_);
79        let componentObserver = this.ohos_UIInspector.createComponentObserver(id);
80        __JSScopeUtil__.restoreInstanceId();
81        return componentObserver;
82    }
83}
84
85class UIContext {
86    /**
87     * Construct new instance of UIContext.
88     * initialzie with instanceId.
89     * @param instanceId obtained on the c++ side.
90     * @since 10
91     */
92    constructor(instanceId) {
93        this.instanceId_ = instanceId;
94    }
95
96    getFont() {
97        this.font_ = new Font(this.instanceId_);
98        return this.font_;
99    }
100
101    getRouter() {
102        this.router_ = new Router(this.instanceId_);
103        return this.router_;
104    }
105
106    createAnimator(options) {
107        __JSScopeUtil__.syncInstanceId(this.instanceId_);
108        this.animator_ = globalThis.requireNapi('animator');
109        let animatorResult = this.animator_.create(options);
110        __JSScopeUtil__.restoreInstanceId();
111        return animatorResult;
112    }
113
114    getPromptAction() {
115        this.promptAction_ = new PromptAction(this.instanceId_);
116        return this.promptAction_;
117    }
118
119    getMediaQuery() {
120        this.mediaQuery_ = new MediaQuery(this.instanceId_);
121        return this.mediaQuery_;
122    }
123
124    getUIInspector(){
125        this.UIInspector_ = new UIInspector(this.instanceId_);
126        return this.UIInspector_;
127    }
128
129    getComponentUtils() {
130        if(this.componentUtils_ == null) {
131            this.componentUtils_ = new ComponentUtils(this.instanceId_);
132        }
133        return this.componentUtils_;
134    }
135    animateTo(value, event) {
136        __JSScopeUtil__.syncInstanceId(this.instanceId_);
137        Context.animateTo(value, event);
138        __JSScopeUtil__.restoreInstanceId();
139    }
140
141    showAlertDialog(options) {
142        __JSScopeUtil__.syncInstanceId(this.instanceId_);
143        AlertDialog.show(options);
144        __JSScopeUtil__.restoreInstanceId();
145    }
146
147    showActionSheet(value) {
148        __JSScopeUtil__.syncInstanceId(this.instanceId_);
149        ActionSheet.show(value);
150        __JSScopeUtil__.restoreInstanceId();
151    }
152
153    showDatePickerDialog(options) {
154        __JSScopeUtil__.syncInstanceId(this.instanceId_);
155        DatePickerDialog.show(options);
156        __JSScopeUtil__.restoreInstanceId();
157    }
158
159    showTimePickerDialog(options) {
160        __JSScopeUtil__.syncInstanceId(this.instanceId_);
161        TimePickerDialog.show(options);
162        __JSScopeUtil__.restoreInstanceId();
163    }
164
165    showTextPickerDialog(options) {
166        __JSScopeUtil__.syncInstanceId(this.instanceId_);
167        TextPickerDialog.show(options);
168        __JSScopeUtil__.restoreInstanceId();
169    }
170
171    runScopedTask(callback) {
172        __JSScopeUtil__.syncInstanceId(this.instanceId_);
173        if (callback !== undefined) {
174            callback();
175        }
176        __JSScopeUtil__.restoreInstanceId();
177    }
178}
179class ComponentUtils {
180    /**
181     * Construct new instance of ComponentUtils.
182     * initialzie with instanceId.
183     * @param instanceId obtained on the c++ side.
184     * @since 10
185     */
186    constructor(instanceId) {
187        this.instanceId_ = instanceId;
188        this.ohos_componentUtils = globalThis.requireNapi('componentUtils');
189    }
190    getRectangleById(id) {
191        __JSScopeUtil__.syncInstanceId(this.instanceId_);
192        let componentInformation = this.ohos_componentUtils.getRectangleById(id);
193        __JSScopeUtil__.restoreInstanceId();
194        return componentInformation;
195    }
196}
197
198class Router {
199    /**
200     * Construct new instance of Font.
201     * initialzie with instanceId.
202     * @param instanceId obtained on the c++ side.
203     * @since 10
204     */
205    constructor(instanceId) {
206        this.instanceId_ = instanceId;
207        this.ohos_router = globalThis.requireNapi('router');
208    }
209
210    pushUrl(options, modeOrCallback, callback) {
211        __JSScopeUtil__.syncInstanceId(this.instanceId_);
212        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
213            let promise = this.ohos_router.pushUrl(options);
214            __JSScopeUtil__.restoreInstanceId();
215            return promise;
216        }
217        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
218            this.ohos_router.pushUrl(options, modeOrCallback, callback);
219            __JSScopeUtil__.restoreInstanceId();
220        }
221        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
222            let promise = this.ohos_router.pushUrl(options, modeOrCallback);
223            __JSScopeUtil__.restoreInstanceId();
224            if(promise)
225            {
226                return promise;
227            }
228        }
229    }
230
231    replaceUrl(options, modeOrCallback, callback) {
232        __JSScopeUtil__.syncInstanceId(this.instanceId_);
233        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
234            let promise = this.ohos_router.replaceUrl(options);
235            __JSScopeUtil__.restoreInstanceId();
236            return promise;
237        }
238        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
239            this.ohos_router.replaceUrl(options, modeOrCallback, callback);
240            __JSScopeUtil__.restoreInstanceId();
241        }
242        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
243            let promise = this.ohos_router.replaceUrl(options, modeOrCallback);
244            __JSScopeUtil__.restoreInstanceId();
245            if(promise)
246            {
247                return promise;
248            }
249        }
250    }
251
252    back(options) {
253        __JSScopeUtil__.syncInstanceId(this.instanceId_);
254        this.ohos_router.back(options);
255        __JSScopeUtil__.restoreInstanceId();
256    }
257
258    clear() {
259        __JSScopeUtil__.syncInstanceId(this.instanceId_);
260        this.ohos_router.clear();
261        __JSScopeUtil__.restoreInstanceId();
262    }
263
264    getLength() {
265        __JSScopeUtil__.syncInstanceId(this.instanceId_);
266        let result = this.ohos_router.getLength();
267        __JSScopeUtil__.restoreInstanceId();
268        return result;
269    }
270
271    getState() {
272        __JSScopeUtil__.syncInstanceId(this.instanceId_);
273        let state = this.ohos_router.getState();
274        __JSScopeUtil__.restoreInstanceId();
275        return state;
276    }
277
278    showAlertBeforeBackPage(options) {
279        __JSScopeUtil__.syncInstanceId(this.instanceId_);
280        this.ohos_router.showAlertBeforeBackPage(options);
281        __JSScopeUtil__.restoreInstanceId();
282    }
283
284    hideAlertBeforeBackPage() {
285        __JSScopeUtil__.syncInstanceId(this.instanceId_);
286        this.ohos_router.hideAlertBeforeBackPage();
287        __JSScopeUtil__.restoreInstanceId();
288    }
289
290    getParams() {
291        __JSScopeUtil__.syncInstanceId(this.instanceId_);
292        let object = this.ohos_router.getParams();
293        __JSScopeUtil__.restoreInstanceId();
294        return object;
295    }
296
297    pushNamedRoute(options, modeOrCallback, callback) {
298        __JSScopeUtil__.syncInstanceId(this.instanceId_);
299        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
300            let promise = this.ohos_router.pushNamedRoute(options);
301            __JSScopeUtil__.restoreInstanceId();
302            return promise;
303        }
304        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
305            this.ohos_router.pushNamedRoute(options, modeOrCallback, callback);
306            __JSScopeUtil__.restoreInstanceId();
307        }
308        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
309            let promise = this.ohos_router.pushNamedRoute(options, modeOrCallback);
310            __JSScopeUtil__.restoreInstanceId();
311            if(promise)
312            {
313                return promise;
314            }
315        }
316    }
317
318    replaceNamedRoute(options, modeOrCallback, callback) {
319        __JSScopeUtil__.syncInstanceId(this.instanceId_);
320        if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') {
321            let promise = this.ohos_router.replaceNamedRoute(options);
322            __JSScopeUtil__.restoreInstanceId();
323            return promise;
324        }
325        else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') {
326            this.ohos_router.replaceNamedRoute(options, modeOrCallback, callback);
327            __JSScopeUtil__.restoreInstanceId();
328        }
329        else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') {
330            let promise = this.ohos_router.replaceNamedRoute(options, modeOrCallback);
331            __JSScopeUtil__.restoreInstanceId();
332            if(promise)
333            {
334                return promise;
335            }
336        }
337    }
338}
339
340class PromptAction {
341    /**
342     * Construct new instance of PromptAction.
343     * initialzie with instanceId.
344     * @param instanceId obtained on the c++ side.
345     * @since 10
346     */
347    constructor(instanceId) {
348        this.instanceId_ = instanceId;
349        this.ohos_prompt = globalThis.requireNapi('promptAction');
350    }
351
352    showToast(options) {
353        __JSScopeUtil__.syncInstanceId(this.instanceId_);
354        this.ohos_prompt.showToast(options);
355        __JSScopeUtil__.restoreInstanceId();
356    }
357
358    showDialog(options, callback) {
359        __JSScopeUtil__.syncInstanceId(this.instanceId_);
360        if (typeof callback !== 'undefined') {
361            this.ohos_prompt.showDialog(options, callback);
362            __JSScopeUtil__.restoreInstanceId();
363        }
364        else {
365            let showDialogSuccessResponse = this.ohos_prompt.showDialog(options);
366            __JSScopeUtil__.restoreInstanceId();
367            return showDialogSuccessResponse;
368        }
369    }
370
371    showActionMenu(options, callback) {
372        __JSScopeUtil__.syncInstanceId(this.instanceId_);
373        if (typeof callback !== 'undefined') {
374            this.ohos_prompt.showActionMenu(options, callback);
375            __JSScopeUtil__.restoreInstanceId();
376        }
377        else {
378            let actionMenuSuccessResponse = this.ohos_prompt.showActionMenu(options);
379            __JSScopeUtil__.restoreInstanceId();
380            return actionMenuSuccessResponse;
381        }
382    }
383}
384
385/**
386 * Get UIContext instance.
387 * @param instanceId obtained on the c++ side.
388 * @returns UIContext instance.
389 */
390function __getUIContext__(instanceId) {
391    return new UIContext(instanceId);
392}
393