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 */ 15 16class Font { 17 /** 18 * Construct new instance of Font. 19 * initialize with instanceId. 20 * @param instanceId obtained on the c++ side. 21 * @since 10 22 */ 23 constructor(instanceId) { 24 this.instanceId_ = instanceId; 25 this.ohos_font = globalThis.requireNapi('font'); 26 } 27 registerFont(options) { 28 __JSScopeUtil__.syncInstanceId(this.instanceId_); 29 this.ohos_font.registerFont(options); 30 __JSScopeUtil__.restoreInstanceId(); 31 } 32 33 getSystemFontList() { 34 __JSScopeUtil__.syncInstanceId(this.instanceId_); 35 let arrayResult_ = this.ohos_font.getSystemFontList(); 36 __JSScopeUtil__.restoreInstanceId(); 37 return arrayResult_; 38 } 39 40 getFontByName(fontName) { 41 __JSScopeUtil__.syncInstanceId(this.instanceId_); 42 let result_ = this.ohos_font.getFontByName(fontName); 43 __JSScopeUtil__.restoreInstanceId(); 44 return result_; 45 } 46} 47 48class MediaQuery { 49 /** 50 * Construct new instance of MediaQuery. 51 * initialize with instanceId. 52 * @param instanceId obtained on the c++ side. 53 * @since 10 54 */ 55 constructor(instanceId) { 56 this.instanceId_ = instanceId; 57 this.ohos_mediaQuery = globalThis.requireNapi('mediaquery'); 58 } 59 matchMediaSync(condition) { 60 __JSScopeUtil__.syncInstanceId(this.instanceId_); 61 let mediaQueryListener = this.ohos_mediaQuery.matchMediaSync(condition); 62 __JSScopeUtil__.restoreInstanceId(); 63 return mediaQueryListener; 64 } 65} 66 67class UIInspector { 68 /** 69 * Construct new instance of ArkUIInspector. 70 * initialize with instanceId. 71 * @param instanceId obtained on the c++ side. 72 * @since 10 73 */ 74 constructor(instanceId) { 75 this.instanceId_ = instanceId; 76 this.ohos_UIInspector = globalThis.requireNapi('arkui.inspector'); 77 } 78 createComponentObserver(id) { 79 __JSScopeUtil__.syncInstanceId(this.instanceId_); 80 let componentObserver = this.ohos_UIInspector.createComponentObserver(id); 81 __JSScopeUtil__.restoreInstanceId(); 82 return componentObserver; 83 } 84} 85 86class ComponentSnapshot { 87 constructor(instanceId) { 88 this.instanceId_ = instanceId; 89 this.ohos_componentSnapshot = globalThis.requireNapi('arkui.componentSnapshot'); 90 } 91 get(id, callback, options) { 92 __JSScopeUtil__.syncInstanceId(this.instanceId_); 93 if (typeof callback !== 'function') { 94 let promise = this.ohos_componentSnapshot.get(id, callback); 95 __JSScopeUtil__.restoreInstanceId(); 96 return promise; 97 } else { 98 this.ohos_componentSnapshot.get(id, callback, options); 99 __JSScopeUtil__.restoreInstanceId(); 100 } 101 } 102 createFromBuilder(builder, callback, delay, checkImageStatus, options) { 103 __JSScopeUtil__.syncInstanceId(this.instanceId_); 104 if (typeof callback !== 'function') { 105 let promise = this.ohos_componentSnapshot.createFromBuilder(builder, callback, delay, checkImageStatus); 106 __JSScopeUtil__.restoreInstanceId(); 107 return promise; 108 } else { 109 this.ohos_componentSnapshot.createFromBuilder(builder, callback, delay, checkImageStatus, options); 110 __JSScopeUtil__.restoreInstanceId(); 111 } 112 } 113 getSync(id, options) { 114 __JSScopeUtil__.syncInstanceId(this.instanceId_); 115 let pixelmap = this.ohos_componentSnapshot.getSync(id, options); 116 __JSScopeUtil__.restoreInstanceId(); 117 return pixelmap; 118 } 119 120 getWithUniqueId(uniqueId, options) { 121 __JSScopeUtil__.syncInstanceId(this.instanceId_); 122 let promise = this.ohos_componentSnapshot.getWithUniqueId(uniqueId, options); 123 __JSScopeUtil__.restoreInstanceId(); 124 return promise; 125 } 126 127 getSyncWithUniqueId(uniqueId, options) { 128 __JSScopeUtil__.syncInstanceId(this.instanceId_); 129 let pixelmap = this.ohos_componentSnapshot.getSyncWithUniqueId(uniqueId, options); 130 __JSScopeUtil__.restoreInstanceId(); 131 return pixelmap; 132 } 133} 134 135class DragController { 136 /** 137 * Construct new instance of DragController. 138 * initialize with instanceId. 139 * @param instanceId obtained on the c++ side. 140 * @since 11 141 */ 142 constructor(instanceId) { 143 this.instanceId_ = instanceId; 144 this.ohos_dragController = globalThis.requireNapi('arkui.dragController'); 145 } 146 147 executeDrag(custom, dragInfo, callback) { 148 __JSScopeUtil__.syncInstanceId(this.instanceId_); 149 if (typeof callback !== 'undefined') { 150 this.ohos_dragController.executeDrag(custom, dragInfo, callback); 151 __JSScopeUtil__.restoreInstanceId(); 152 } else { 153 let eventPromise = this.ohos_dragController.executeDrag(custom, dragInfo); 154 __JSScopeUtil__.restoreInstanceId(); 155 return eventPromise; 156 } 157 } 158 159 createDragAction(customs, dragInfo) { 160 __JSScopeUtil__.syncInstanceId(this.instanceId_); 161 let dragAction = this.ohos_dragController.createDragAction(customs, dragInfo); 162 __JSScopeUtil__.restoreInstanceId(); 163 return dragAction; 164 } 165 166 getDragPreview() { 167 __JSScopeUtil__.syncInstanceId(this.instanceId_); 168 let dragPreview = this.ohos_dragController.getDragPreview(); 169 __JSScopeUtil__.restoreInstanceId(); 170 return dragPreview; 171 } 172 173 setDragEventStrictReportingEnabled(enable) { 174 __JSScopeUtil__.syncInstanceId(this.instanceId_); 175 JSViewAbstract.setDragEventStrictReportingEnabled(enable); 176 __JSScopeUtil__.restoreInstanceId(); 177 } 178 179 cancelDataLoading(key) { 180 __JSScopeUtil__.syncInstanceId(this.instanceId_); 181 JSViewAbstract.cancelDataLoading(key); 182 __JSScopeUtil__.restoreInstanceId(); 183 } 184} 185 186class UIObserver { 187 constructor(instanceId) { 188 this.instanceId_ = instanceId; 189 this.ohos_observer = globalThis.requireNapi('arkui.observer'); 190 } 191 on(...args) { 192 __JSScopeUtil__.syncInstanceId(this.instanceId_); 193 this.ohos_observer.on(...args); 194 __JSScopeUtil__.restoreInstanceId(); 195 } 196 off(...args) { 197 __JSScopeUtil__.syncInstanceId(this.instanceId_); 198 this.ohos_observer.off(...args); 199 __JSScopeUtil__.restoreInstanceId(); 200 } 201} 202 203class MeasureUtils { 204 /** 205 * Construct new instance of MeasureUtils. 206 * initialize with instanceId. 207 * @param instanceId obtained on the c++ side. 208 * @since 12 209 */ 210 constructor(instanceId) { 211 this.instanceId_ = instanceId; 212 this.ohos_measureUtils = globalThis.requireNapi('measure'); 213 } 214 215 measureText(options) { 216 __JSScopeUtil__.syncInstanceId(this.instanceId_); 217 let number = this.ohos_measureUtils.measureText(options); 218 __JSScopeUtil__.restoreInstanceId(); 219 return number; 220 } 221 222 measureTextSize(options) { 223 __JSScopeUtil__.syncInstanceId(this.instanceId_); 224 let sizeOption = this.ohos_measureUtils.measureTextSize(options); 225 __JSScopeUtil__.restoreInstanceId(); 226 return sizeOption; 227 } 228} 229 230class FrameCallback { 231} 232 233class UIContext { 234 /** 235 * Construct new instance of UIContext. 236 * initialize with instanceId. 237 * @param instanceId obtained on the c++ side. 238 * @since 10 239 */ 240 constructor(instanceId) { 241 this.instanceId_ = instanceId; 242 } 243 244 getDragController() { 245 this.dragController_ = new DragController(this.instanceId_); 246 return this.dragController_; 247 } 248 249 getFont() { 250 this.font_ = new Font(this.instanceId_); 251 return this.font_; 252 } 253 254 getRouter() { 255 this.router_ = new Router(this.instanceId_); 256 return this.router_; 257 } 258 259 createAnimator(options) { 260 __JSScopeUtil__.syncInstanceId(this.instanceId_); 261 this.animator_ = globalThis.requireNapi('animator'); 262 let animatorResult = this.animator_.create(options); 263 __JSScopeUtil__.restoreInstanceId(); 264 return animatorResult; 265 } 266 267 getPromptAction() { 268 this.promptAction_ = new PromptAction(this.instanceId_); 269 return this.promptAction_; 270 } 271 272 getMediaQuery() { 273 this.mediaQuery_ = new MediaQuery(this.instanceId_); 274 return this.mediaQuery_; 275 } 276 277 getUIInspector() { 278 this.UIInspector_ = new UIInspector(this.instanceId_); 279 return this.UIInspector_; 280 } 281 282 getFilteredInspectorTree(filter) { 283 __JSScopeUtil__.syncInstanceId(this.instanceId_); 284 if (typeof filter === 'undefined') { 285 let result_ = globalThis.getFilteredInspectorTree(); 286 __JSScopeUtil__.restoreInstanceId(); 287 return result_; 288 } else { 289 let result_ = globalThis.getFilteredInspectorTree(filter); 290 __JSScopeUtil__.restoreInstanceId(); 291 return result_; 292 } 293 } 294 295 getFilteredInspectorTreeById(id, depth, filter) { 296 __JSScopeUtil__.syncInstanceId(this.instanceId_); 297 if (typeof filter === 'undefined') { 298 let result_ = globalThis.getFilteredInspectorTreeById(id, depth); 299 __JSScopeUtil__.restoreInstanceId(); 300 return result_; 301 } else { 302 let result_ = globalThis.getFilteredInspectorTreeById(id, depth, filter); 303 __JSScopeUtil__.restoreInstanceId(); 304 return result_; 305 } 306 } 307 308 getComponentSnapshot() { 309 this.ComponentSnapshot_ = new ComponentSnapshot(this.instanceId_); 310 return this.ComponentSnapshot_; 311 } 312 313 vp2px(value) { 314 __JSScopeUtil__.syncInstanceId(this.instanceId_); 315 let vp2pxResult = globalThis.vp2px(value); 316 __JSScopeUtil__.restoreInstanceId(); 317 return vp2pxResult; 318 } 319 320 px2vp(value) { 321 __JSScopeUtil__.syncInstanceId(this.instanceId_); 322 let px2vpResult = globalThis.px2vp(value); 323 __JSScopeUtil__.restoreInstanceId(); 324 return px2vpResult; 325 } 326 327 fp2px(value) { 328 __JSScopeUtil__.syncInstanceId(this.instanceId_); 329 let fp2pxResult = globalThis.fp2px(value); 330 __JSScopeUtil__.restoreInstanceId(); 331 return fp2pxResult; 332 } 333 334 px2fp(value) { 335 __JSScopeUtil__.syncInstanceId(this.instanceId_); 336 let px2fpResult = globalThis.px2fp(value); 337 __JSScopeUtil__.restoreInstanceId(); 338 return px2fpResult; 339 } 340 341 lpx2px(value) { 342 __JSScopeUtil__.syncInstanceId(this.instanceId_); 343 let lpx2pxResult = globalThis.lpx2px(value); 344 __JSScopeUtil__.restoreInstanceId(); 345 return lpx2pxResult; 346 } 347 348 px2lpx(value) { 349 __JSScopeUtil__.syncInstanceId(this.instanceId_); 350 let px2lpxResult = globalThis.px2lpx(value); 351 __JSScopeUtil__.restoreInstanceId(); 352 return px2lpxResult; 353 } 354 355 getComponentUtils() { 356 if (this.componentUtils_ == null) { 357 this.componentUtils_ = new ComponentUtils(this.instanceId_); 358 } 359 return this.componentUtils_; 360 } 361 362 getOverlayManager() { 363 if(!this.overlayManager_) { 364 this.overlayManager_ = new OverlayManager(this.instanceId_); 365 } 366 this.overlayManager_.setOverlayManagerOptions(); 367 return this.overlayManager_; 368 } 369 setOverlayManagerOptions(options) { 370 if(!this.overlayManager_) { 371 this.overlayManager_ = new OverlayManager(this.instanceId_); 372 } 373 return this.overlayManager_.setOverlayManagerOptions(options); 374 } 375 getOverlayManagerOptions() { 376 if(!this.overlayManager_) { 377 this.overlayManager_ = new OverlayManager(this.instanceId_); 378 } 379 return this.overlayManager_.getOverlayManagerOptions(); 380 } 381 382 animateTo(value, event) { 383 __JSScopeUtil__.syncInstanceId(this.instanceId_); 384 Context.animateTo(value, event); 385 __JSScopeUtil__.restoreInstanceId(); 386 } 387 388 showAlertDialog(options) { 389 __JSScopeUtil__.syncInstanceId(this.instanceId_); 390 AlertDialog.show(options); 391 __JSScopeUtil__.restoreInstanceId(); 392 } 393 394 showActionSheet(value) { 395 __JSScopeUtil__.syncInstanceId(this.instanceId_); 396 ActionSheet.show(value); 397 __JSScopeUtil__.restoreInstanceId(); 398 } 399 400 openBindSheet(content, options, targetId) { 401 let paramErrMsg = 402 'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' + 403 ' 2. Incorrect parameter types; 3. Parameter verification failed.'; 404 __JSScopeUtil__.syncInstanceId(this.instanceId_); 405 let argLength = arguments.length; 406 if (argLength < 1 || content === null || content === undefined) { 407 __JSScopeUtil__.restoreInstanceId(); 408 return new Promise((resolve, reject) => { 409 reject({ message: paramErrMsg, code: 401 }); 410 }); 411 } 412 if ((argLength >= 3 && (targetId === null || targetId === undefined))) { 413 __JSScopeUtil__.restoreInstanceId(); 414 return new Promise((resolve, reject) => { 415 reject({ message: paramErrMsg, code: 401 }); 416 }); 417 } 418 let result_; 419 if (argLength === 1) { 420 result_ = Context.openBindSheet(content.getNodePtr()); 421 } else if (argLength === 2) { 422 result_ = Context.openBindSheet(content.getNodePtr(), options); 423 } else { 424 result_ = Context.openBindSheet(content.getNodePtr(), options, targetId); 425 } 426 __JSScopeUtil__.restoreInstanceId(); 427 return result_; 428 } 429 430 updateBindSheet(content, options, partialUpdate) { 431 let paramErrMsg = 432 'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' + 433 ' 2. Incorrect parameter types; 3. Parameter verification failed.'; 434 __JSScopeUtil__.syncInstanceId(this.instanceId_); 435 let argLength = arguments.length; 436 if (argLength < 2 || content === null || content === undefined) { 437 __JSScopeUtil__.restoreInstanceId(); 438 return new Promise((resolve, reject) => { 439 reject({ message: paramErrMsg, code: 401 }); 440 }); 441 } 442 let result_; 443 if (argLength === 2) { 444 result_ = Context.updateBindSheet(content.getNodePtr(), options); 445 } else { 446 result_ = Context.updateBindSheet(content.getNodePtr(), options, partialUpdate); 447 } 448 __JSScopeUtil__.restoreInstanceId(); 449 return result_; 450 } 451 452 closeBindSheet(content) { 453 let paramErrMsg = 454 'Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;' + 455 ' 2. Incorrect parameter types; 3. Parameter verification failed.'; 456 __JSScopeUtil__.syncInstanceId(this.instanceId_); 457 if (arguments.length < 1 || content === null || content === undefined) { 458 __JSScopeUtil__.restoreInstanceId(); 459 return new Promise((resolve, reject) => { 460 reject({ message: paramErrMsg, code: 401 }); 461 }); 462 } 463 let result_ = Context.closeBindSheet(content.getNodePtr()); 464 __JSScopeUtil__.restoreInstanceId(); 465 return result_; 466 } 467 468 showDatePickerDialog(options) { 469 __JSScopeUtil__.syncInstanceId(this.instanceId_); 470 DatePickerDialog.show(options); 471 __JSScopeUtil__.restoreInstanceId(); 472 } 473 474 showTimePickerDialog(options) { 475 __JSScopeUtil__.syncInstanceId(this.instanceId_); 476 TimePickerDialog.show(options); 477 __JSScopeUtil__.restoreInstanceId(); 478 } 479 480 showTextPickerDialog(options) { 481 __JSScopeUtil__.syncInstanceId(this.instanceId_); 482 TextPickerDialog.show(options); 483 __JSScopeUtil__.restoreInstanceId(); 484 } 485 486 runScopedTask(callback) { 487 __JSScopeUtil__.syncInstanceId(this.instanceId_); 488 if (callback !== undefined) { 489 callback(); 490 } 491 __JSScopeUtil__.restoreInstanceId(); 492 } 493 494 setKeyboardAvoidMode(value) { 495 __JSScopeUtil__.syncInstanceId(this.instanceId_); 496 __KeyboardAvoid__.setKeyboardAvoid(value); 497 __JSScopeUtil__.restoreInstanceId(); 498 } 499 500 getKeyboardAvoidMode() { 501 __JSScopeUtil__.syncInstanceId(this.instanceId_); 502 let keyBoardAvoidMode = __KeyboardAvoid__.getKeyboardAvoid(); 503 __JSScopeUtil__.restoreInstanceId(); 504 return keyBoardAvoidMode; 505 } 506 507 dispatchKeyEvent(node, event) { 508 __JSScopeUtil__.syncInstanceId(this.instanceId_); 509 let result = JSViewAbstract.dispatchKeyEvent(node, event); 510 __JSScopeUtil__.restoreInstanceId(); 511 return result; 512 } 513 514 getAtomicServiceBar() { 515 const bundleMgr = globalThis.requireNapi('bundle.bundleManager'); 516 if (!bundleMgr || !bundleMgr.BundleFlag) { 517 return undefined; 518 } 519 let data = bundleMgr.getBundleInfoForSelfSync(bundleMgr.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION); 520 if (data.appInfo.bundleType == 1) { 521 this.atomServiceBar = new AtomicServiceBar(this.instanceId_); 522 return this.atomServiceBar; 523 } else { 524 return undefined; 525 } 526 } 527 528 getUIObserver() { 529 this.observer_ = new UIObserver(this.instanceId_); 530 return this.observer_; 531 } 532 533 keyframeAnimateTo(param, keyframes) { 534 __JSScopeUtil__.syncInstanceId(this.instanceId_); 535 Context.keyframeAnimateTo(param, keyframes); 536 __JSScopeUtil__.restoreInstanceId(); 537 } 538 539 animateToImmediately(param, event) { 540 __JSScopeUtil__.syncInstanceId(this.instanceId_); 541 Context.animateToImmediately(param, event); 542 __JSScopeUtil__.restoreInstanceId(); 543 } 544 545 getMeasureUtils() { 546 this.measureUtils_ = new MeasureUtils(this.instanceId_); 547 return this.measureUtils_; 548 } 549 550 getHostContext() { 551 __JSScopeUtil__.syncInstanceId(this.instanceId_); 552 let context = getContext(); 553 __JSScopeUtil__.restoreInstanceId(); 554 return context; 555 } 556 557 getSharedLocalStorage() { 558 __JSScopeUtil__.syncInstanceId(this.instanceId_); 559 let localStorage = NativeLocalStorage.GetShared(); 560 __JSScopeUtil__.restoreInstanceId(); 561 return localStorage; 562 } 563 564 getFrameNodeById(id) { 565 __JSScopeUtil__.syncInstanceId(this.instanceId_); 566 let nodePtr = getUINativeModule().getFrameNodeByKey(id); 567 if (!nodePtr) { 568 __JSScopeUtil__.restoreInstanceId(); 569 return null; 570 } 571 let xNode = globalThis.__getArkUINode__(); 572 let node = xNode.FrameNodeUtils.searchNodeInRegisterProxy(nodePtr); 573 if (!node) { 574 node = xNode.FrameNodeUtils.createFrameNode(this, nodePtr); 575 } 576 __JSScopeUtil__.restoreInstanceId(); 577 return node; 578 } 579 580 getAttachedFrameNodeById(id) { 581 __JSScopeUtil__.syncInstanceId(this.instanceId_); 582 let nodePtr = getUINativeModule().getAttachedFrameNodeById(id); 583 if (!nodePtr) { 584 __JSScopeUtil__.restoreInstanceId(); 585 return null; 586 } 587 let xNode = globalThis.__getArkUINode__(); 588 let node = xNode.FrameNodeUtils.searchNodeInRegisterProxy(nodePtr); 589 if (!node) { 590 node = xNode.FrameNodeUtils.createFrameNode(this, nodePtr); 591 } 592 __JSScopeUtil__.restoreInstanceId(); 593 return node; 594 } 595 596 getFrameNodeByNodeId(id) { 597 __JSScopeUtil__.syncInstanceId(this.instanceId_); 598 let nodePtr = getUINativeModule().getFrameNodeById(id); 599 let xNode = globalThis.__getArkUINode__(); 600 let node = xNode.FrameNodeUtils.searchNodeInRegisterProxy(nodePtr); 601 if (!node) { 602 node = xNode.FrameNodeUtils.createFrameNode(this, nodePtr); 603 } 604 __JSScopeUtil__.restoreInstanceId(); 605 return node; 606 } 607 608 getFocusController() { 609 if (this.focusController_ == null) { 610 this.focusController_ = new FocusController(this.instanceId_); 611 } 612 return this.focusController_; 613 } 614 615 setDynamicDimming(id, number) { 616 __JSScopeUtil__.syncInstanceId(this.instanceId_); 617 let nodePtr = getUINativeModule().getFrameNodeByKey(id); 618 if (!nodePtr) { 619 return; 620 } 621 Context.setDynamicDimming(nodePtr, number); 622 } 623 624 getFrameNodeByUniqueId(uniqueId) { 625 __JSScopeUtil__.syncInstanceId(this.instanceId_); 626 let nodePtr = getUINativeModule().getFrameNodeByUniqueId(uniqueId); 627 if (nodePtr === undefined) { 628 __JSScopeUtil__.restoreInstanceId(); 629 return null; 630 } 631 let xNode = globalThis.__getArkUINode__(); 632 let node = xNode.FrameNodeUtils.searchNodeInRegisterProxy(nodePtr); 633 if (!node) { 634 node = xNode.FrameNodeUtils.createFrameNode(this, nodePtr); 635 } 636 __JSScopeUtil__.restoreInstanceId(); 637 return node; 638 } 639 640 getPageInfoByUniqueId(uniqueId) { 641 __JSScopeUtil__.syncInstanceId(this.instanceId_); 642 const pageInfo = getUINativeModule().getPageInfoByUniqueId(uniqueId); 643 __JSScopeUtil__.restoreInstanceId(); 644 return pageInfo; 645 } 646 647 getNavigationInfoByUniqueId(uniqueId) { 648 __JSScopeUtil__.syncInstanceId(this.instanceId_); 649 const navigationInfo = getUINativeModule().getNavigationInfoByUniqueId(uniqueId); 650 __JSScopeUtil__.restoreInstanceId(); 651 return navigationInfo; 652 } 653 654 getCursorController() { 655 if (this.cursorController_ == null) { 656 this.cursorController_ = new CursorController(this.instanceId_); 657 } 658 return this.cursorController_; 659 } 660 661 getContextMenuController() { 662 if (this.contextMenuController_ == null) { 663 this.contextMenuController_ = new ContextMenuController(this.instanceId_); 664 } 665 return this.contextMenuController_; 666 } 667 668 getWindowName() { 669 __JSScopeUtil__.syncInstanceId(this.instanceId_); 670 const windowName = getUINativeModule().common.getWindowName(); 671 __JSScopeUtil__.restoreInstanceId(); 672 return windowName 673 } 674 675 getWindowWidthBreakpoint() { 676 __JSScopeUtil__.syncInstanceId(this.instanceId_); 677 const breakpoint = getUINativeModule().common.getWindowWidthBreakpoint(); 678 __JSScopeUtil__.restoreInstanceId(); 679 return breakpoint; 680 } 681 682 getWindowHeightBreakpoint() { 683 __JSScopeUtil__.syncInstanceId(this.instanceId_); 684 const breakpoint = getUINativeModule().common.getWindowHeightBreakpoint(); 685 __JSScopeUtil__.restoreInstanceId(); 686 return breakpoint; 687 } 688 689 postFrameCallback(frameCallback) { 690 __JSScopeUtil__.syncInstanceId(this.instanceId_); 691 getUINativeModule().common.postFrameCallback(frameCallback, 0); 692 __JSScopeUtil__.restoreInstanceId(); 693 } 694 695 postDelayedFrameCallback(frameCallback, delayMillis) { 696 __JSScopeUtil__.syncInstanceId(this.instanceId_); 697 getUINativeModule().common.postFrameCallback(frameCallback, delayMillis); 698 __JSScopeUtil__.restoreInstanceId(); 699 } 700 701 clearResourceCache() { 702 getUINativeModule().resource.clearCache(); 703 } 704 705 requireDynamicSyncScene(id) { 706 __JSScopeUtil__.syncInstanceId(this.instanceId_); 707 let dynamicSceneInfo = getUINativeModule().requireDynamicSyncScene(id); 708 if (!dynamicSceneInfo) { 709 __JSScopeUtil__.restoreInstanceId(); 710 return []; 711 } 712 if (dynamicSceneInfo.tag == 'Swiper') { 713 __JSScopeUtil__.restoreInstanceId(); 714 let nodeRef = dynamicSceneInfo.nativeRef; 715 return SwiperDynamicSyncScene.createInstances(nodeRef); 716 } 717 if (dynamicSceneInfo.tag == 'Marquee') { 718 __JSScopeUtil__.restoreInstanceId(); 719 let nodeRef = dynamicSceneInfo.nativeRef; 720 return MarqueeDynamicSyncScene.createInstances(nodeRef); 721 } 722 __JSScopeUtil__.restoreInstanceId(); 723 return []; 724 } 725 726 isFollowingSystemFontScale() { 727 __JSScopeUtil__.syncInstanceId(this.instanceId_); 728 let isFollowing = Context.isFollowingSystemFontScale(); 729 __JSScopeUtil__.restoreInstanceId(); 730 return isFollowing; 731 } 732 733 getMaxFontScale() { 734 __JSScopeUtil__.syncInstanceId(this.instanceId_); 735 let maxFontScale = Context.getMaxFontScale(); 736 __JSScopeUtil__.restoreInstanceId(); 737 return maxFontScale; 738 } 739 740 bindTabsToScrollable(tabsController, scroller) { 741 __JSScopeUtil__.syncInstanceId(this.instanceId_); 742 Context.bindTabsToScrollable(tabsController, scroller); 743 __JSScopeUtil__.restoreInstanceId(); 744 } 745 746 unbindTabsFromScrollable(tabsController, scroller) { 747 __JSScopeUtil__.syncInstanceId(this.instanceId_); 748 Context.unbindTabsFromScrollable(tabsController, scroller); 749 __JSScopeUtil__.restoreInstanceId(); 750 } 751 752 bindTabsToNestedScrollable(tabsController, parentScroller, childScroller) { 753 __JSScopeUtil__.syncInstanceId(this.instanceId_); 754 Context.bindTabsToNestedScrollable(tabsController, parentScroller, childScroller); 755 __JSScopeUtil__.restoreInstanceId(); 756 } 757 758 unbindTabsFromNestedScrollable(tabsController, parentScroller, childScroller) { 759 __JSScopeUtil__.syncInstanceId(this.instanceId_); 760 Context.unbindTabsFromNestedScrollable(tabsController, parentScroller, childScroller); 761 __JSScopeUtil__.restoreInstanceId(); 762 } 763} 764 765class DynamicSyncScene { 766 /** 767 * Construct new instance of DynamicSyncScene. 768 * initialize with instanceId. 769 * @param {Object} nodeRef - obtained on the c++ side. 770 * @param {Object} frameRateRange - frameRateRange 771 * @since 12 772 */ 773 constructor(nodeRef, frameRateRange) { 774 this.frameRateRange = { ...frameRateRange }; 775 if (!nodeRef.invalid()) { 776 this.nodeRef = nodeRef; 777 this.nodePtr = this.nodeRef.getNativeHandle(); 778 } 779 } 780 781 /** 782 * Get the frame rate range. 783 * @returns {Object} The frame rate range. 784 */ 785 getFrameRateRange() { 786 return this.frameRateRange; 787 } 788} 789 790class SwiperDynamicSyncScene extends DynamicSyncScene { 791 /** 792 * Create instances of SwiperDynamicSyncScene. 793 * @param {Object} nodeRef - obtained on the c++ side. 794 * @returns {SwiperDynamicSyncScene[]} Array of SwiperDynamicSyncScene instances. 795 */ 796 static createInstances(nodeRef) { 797 return [new SwiperDynamicSyncScene(nodeRef, 0), new SwiperDynamicSyncScene(nodeRef, 1)]; 798 } 799 800 /** 801 * Construct new instance of SwiperDynamicSyncScene. 802 * @param {Object} nodeRef - obtained on the c++ side. 803 * @param {number} type - type of the scenes. 804 */ 805 constructor(nodeRef, type) { 806 super(nodeRef, { min: 0, max: 120, expected: 120 }); 807 this.type = type; 808 } 809 810 /** 811 * Set the frame rate range. 812 * @param {Object} frameRateRange - The new frame rate range. 813 */ 814 setFrameRateRange(frameRateRange) { 815 this.frameRateRange = { ...frameRateRange }; 816 getUINativeModule().setFrameRateRange(this.nodePtr, frameRateRange, this.type); 817 } 818} 819 820class MarqueeDynamicSyncScene extends DynamicSyncScene { 821 /** 822 * Create instances of MarqueeDynamicSyncScene. 823 * @param {Object} nodeRef - obtained on the c++ side. 824 * @returns {MarqueeDynamicSyncScene[]} Array of MarqueeDynamicSyncScene instances. 825 */ 826 static createInstances(nodeRef) { 827 return [new MarqueeDynamicSyncScene(nodeRef, 1)]; 828 } 829 830 /** 831 * Construct new instance of MarqueeDynamicSyncScene. 832 * @param {Object} nodeRef - obtained on the c++ side. 833 */ 834 constructor(nodeRef, type) { 835 super(nodeRef, { min: 0, max: 120, expected: 120 }); 836 this.type = type; 837 } 838 839 /** 840 * Set the frame rate range. 841 * @param {Object} frameRateRange - The new frame rate range. 842 */ 843 setFrameRateRange(frameRateRange) { 844 this.frameRateRange = { ...frameRateRange }; // 确保每个实例有独立的frameRateRange 845 getUINativeModule().setMarqueeFrameRateRange(this.nodePtr, frameRateRange, this.type); 846 } 847} 848 849class FocusController { 850 /** 851 * Construct new instance of FocusController. 852 * initialize with instanceId. 853 * @param instanceId obtained on the c++ side. 854 * @since 12 855 */ 856 constructor(instanceId) { 857 this.instanceId_ = instanceId; 858 this.ohos_focusController = globalThis.requireNapi('arkui.focusController'); 859 } 860 clearFocus() { 861 if (this.ohos_focusController === null || this.ohos_focusController === undefined) { 862 return; 863 } 864 __JSScopeUtil__.syncInstanceId(this.instanceId_); 865 this.ohos_focusController.clearFocus(); 866 __JSScopeUtil__.restoreInstanceId(); 867 } 868 869 requestFocus(value) { 870 if (this.ohos_focusController === null || this.ohos_focusController === undefined) { 871 return false; 872 } 873 __JSScopeUtil__.syncInstanceId(this.instanceId_); 874 let result = this.ohos_focusController.requestFocus(value); 875 __JSScopeUtil__.restoreInstanceId(); 876 return result; 877 } 878 879 activate(isActive, autoInactive) { 880 __JSScopeUtil__.syncInstanceId(this.instanceId_); 881 if (arguments.length === 2) { 882 let result = this.ohos_focusController.activate(isActive, autoInactive); 883 __JSScopeUtil__.restoreInstanceId(); 884 return result; 885 } else { 886 let result = this.ohos_focusController.activate(isActive); 887 __JSScopeUtil__.restoreInstanceId(); 888 return result; 889 } 890 } 891 892 setKeyProcessingMode(value) { 893 if (this.ohos_focusController === null || this.ohos_focusController === undefined) { 894 return; 895 } 896 __JSScopeUtil__.syncInstanceId(this.instanceId_); 897 this.ohos_focusController.setKeyProcessingMode(value); 898 __JSScopeUtil__.restoreInstanceId(); 899 } 900 901 setAutoFocusTransfer(value) { 902 __JSScopeUtil__.syncInstanceId(this.instanceId_); 903 this.ohos_focusController.setAutoFocusTransfer(value); 904 __JSScopeUtil__.restoreInstanceId(); 905 } 906} 907 908class CursorController { 909 /** 910 * Construct new instance of CursorController. 911 * initialzie with instanceId. 912 * @param instanceId obtained on the c++ side. 913 * @since 12 914 */ 915 constructor(instanceId) { 916 this.instanceId_ = instanceId; 917 } 918 919 restoreDefault() { 920 __JSScopeUtil__.syncInstanceId(this.instanceId_); 921 cursorControl.restoreDefault(); 922 __JSScopeUtil__.restoreInstanceId(); 923 } 924 925 setCursor(value) { 926 __JSScopeUtil__.syncInstanceId(this.instanceId_); 927 cursorControl.setCursor(value); 928 __JSScopeUtil__.restoreInstanceId(); 929 } 930} 931 932class ContextMenuController { 933 /** 934 * Construct new instance of ContextMenuController. 935 * initialzie with instanceId. 936 * @param instanceId obtained on the c++ side. 937 * @since 12 938 */ 939 constructor(instanceId) { 940 this.instanceId_ = instanceId; 941 } 942 943 close() { 944 __JSScopeUtil__.syncInstanceId(this.instanceId_); 945 ContextMenu.close(); 946 __JSScopeUtil__.restoreInstanceId(); 947 } 948} 949 950class ComponentUtils { 951 /** 952 * Construct new instance of ComponentUtils. 953 * initialize with instanceId. 954 * @param instanceId obtained on the c++ side. 955 * @since 10 956 */ 957 constructor(instanceId) { 958 this.instanceId_ = instanceId; 959 this.ohos_componentUtils = globalThis.requireNapi('arkui.componentUtils'); 960 } 961 getRectangleById(id) { 962 __JSScopeUtil__.syncInstanceId(this.instanceId_); 963 if (typeof this.ohos_componentUtils.getRectangleById !== 'function') { 964 throw Error('getRectangleById is not callable'); 965 } 966 let componentInformation = this.ohos_componentUtils?.getRectangleById?.(id); 967 __JSScopeUtil__.restoreInstanceId(); 968 return componentInformation; 969 } 970} 971 972class Router { 973 /** 974 * Construct new instance of Font. 975 * initialize with instanceId. 976 * @param instanceId obtained on the c++ side. 977 * @since 10 978 */ 979 constructor(instanceId) { 980 this.instanceId_ = instanceId; 981 this.ohos_router = globalThis.requireNapi('router'); 982 } 983 984 pushUrl(options, modeOrCallback, callback) { 985 __JSScopeUtil__.syncInstanceId(this.instanceId_); 986 if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') { 987 let promise = this.ohos_router.pushUrl(options); 988 __JSScopeUtil__.restoreInstanceId(); 989 return promise; 990 } 991 else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') { 992 this.ohos_router.pushUrl(options, modeOrCallback, callback); 993 __JSScopeUtil__.restoreInstanceId(); 994 } 995 else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') { 996 let promise = this.ohos_router.pushUrl(options, modeOrCallback); 997 __JSScopeUtil__.restoreInstanceId(); 998 if (promise) { 999 return promise; 1000 } 1001 } 1002 } 1003 1004 replaceUrl(options, modeOrCallback, callback) { 1005 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1006 if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') { 1007 let promise = this.ohos_router.replaceUrl(options); 1008 __JSScopeUtil__.restoreInstanceId(); 1009 return promise; 1010 } 1011 else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') { 1012 this.ohos_router.replaceUrl(options, modeOrCallback, callback); 1013 __JSScopeUtil__.restoreInstanceId(); 1014 } 1015 else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') { 1016 let promise = this.ohos_router.replaceUrl(options, modeOrCallback); 1017 __JSScopeUtil__.restoreInstanceId(); 1018 if (promise) { 1019 return promise; 1020 } 1021 } 1022 } 1023 1024 back(options, params) { 1025 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1026 if (typeof options === 'number' || arguments.length === 2) { 1027 this.ohos_router.back(options, params); 1028 } else { 1029 this.ohos_router.back(options); 1030 } 1031 __JSScopeUtil__.restoreInstanceId(); 1032 } 1033 1034 clear() { 1035 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1036 this.ohos_router.clear(); 1037 __JSScopeUtil__.restoreInstanceId(); 1038 } 1039 1040 getLength() { 1041 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1042 let result = this.ohos_router.getLength(); 1043 __JSScopeUtil__.restoreInstanceId(); 1044 return result; 1045 } 1046 1047 getState() { 1048 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1049 let state = this.ohos_router.getState(); 1050 __JSScopeUtil__.restoreInstanceId(); 1051 return state; 1052 } 1053 1054 getStateByIndex(index) { 1055 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1056 let state = this.ohos_router.getStateByIndex(index); 1057 __JSScopeUtil__.restoreInstanceId(); 1058 return state; 1059 } 1060 1061 getStateByUrl(url) { 1062 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1063 let state = this.ohos_router.getStateByUrl(url); 1064 __JSScopeUtil__.restoreInstanceId(); 1065 return state; 1066 } 1067 1068 showAlertBeforeBackPage(options) { 1069 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1070 this.ohos_router.showAlertBeforeBackPage(options); 1071 __JSScopeUtil__.restoreInstanceId(); 1072 } 1073 1074 hideAlertBeforeBackPage() { 1075 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1076 this.ohos_router.hideAlertBeforeBackPage(); 1077 __JSScopeUtil__.restoreInstanceId(); 1078 } 1079 1080 getParams() { 1081 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1082 let object = this.ohos_router.getParams(); 1083 __JSScopeUtil__.restoreInstanceId(); 1084 return object; 1085 } 1086 1087 pushNamedRoute(options, modeOrCallback, callback) { 1088 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1089 if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') { 1090 let promise = this.ohos_router.pushNamedRoute(options); 1091 __JSScopeUtil__.restoreInstanceId(); 1092 return promise; 1093 } 1094 else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') { 1095 this.ohos_router.pushNamedRoute(options, modeOrCallback, callback); 1096 __JSScopeUtil__.restoreInstanceId(); 1097 } 1098 else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') { 1099 let promise = this.ohos_router.pushNamedRoute(options, modeOrCallback); 1100 __JSScopeUtil__.restoreInstanceId(); 1101 if (promise) { 1102 return promise; 1103 } 1104 } 1105 } 1106 1107 replaceNamedRoute(options, modeOrCallback, callback) { 1108 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1109 if (typeof callback === 'undefined' && typeof modeOrCallback === 'undefined') { 1110 let promise = this.ohos_router.replaceNamedRoute(options); 1111 __JSScopeUtil__.restoreInstanceId(); 1112 return promise; 1113 } 1114 else if (typeof callback !== 'undefined' && typeof modeOrCallback !== 'undefined') { 1115 this.ohos_router.replaceNamedRoute(options, modeOrCallback, callback); 1116 __JSScopeUtil__.restoreInstanceId(); 1117 } 1118 else if (typeof callback === 'undefined' && typeof modeOrCallback !== 'undefined') { 1119 let promise = this.ohos_router.replaceNamedRoute(options, modeOrCallback); 1120 __JSScopeUtil__.restoreInstanceId(); 1121 if (promise) { 1122 return promise; 1123 } 1124 } 1125 } 1126} 1127 1128class PromptAction { 1129 /** 1130 * Construct new instance of PromptAction. 1131 * initialize with instanceId. 1132 * @param instanceId obtained on the c++ side. 1133 * @since 10 1134 */ 1135 constructor(instanceId) { 1136 this.instanceId_ = instanceId; 1137 this.ohos_prompt = globalThis.requireNapi('promptAction'); 1138 } 1139 1140 showToast(options) { 1141 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1142 this.ohos_prompt.showToast(options); 1143 __JSScopeUtil__.restoreInstanceId(); 1144 } 1145 1146 showDialog(options, callback) { 1147 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1148 if (typeof callback !== 'undefined') { 1149 this.ohos_prompt.showDialog(options, callback); 1150 __JSScopeUtil__.restoreInstanceId(); 1151 } 1152 else { 1153 let showDialogSuccessResponse = this.ohos_prompt.showDialog(options); 1154 __JSScopeUtil__.restoreInstanceId(); 1155 return showDialogSuccessResponse; 1156 } 1157 } 1158 1159 openCustomDialog(content, options) { 1160 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1161 if (arguments.length === 2) { 1162 let result_ = this.ohos_prompt.openCustomDialog(content.getFrameNode(), options); 1163 __JSScopeUtil__.restoreInstanceId(); 1164 return result_; 1165 } 1166 else { 1167 if (content.builderNode_ === undefined) { 1168 let result_ = this.ohos_prompt.openCustomDialog(content); 1169 __JSScopeUtil__.restoreInstanceId(); 1170 return result_; 1171 } 1172 else { 1173 let result_ = this.ohos_prompt.openCustomDialog(content.getFrameNode()); 1174 __JSScopeUtil__.restoreInstanceId(); 1175 return result_; 1176 } 1177 } 1178 } 1179 1180 updateCustomDialog(content, options) { 1181 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1182 let result_ = this.ohos_prompt.updateCustomDialog(content.getFrameNode(), options); 1183 __JSScopeUtil__.restoreInstanceId(); 1184 return result_; 1185 } 1186 1187 closeCustomDialog(content) { 1188 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1189 if (typeof content === 'number') { 1190 this.ohos_prompt.closeCustomDialog(content); 1191 __JSScopeUtil__.restoreInstanceId(); 1192 } 1193 else { 1194 let result_ = this.ohos_prompt.closeCustomDialog(content.getFrameNode()); 1195 __JSScopeUtil__.restoreInstanceId(); 1196 return result_; 1197 } 1198 } 1199 1200 showActionMenu(options, callback) { 1201 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1202 if (typeof callback !== 'undefined') { 1203 this.ohos_prompt.showActionMenu(options, callback); 1204 __JSScopeUtil__.restoreInstanceId(); 1205 } 1206 else { 1207 let actionMenuSuccessResponse = this.ohos_prompt.showActionMenu(options); 1208 __JSScopeUtil__.restoreInstanceId(); 1209 return actionMenuSuccessResponse; 1210 } 1211 } 1212} 1213 1214class AtomicServiceBar { 1215 /** 1216 * Construct new instance of AtomicServiceBar. 1217 * initialize with instanceId. 1218 * @param instanceId obtained on the c++ side. 1219 * @since 11 1220 */ 1221 constructor(instanceId) { 1222 this.instanceId_ = instanceId; 1223 this.ohos_atomicServiceBar = globalThis.requireNapi('atomicservicebar'); 1224 } 1225 1226 setVisible(visible) { 1227 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1228 this.ohos_atomicServiceBar.setVisible(visible); 1229 __JSScopeUtil__.restoreInstanceId(); 1230 } 1231 1232 setBackgroundColor(color) { 1233 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1234 this.ohos_atomicServiceBar.setBackgroundColor(color); 1235 __JSScopeUtil__.restoreInstanceId(); 1236 } 1237 1238 setTitleContent(content) { 1239 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1240 this.ohos_atomicServiceBar.setTitleContent(content); 1241 __JSScopeUtil__.restoreInstanceId(); 1242 } 1243 1244 setTitleFontStyle(font) { 1245 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1246 this.ohos_atomicServiceBar.setTitleFontStyle(font); 1247 __JSScopeUtil__.restoreInstanceId(); 1248 } 1249 1250 setIconColor(color) { 1251 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1252 this.ohos_atomicServiceBar.setIconColor(color); 1253 __JSScopeUtil__.restoreInstanceId(); 1254 } 1255 1256 getBarRect() { 1257 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1258 let rect = this.ohos_atomicServiceBar.getBarRect(); 1259 __JSScopeUtil__.restoreInstanceId(); 1260 return rect; 1261 } 1262} 1263 1264class OverlayManager { 1265 /** 1266 * Construct new instance of Overlay. 1267 * initialize with instanceId. 1268 * @param instanceId obtained on the c++ side. 1269 * @since 12 1270 */ 1271 constructor(instanceId) { 1272 this.instanceId_ = instanceId; 1273 this.ohos_overlayManager = globalThis.requireNapi('overlay'); 1274 } 1275 1276 setOverlayManagerOptions(options) { 1277 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1278 let res = this.ohos_overlayManager.setOverlayManagerOptions(options); 1279 __JSScopeUtil__.restoreInstanceId(); 1280 return res; 1281 } 1282 1283 getOverlayManagerOptions() { 1284 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1285 let res = this.ohos_overlayManager.getOverlayManagerOptions(); 1286 __JSScopeUtil__.restoreInstanceId(); 1287 return res; 1288 } 1289 1290 addComponentContent(content, index) { 1291 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1292 if (typeof index !== 'undefined') { 1293 this.ohos_overlayManager.addFrameNode(content.getFrameNode(), index); 1294 } else { 1295 this.ohos_overlayManager.addFrameNode(content.getFrameNode()); 1296 } 1297 __JSScopeUtil__.restoreInstanceId(); 1298 } 1299 1300 removeComponentContent(content) { 1301 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1302 this.ohos_overlayManager.removeFrameNode(content.getFrameNode()); 1303 __JSScopeUtil__.restoreInstanceId(); 1304 } 1305 1306 showComponentContent(content) { 1307 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1308 this.ohos_overlayManager.showNode(content.getFrameNode()); 1309 __JSScopeUtil__.restoreInstanceId(); 1310 } 1311 1312 hideComponentContent(content) { 1313 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1314 this.ohos_overlayManager.hideNode(content.getFrameNode()); 1315 __JSScopeUtil__.restoreInstanceId(); 1316 } 1317 1318 showAllComponentContents() { 1319 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1320 this.ohos_overlayManager.showAllFrameNodes(); 1321 __JSScopeUtil__.restoreInstanceId(); 1322 } 1323 1324 hideAllComponentContents() { 1325 __JSScopeUtil__.syncInstanceId(this.instanceId_); 1326 this.ohos_overlayManager.hideAllFrameNodes(); 1327 __JSScopeUtil__.restoreInstanceId(); 1328 } 1329} 1330/** 1331 * Get UIContext instance. 1332 * @param instanceId obtained on the c++ side. 1333 * @returns UIContext instance. 1334 */ 1335function __getUIContext__(instanceId) { 1336 return new UIContext(instanceId); 1337} 1338 1339/** 1340 * Get FrameNode by id of UIContext instance. 1341 * @param instanceId obtained on the C++ side. 1342 * @param nodeId the id of frameNode. 1343 * @returns FrameNode instance. 1344 */ 1345function __getFrameNodeByNodeId__(instanceId, nodeId) { 1346 const uiContext = __getUIContext__(instanceId); 1347 return uiContext.getFrameNodeByNodeId(nodeId); 1348} 1349 1350/** 1351 * check regex valid 1352 * @param pattern regex string 1353 * @returns valid result 1354 */ 1355function __checkRegexValid__(pattern) { 1356 let result = true; 1357 try { 1358 new RegExp(pattern); 1359 } catch (error) { 1360 result = false; 1361 } finally { 1362 return result; 1363 } 1364}