1/* 2 * Copyright (c) 2023-2025 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 16const display = requireNapi('display'); 17const hilog = requireNapi('hilog'); 18const measure = requireNapi('measure'); 19const resourceManager = requireNapi('resourceManager'); 20const LengthMetrics = requireNapi('arkui.node').LengthMetrics; 21const LengthUnit = requireNapi('arkui.node').LengthUnit; 22const accessibility = requireNapi('accessibility'); 23const KeyCode = requireNapi('multimodalInput.keyCode').KeyCode; 24const i18n = requireNapi('i18n') 25 26if (!('finalizeConstruction' in ViewPU.prototype)) { 27 Reflect.set(ViewPU.prototype, 'finalizeConstruction', () => { 28 }); 29} 30 31class CustomThemeImpl { 32 constructor(colors) { 33 this.colors = colors; 34 } 35} 36 37const TITLE_MAX_LINES = 2; 38const HORIZON_BUTTON_MAX_COUNT = 2; 39const VERTICAL_BUTTON_MAX_COUNT = 4; 40const BUTTON_LAYOUT_WEIGHT = 1; 41const CONTENT_MAX_LINES = 2; 42const LOADING_PROGRESS_WIDTH = 40; 43const LOADING_PROGRESS_HEIGHT = 40; 44const LOADING_MAX_LINES = 10; 45const LOADING_MAX_LINES_BIG_FONT = 4; 46const LOADING_TEXT_LAYOUT_WEIGHT = 1; 47const LOADING_TEXT_MARGIN_LEFT = 12; 48const LOADING_MIN_HEIGHT = 48; 49const LIST_MIN_HEIGHT = 48; 50const CHECKBOX_CONTAINER_LENGTH = 20; 51const TEXT_MIN_HEIGHT = 48; 52const MIN_CONTENT_HEIGHT = 100; 53const MAX_CONTENT_HEIGHT = 30000; 54const KEYCODE_UP = 2012; 55const KEYCODE_DOWN = 2013; 56const IGNORE_KEY_EVENT_TYPE = 1; 57const FIRST_ITEM_INDEX = 0; 58const VERSION_TWELVE = 50000012; 59const MAX_FONT_SCALE = 2; 60const FADEOUT_GRADIENT_WIDTH = 32; 61const FADEOUT_ENABLE = 'true'; 62// 'sys.float.alert_container_max_width' 63const MAX_DIALOG_WIDTH = getNumberByResourceId(125831042, 400); 64// 'sys.float.alert_right_padding_horizontal' 65const BUTTON_HORIZONTAL_MARGIN = getNumberByResourceId(125831054, 16); 66// 'sys.float.padding_level8' 67const BUTTON_HORIZONTAL_PADDING = getNumberByResourceId(125830927, 16); 68// 'sys.float.alert_button_horizontal_space' 69const BUTTON_HORIZONTAL_SPACE = getNumberByResourceId(125831051, 8); 70// 'sys.float.Body_L' 71const BODY_L = getNumberByResourceId(125830970, 16); 72// 'sys.float.Body_M' 73const BODY_M = getNumberByResourceId(125830971, 14); 74// 'sys.float.Body_S' 75const BODY_S = getNumberByResourceId(125830972, 12); 76// 'sys.float.Title_S' 77const TITLE_S = getNumberByResourceId(125830966, 20); 78// 'sys.float.padding_level8' 79const PADDING_LEVEL_8 = getNumberByResourceId(125830927, 16); 80const BUTTON_MIN_FONT_SIZE = lazyInit(() => { 81 return getLengthMetricsByResource({ 82 'id': -1, 83 'type': 10002, 84 params: ['sys.float.dialog_button_font_min_size'], 85 'bundleName': '__harDefaultBundleName__', 86 'moduleName': '__harDefaultModuleName__' 87 }, 9); 88}); 89const BUTTON_MAX_FONT_SIZE = lazyInit(() => { 90 return getLengthMetricsByResource({ 91 'id': -1, 92 'type': 10002, 93 params: ['sys.float.dialog_button_font_max_size'], 94 'bundleName': '__harDefaultBundleName__', 95 'moduleName': '__harDefaultModuleName__' 96 }, 16); 97}); 98const DEFAULT_IMAGE_SIZE = lazyInit(() => { 99 return getLengthMetricsByResource({ 100 'id': -1, 101 'type': 10002, 102 params: ['sys.float.dialog_tip_image_size'], 103 'bundleName': '__harDefaultBundleName__', 104 'moduleName': '__harDefaultModuleName__' 105 }, 64); 106}); 107const DEFAULT_IMAGE_RADIUS = lazyInit(() => { 108 return getLengthMetricsByResource({ 109 'id': -1, 110 'type': 10002, 111 params: ['sys.float.dialog_tip_image_radius'], 112 'bundleName': '__harDefaultBundleName__', 113 'moduleName': '__harDefaultModuleName__' 114 }, 12); 115}); 116const TIP_TEXT_TOP_PADDING = lazyInit(() => { 117 return getLengthMetricsByResource({ 118 'id': -1, 119 'type': 10002, 120 params: ['sys.float.dialog_tip_text_top_padding'], 121 'bundleName': '__harDefaultBundleName__', 122 'moduleName': '__harDefaultModuleName__' 123 }, 16); 124}); 125const TIP_CHECKBOX_TOP_PADDING = lazyInit(() => { 126 return getLengthMetricsByResource({ 127 'id': -1, 128 'type': 10002, 129 params: ['sys.float.dialog_checkbox_top_padding'], 130 'bundleName': '__harDefaultBundleName__', 131 'moduleName': '__harDefaultModuleName__' 132 }, 8); 133}); 134const TIP_CHECKBOX_BOTTOM_PADDING = lazyInit(() => { 135 return getLengthMetricsByResource({ 136 'id': -1, 137 'type': 10002, 138 params: ['sys.float.dialog_checkbox_bottom_padding'], 139 'bundleName': '__harDefaultBundleName__', 140 'moduleName': '__harDefaultModuleName__' 141 }, 8, true); 142}); 143const TIP_CHECKBOX_END_MARGIN = lazyInit(() => { 144 return getLengthMetricsByResource({ 145 'id': -1, 146 'type': 10002, 147 params: ['sys.float.dialog_checkbox_end_margin'], 148 'bundleName': '__harDefaultBundleName__', 149 'moduleName': '__harDefaultModuleName__' 150 }, 8); 151}); 152const SUBTITLE_SIZE = lazyInit(() => { 153 return getLengthMetricsByResource({ 154 'id': -1, 155 'type': 10002, 156 params: ['sys.float.dialog_subtitle_font_size'], 157 'bundleName': '__harDefaultBundleName__', 158 'moduleName': '__harDefaultModuleName__' 159 }, 14); 160}); 161const CHECKBOX_CONTAINER_HEIGHT = lazyInit(() => { 162 return getLengthMetricsByResource({ 163 'id': -1, 164 'type': 10002, 165 params: ['sys.float.dialog_checkbox_min_height'], 166 'bundleName': '__harDefaultBundleName__', 167 'moduleName': '__harDefaultModuleName__' 168 }, 48, true); 169}); 170const CONTENT_END_MARGIN = lazyInit(() => { 171 return getLengthMetricsByResource({ 172 'id': -1, 173 'type': 10002, 174 params: ['sys.float.dialog_content_right_margin'], 175 'bundleName': '__harDefaultBundleName__', 176 'moduleName': '__harDefaultModuleName__' 177 }, 16); 178}); 179const SCROLL_END_MARGIN = lazyInit(() => { 180 return getLengthMetricsByResource({ 181 'id': -1, 182 'type': 10002, 183 params: ['sys.float.dialog_scroll_right_margin'], 184 'bundleName': '__harDefaultBundleName__', 185 'moduleName': '__harDefaultModuleName__' 186 }, 16); 187}); 188const DIALOG_DIVIDER_SHOW = lazyInit(() => { 189 return getLengthMetricsByResource({ 190 'id': -1, 191 'type': 10002, 192 params: ['sys.float.dialog_divider_show'], 193 'bundleName': '__harDefaultBundleName__', 194 'moduleName': '__harDefaultModuleName__' 195 }, 1, true); 196}); 197const ALERT_BUTTON_STYLE = lazyInit(() => { 198 return getLengthMetricsByResource({ 199 'id': -1, 200 'type': 10002, 201 params: ['sys.float.alert_button_style'], 202 'bundleName': '__harDefaultBundleName__', 203 'moduleName': '__harDefaultModuleName__' 204 }, 2, true); 205}); 206const ALERT_TITLE_ALIGNMENT = lazyInit(() => { 207 return getLengthMetricsByResource({ 208 'id': -1, 209 'type': 10002, 210 params: ['sys.float.alert_title_alignment'], 211 'bundleName': '__harDefaultBundleName__', 212 'moduleName': '__harDefaultModuleName__' 213 }, 1); 214}); 215const ERROR_BUTTON_STYLE = lazyInit(() => { 216 return getLengthMetricsByResource({ 217 'id': -1, 218 'type': 10002, 219 params: ['sys.float.dialog_error_button_style'], 220 'bundleName': '__harDefaultBundleName__', 221 'moduleName': '__harDefaultModuleName__' 222 }, 2, true); 223}); 224// 'sys.string.ohos_id_text_fadeout_enable_default' 225const IS_FADEOUT_ENABLE = lazyInit(() => { 226 return getString(125831120) === FADEOUT_ENABLE; 227}); 228// 'sys.string.dialog_title_font_weight' 229const TITLE_FONT_WEIGHT = lazyInit(() => { 230 let fontWeight = FontWeight[getString(125834679) || 'Bold']; 231 return fontWeight; 232}); 233// 'sys.string.dialog_content_font_weight' 234const CONTENT_FONT_WEIGHT = lazyInit(() => { 235 let fontWeight = FontWeight[getString(125834682) || 'Medium']; 236 return fontWeight; 237}); 238const SCROLL_BAR_OFFSET = 20; 239 240export class TipsDialog extends ViewPU { 241 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 242 super(parent, __localStorage, elmtId, extraInfo); 243 if (typeof paramsLambda === 'function') { 244 this.paramsGenerator_ = paramsLambda; 245 } 246 this.controller = undefined; 247 this.imageRes = null; 248 this.__imageSize = 249 new ObservedPropertyObjectPU({ width: DEFAULT_IMAGE_SIZE(), height: DEFAULT_IMAGE_SIZE() }, this, 250 'imageSize'); 251 this.title = null; 252 this.content = null; 253 this.checkAction = undefined; 254 this.onCheckedChange = undefined; 255 this.checkTips = null; 256 this.__isChecked = new ObservedPropertySimplePU(false, this, 'isChecked'); 257 this.primaryButton = null; 258 this.secondaryButton = null; 259 this.buttons = undefined; 260 this.__textAlignment = new ObservedPropertySimplePU(TextAlign.Start, this, 'textAlignment'); 261 this.marginOffset = 0; 262 this.contentScroller = new Scroller(); 263 this.__fontColorWithTheme = new ObservedPropertyObjectPU({ 264 'id': -1, 265 'type': 10001, 266 params: ['sys.color.font_primary'], 267 'bundleName': '__harDefaultBundleName__', 268 'moduleName': '__harDefaultModuleName__' 269 }, this, 'fontColorWithTheme'); 270 this.theme = new CustomThemeImpl({}); 271 this.themeColorMode = ThemeColorMode.SYSTEM; 272 this.__fontSizeScale = new ObservedPropertySimplePU(1, this, 'fontSizeScale'); 273 this.__minContentHeight = new ObservedPropertySimplePU(160, this, 'minContentHeight'); 274 this.updateTextAlign = (maxWidth) => { 275 if (this.content) { 276 this.textAlignment = getTextAlign(maxWidth, this.content, `${BODY_L * this.fontSizeScale}vp`); 277 } 278 }; 279 this.imageIndex = 0; 280 this.textIndex = 1; 281 this.checkBoxIndex = 2; 282 this.appMaxFontScale = 3.2; 283 this.setInitiallyProvidedValue(params); 284 this.finalizeConstruction(); 285 } 286 287 setInitiallyProvidedValue(params) { 288 if (params.controller !== undefined) { 289 this.controller = params.controller; 290 } 291 if (params.imageRes !== undefined) { 292 this.imageRes = params.imageRes; 293 } 294 if (params.imageSize !== undefined) { 295 this.imageSize = params.imageSize; 296 } 297 if (params.title !== undefined) { 298 this.title = params.title; 299 } 300 if (params.content !== undefined) { 301 this.content = params.content; 302 } 303 if (params.checkAction !== undefined) { 304 this.checkAction = params.checkAction; 305 } 306 if (params.onCheckedChange !== undefined) { 307 this.onCheckedChange = params.onCheckedChange; 308 } 309 if (params.checkTips !== undefined) { 310 this.checkTips = params.checkTips; 311 } 312 if (params.isChecked !== undefined) { 313 this.isChecked = params.isChecked; 314 } 315 if (params.primaryButton !== undefined) { 316 this.primaryButton = params.primaryButton; 317 } 318 if (params.secondaryButton !== undefined) { 319 this.secondaryButton = params.secondaryButton; 320 } 321 if (params.buttons !== undefined) { 322 this.buttons = params.buttons; 323 } 324 if (params.textAlignment !== undefined) { 325 this.textAlignment = params.textAlignment; 326 } 327 if (params.marginOffset !== undefined) { 328 this.marginOffset = params.marginOffset; 329 } 330 if (params.contentScroller !== undefined) { 331 this.contentScroller = params.contentScroller; 332 } 333 if (params.fontColorWithTheme !== undefined) { 334 this.fontColorWithTheme = params.fontColorWithTheme; 335 } 336 if (params.theme !== undefined) { 337 this.theme = params.theme; 338 } 339 if (params.themeColorMode !== undefined) { 340 this.themeColorMode = params.themeColorMode; 341 } 342 if (params.fontSizeScale !== undefined) { 343 this.fontSizeScale = params.fontSizeScale; 344 } 345 if (params.minContentHeight !== undefined) { 346 this.minContentHeight = params.minContentHeight; 347 } 348 if (params.updateTextAlign !== undefined) { 349 this.updateTextAlign = params.updateTextAlign; 350 } 351 if (params.imageIndex !== undefined) { 352 this.imageIndex = params.imageIndex; 353 } 354 if (params.textIndex !== undefined) { 355 this.textIndex = params.textIndex; 356 } 357 if (params.checkBoxIndex !== undefined) { 358 this.checkBoxIndex = params.checkBoxIndex; 359 } 360 if (params.appMaxFontScale !== undefined) { 361 this.appMaxFontScale = params.appMaxFontScale; 362 } 363 } 364 365 updateStateVars(params) { 366 } 367 368 purgeVariableDependenciesOnElmtId(rmElmtId) { 369 this.__imageSize.purgeDependencyOnElmtId(rmElmtId); 370 this.__isChecked.purgeDependencyOnElmtId(rmElmtId); 371 this.__textAlignment.purgeDependencyOnElmtId(rmElmtId); 372 this.__fontColorWithTheme.purgeDependencyOnElmtId(rmElmtId); 373 this.__fontSizeScale.purgeDependencyOnElmtId(rmElmtId); 374 this.__minContentHeight.purgeDependencyOnElmtId(rmElmtId); 375 } 376 377 aboutToBeDeleted() { 378 this.__imageSize.aboutToBeDeleted(); 379 this.__isChecked.aboutToBeDeleted(); 380 this.__textAlignment.aboutToBeDeleted(); 381 this.__fontColorWithTheme.aboutToBeDeleted(); 382 this.__fontSizeScale.aboutToBeDeleted(); 383 this.__minContentHeight.aboutToBeDeleted(); 384 SubscriberManager.Get().delete(this.id__()); 385 this.aboutToBeDeletedInternal(); 386 } 387 388 setController(ctr) { 389 this.controller = ctr; 390 } 391 392 get imageSize() { 393 return this.__imageSize.get(); 394 } 395 396 set imageSize(newValue) { 397 this.__imageSize.set(newValue); 398 } 399 400 get isChecked() { 401 return this.__isChecked.get(); 402 } 403 404 set isChecked(newValue) { 405 this.__isChecked.set(newValue); 406 } 407 408 get textAlignment() { 409 return this.__textAlignment.get(); 410 } 411 412 set textAlignment(newValue) { 413 this.__textAlignment.set(newValue); 414 } 415 416 get fontColorWithTheme() { 417 return this.__fontColorWithTheme.get(); 418 } 419 420 set fontColorWithTheme(newValue) { 421 this.__fontColorWithTheme.set(newValue); 422 } 423 424 get fontSizeScale() { 425 return this.__fontSizeScale.get(); 426 } 427 428 set fontSizeScale(newValue) { 429 this.__fontSizeScale.set(newValue); 430 } 431 432 get minContentHeight() { 433 return this.__minContentHeight.get(); 434 } 435 436 set minContentHeight(newValue) { 437 this.__minContentHeight.set(newValue); 438 } 439 440 initialRender() { 441 this.observeComponentCreation2((elmtId, isInitialRender) => { 442 __Common__.create(); 443 __Common__.constraintSize({ maxHeight: '100%' }); 444 }, __Common__); 445 { 446 this.observeComponentCreation2((elmtId, isInitialRender) => { 447 if (isInitialRender) { 448 let componentCall = new CustomDialogContentComponent(this, { 449 controller: this.controller, 450 contentBuilder: () => { 451 this.contentBuilder(); 452 }, 453 buttons: this.buttons, 454 theme: this.theme, 455 themeColorMode: this.themeColorMode, 456 fontSizeScale: this.__fontSizeScale, 457 minContentHeight: this.__minContentHeight, 458 }, undefined, elmtId, () => { 459 }, { page: 'library/src/main/ets/components/dialog.ets', line: 180, col: 5 }); 460 ViewPU.create(componentCall); 461 let paramsLambda = () => { 462 return { 463 controller: this.controller, 464 contentBuilder: () => { 465 this.contentBuilder(); 466 }, 467 buttons: this.buttons, 468 theme: this.theme, 469 themeColorMode: this.themeColorMode, 470 fontSizeScale: this.fontSizeScale, 471 minContentHeight: this.minContentHeight 472 }; 473 }; 474 componentCall.paramsGenerator_ = paramsLambda; 475 } else { 476 this.updateStateVarsOfChildByElmtId(elmtId, {}); 477 } 478 }, { name: 'CustomDialogContentComponent' }); 479 } 480 __Common__.pop(); 481 } 482 483 contentBuilder(parent = null) { 484 { 485 this.observeComponentCreation2((elmtId, isInitialRender) => { 486 if (isInitialRender) { 487 let componentCall = new TipsDialogContentLayout(this, { 488 title: this.title, 489 content: this.content, 490 checkTips: this.checkTips, 491 minContentHeight: this.__minContentHeight, 492 updateTextAlign: this.updateTextAlign, 493 dialogBuilder: () => { 494 this.observeComponentCreation2((elmtId, isInitialRender) => { 495 ForEach.create(); 496 const forEachItemGenFunction = _item => { 497 const index = _item; 498 this.observeComponentCreation2((elmtId, isInitialRender) => { 499 If.create(); 500 if (index === this.imageIndex) { 501 this.ifElseBranchUpdateFunction(0, () => { 502 this.imagePart.bind(this)(); 503 }); 504 } else if (index === this.textIndex) { 505 this.ifElseBranchUpdateFunction(1, () => { 506 this.observeComponentCreation2((elmtId, isInitialRender) => { 507 Column.create(); 508 Column.padding({ top: TIP_TEXT_TOP_PADDING() }); 509 }, Column); 510 this.observeComponentCreation2((elmtId, isInitialRender) => { 511 WithTheme.create({ 512 theme: this.theme, 513 colorMode: this.themeColorMode 514 }); 515 }, WithTheme); 516 this.textPart.bind(this)(); 517 WithTheme.pop(); 518 Column.pop(); 519 }); 520 } else { 521 this.ifElseBranchUpdateFunction(2, () => { 522 this.observeComponentCreation2((elmtId, isInitialRender) => { 523 WithTheme.create({ 524 theme: this.theme, 525 colorMode: this.themeColorMode 526 }); 527 }, WithTheme); 528 this.checkBoxPart.bind(this)(); 529 WithTheme.pop(); 530 }); 531 } 532 }, If); 533 If.pop(); 534 }; 535 this.forEachUpdateFunction(elmtId, 536 [this.imageIndex, this.textIndex, this.checkBoxIndex], forEachItemGenFunction); 537 }, ForEach); 538 ForEach.pop(); 539 } 540 }, undefined, elmtId, () => { 541 }, { page: 'library/src/main/ets/components/dialog.ets', line: 195, col: 5 }); 542 ViewPU.create(componentCall); 543 let paramsLambda = () => { 544 return { 545 title: this.title, 546 content: this.content, 547 checkTips: this.checkTips, 548 minContentHeight: this.minContentHeight, 549 updateTextAlign: this.updateTextAlign, 550 dialogBuilder: () => { 551 this.observeComponentCreation2((elmtId, isInitialRender) => { 552 ForEach.create(); 553 const forEachItemGenFunction = _item => { 554 const index = _item; 555 this.observeComponentCreation2((elmtId, isInitialRender) => { 556 If.create(); 557 if (index === this.imageIndex) { 558 this.ifElseBranchUpdateFunction(0, () => { 559 this.imagePart.bind(this)(); 560 }); 561 } else if (index === this.textIndex) { 562 this.ifElseBranchUpdateFunction(1, () => { 563 this.observeComponentCreation2((elmtId, isInitialRender) => { 564 Column.create(); 565 Column.padding({ top: TIP_TEXT_TOP_PADDING() }); 566 }, Column); 567 this.observeComponentCreation2((elmtId, isInitialRender) => { 568 WithTheme.create({ 569 theme: this.theme, 570 colorMode: this.themeColorMode 571 }); 572 }, WithTheme); 573 this.textPart.bind(this)(); 574 WithTheme.pop(); 575 Column.pop(); 576 }); 577 } else { 578 this.ifElseBranchUpdateFunction(2, () => { 579 this.observeComponentCreation2((elmtId, isInitialRender) => { 580 WithTheme.create({ 581 theme: this.theme, 582 colorMode: this.themeColorMode 583 }); 584 }, WithTheme); 585 this.checkBoxPart.bind(this)(); 586 WithTheme.pop(); 587 }); 588 } 589 }, If); 590 If.pop(); 591 }; 592 this.forEachUpdateFunction(elmtId, 593 [this.imageIndex, this.textIndex, this.checkBoxIndex], forEachItemGenFunction); 594 }, ForEach); 595 ForEach.pop(); 596 } 597 }; 598 }; 599 componentCall.paramsGenerator_ = paramsLambda; 600 } else { 601 this.updateStateVarsOfChildByElmtId(elmtId, {}); 602 } 603 }, { name: 'TipsDialogContentLayout' }); 604 } 605 } 606 607 checkBoxPart(parent = null) { 608 this.observeComponentCreation2((elmtId, isInitialRender) => { 609 Row.create(); 610 Row.accessibilityGroup(true); 611 Row.accessibilityText(getCheckTipsAccessibilityText(this.checkTips, this.isChecked)); 612 Row.accessibilityDescription(this.isChecked ? { 613 'id': -1, 614 'type': 10003, 615 params: ['sys.string.advanced_dialog_accessibility_cancel_checked_desc'], 616 'bundleName': '__harDefaultBundleName__', 617 'moduleName': '__harDefaultModuleName__' 618 } : { 619 'id': -1, 620 'type': 10003, 621 params: ['sys.string.slider_accessibility_unselectedDesc'], 622 'bundleName': '__harDefaultBundleName__', 623 'moduleName': '__harDefaultModuleName__' 624 }); 625 Row.onClick(() => { 626 this.isChecked = !this.isChecked; 627 if (this.checkAction) { 628 this.checkAction(this.isChecked); 629 } 630 try { 631 let eventInfo = ({ 632 type: 'announceForAccessibility', 633 bundleName: getContext()?.abilityInfo?.bundleName, 634 triggerAction: 'common', 635 textAnnouncedForAccessibility: this.isChecked ? 636 getContext().resourceManager.getStringSync(125833934) : 637 getContext().resourceManager.getStringSync(125833935) 638 }); 639 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 640 console.info(`Accessibility send event`); 641 }); 642 } catch (exception) { 643 let code = exception.code; 644 let message = exception.message; 645 hilog.error(0x3900, 'Ace', `Faild to send event, cause, code: ${code}, message: ${message}`); 646 } 647 }); 648 Row.padding({ top: TIP_CHECKBOX_TOP_PADDING(), bottom: TIP_CHECKBOX_BOTTOM_PADDING() }); 649 Row.constraintSize({ minHeight: CHECKBOX_CONTAINER_HEIGHT() }); 650 Row.width('100%'); 651 }, Row); 652 this.observeComponentCreation2((elmtId, isInitialRender) => { 653 If.create(); 654 if (this.checkTips !== null) { 655 this.ifElseBranchUpdateFunction(0, () => { 656 this.observeComponentCreation2((elmtId, isInitialRender) => { 657 Checkbox.create({ name: '', group: 'checkboxGroup' }); 658 Checkbox.select(this.isChecked); 659 Checkbox.onChange((checked) => { 660 this.isChecked = checked; 661 if (this.checkAction) { 662 this.checkAction(checked); 663 } 664 if (this.onCheckedChange) { 665 this.onCheckedChange(checked); 666 } 667 }); 668 Checkbox.margin({ 669 start: LengthMetrics.vp(0), 670 end: LengthMetrics.vp(TIP_CHECKBOX_END_MARGIN()) 671 }); 672 }, Checkbox); 673 Checkbox.pop(); 674 this.observeComponentCreation2((elmtId, isInitialRender) => { 675 Text.create(this.checkTips); 676 Text.fontSize(`${BODY_L}fp`); 677 Text.fontWeight(FontWeight.Regular); 678 Text.fontColor(ObservedObject.GetRawObject(this.fontColorWithTheme)); 679 Text.maxLines(CONTENT_MAX_LINES); 680 Text.layoutWeight(1); 681 Text.focusable(false); 682 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 683 }, Text); 684 Text.pop(); 685 }); 686 } else { 687 this.ifElseBranchUpdateFunction(1, () => { 688 }); 689 } 690 }, If); 691 If.pop(); 692 Row.pop(); 693 } 694 695 imagePart(parent = null) { 696 this.observeComponentCreation2((elmtId, isInitialRender) => { 697 Column.create(); 698 Column.width('100%'); 699 }, Column); 700 this.observeComponentCreation2((elmtId, isInitialRender) => { 701 Image.create(this.imageRes); 702 Image.objectFit(ImageFit.Contain); 703 Image.borderRadius(DEFAULT_IMAGE_RADIUS()); 704 Image.constraintSize({ 705 maxWidth: this.imageSize?.width ?? DEFAULT_IMAGE_SIZE(), 706 maxHeight: this.imageSize?.height ?? DEFAULT_IMAGE_SIZE() 707 }); 708 }, Image); 709 Column.pop(); 710 } 711 712 textPart(parent = null) { 713 this.observeComponentCreation2((elmtId, isInitialRender) => { 714 Scroll.create(this.contentScroller); 715 Scroll.fadingEdge(IS_FADEOUT_ENABLE(), { fadingEdgeLength: LengthMetrics.vp(FADEOUT_GRADIENT_WIDTH) }); 716 Scroll.nestedScroll({ 717 scrollForward: NestedScrollMode.PARALLEL, 718 scrollBackward: NestedScrollMode.PARALLEL 719 }); 720 Scroll.margin({ end: LengthMetrics.vp(this.marginOffset) }); 721 }, Scroll); 722 this.observeComponentCreation2((elmtId, isInitialRender) => { 723 Column.create(); 724 Column.margin({ end: LengthMetrics.vp(CONTENT_END_MARGIN()) }); 725 }, Column); 726 this.observeComponentCreation2((elmtId, isInitialRender) => { 727 If.create(); 728 if (this.title !== null) { 729 this.ifElseBranchUpdateFunction(0, () => { 730 this.observeComponentCreation2((elmtId, isInitialRender) => { 731 Row.create(); 732 Row.padding({ 733 bottom: { 734 'id': -1, 735 'type': 10002, 736 params: ['sys.float.padding_level8'], 737 'bundleName': '__harDefaultBundleName__', 738 'moduleName': '__harDefaultModuleName__' 739 } 740 }); 741 }, Row); 742 this.observeComponentCreation2((elmtId, isInitialRender) => { 743 Text.create(this.title); 744 Text.fontSize(`${TITLE_S}fp`); 745 Text.maxFontScale(Math.min(this.appMaxFontScale, MAX_FONT_SCALE)); 746 Text.fontWeight(TITLE_FONT_WEIGHT()); 747 Text.fontColor(ObservedObject.GetRawObject(this.fontColorWithTheme)); 748 Text.textAlign(TextAlign.Center); 749 Text.maxLines(CONTENT_MAX_LINES); 750 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 751 Text.width('100%'); 752 }, Text); 753 Text.pop(); 754 Row.pop(); 755 }); 756 } else { 757 this.ifElseBranchUpdateFunction(1, () => { 758 }); 759 } 760 }, If); 761 If.pop(); 762 this.observeComponentCreation2((elmtId, isInitialRender) => { 763 If.create(); 764 if (this.content !== null) { 765 this.ifElseBranchUpdateFunction(0, () => { 766 this.observeComponentCreation2((elmtId, isInitialRender) => { 767 Row.create(); 768 }, Row); 769 this.observeComponentCreation2((elmtId, isInitialRender) => { 770 Text.create(this.content); 771 Text.focusable(true); 772 Text.defaultFocus(!(this.primaryButton || this.secondaryButton)); 773 Text.focusBox({ 774 strokeWidth: LengthMetrics.px(0) 775 }); 776 Text.fontSize(this.getContentFontSize()); 777 Text.fontWeight(CONTENT_FONT_WEIGHT()); 778 Text.fontColor(ObservedObject.GetRawObject(this.fontColorWithTheme)); 779 Text.textAlign(this.textAlignment); 780 Text.width('100%'); 781 Text.onKeyEvent((event) => { 782 if (event) { 783 resolveKeyEvent(event, this.contentScroller); 784 } 785 }); 786 }, Text); 787 Text.pop(); 788 Row.pop(); 789 }); 790 } else { 791 this.ifElseBranchUpdateFunction(1, () => { 792 }); 793 } 794 }, If); 795 If.pop(); 796 Column.pop(); 797 Scroll.pop(); 798 } 799 800 aboutToAppear() { 801 this.fontColorWithTheme = this.theme?.colors?.fontPrimary ? 802 this.theme.colors.fontPrimary : { 803 'id': -1, 804 'type': 10001, 805 params: ['sys.color.font_primary'], 806 'bundleName': '__harDefaultBundleName__', 807 'moduleName': '__harDefaultModuleName__' 808 }; 809 let uiContext = this.getUIContext(); 810 this.appMaxFontScale = uiContext.getMaxFontScale(); 811 this.initButtons(); 812 this.initMargin(); 813 } 814 815 getContentFontSize() { 816 return BODY_L + 'fp'; 817 } 818 819 initButtons() { 820 if (!this.primaryButton && !this.secondaryButton) { 821 return; 822 } 823 this.buttons = []; 824 if (this.primaryButton) { 825 this.buttons.push(this.primaryButton); 826 } 827 if (this.secondaryButton) { 828 this.buttons.push(this.secondaryButton); 829 } 830 } 831 832 initMargin() { 833 this.marginOffset = 0 - SCROLL_END_MARGIN(); 834 } 835 836 rerender() { 837 this.updateDirtyElements(); 838 } 839} 840 841class TipsDialogContentLayout extends ViewPU { 842 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 843 super(parent, __localStorage, elmtId, extraInfo); 844 if (typeof paramsLambda === 'function') { 845 this.paramsGenerator_ = paramsLambda; 846 } 847 this.title = null; 848 this.content = null; 849 this.checkTips = null; 850 this.updateTextAlign = (maxWidth) => { 851 }; 852 this.__minContentHeight = new SynchedPropertySimpleTwoWayPU(params.minContentHeight, this, 'minContentHeight'); 853 this.dialogBuilder = this.doNothingBuilder; 854 this.imageIndex = 0; 855 this.textIndex = 1; 856 this.checkBoxIndex = 2; 857 this.childrenSize = 3; 858 this.setInitiallyProvidedValue(params); 859 this.finalizeConstruction(); 860 } 861 862 setInitiallyProvidedValue(params) { 863 if (params.title !== undefined) { 864 this.title = params.title; 865 } 866 if (params.content !== undefined) { 867 this.content = params.content; 868 } 869 if (params.checkTips !== undefined) { 870 this.checkTips = params.checkTips; 871 } 872 if (params.updateTextAlign !== undefined) { 873 this.updateTextAlign = params.updateTextAlign; 874 } 875 if (params.dialogBuilder !== undefined) { 876 this.dialogBuilder = params.dialogBuilder; 877 } 878 if (params.imageIndex !== undefined) { 879 this.imageIndex = params.imageIndex; 880 } 881 if (params.textIndex !== undefined) { 882 this.textIndex = params.textIndex; 883 } 884 if (params.checkBoxIndex !== undefined) { 885 this.checkBoxIndex = params.checkBoxIndex; 886 } 887 if (params.childrenSize !== undefined) { 888 this.childrenSize = params.childrenSize; 889 } 890 } 891 892 updateStateVars(params) { 893 } 894 895 purgeVariableDependenciesOnElmtId(rmElmtId) { 896 this.__minContentHeight.purgeDependencyOnElmtId(rmElmtId); 897 } 898 899 aboutToBeDeleted() { 900 this.__minContentHeight.aboutToBeDeleted(); 901 SubscriberManager.Get().delete(this.id__()); 902 this.aboutToBeDeletedInternal(); 903 } 904 905 doNothingBuilder(parent = null) { 906 } 907 908 get minContentHeight() { 909 return this.__minContentHeight.get(); 910 } 911 912 set minContentHeight(newValue) { 913 this.__minContentHeight.set(newValue); 914 } 915 916 onPlaceChildren(selfLayoutInfo, children, constraint) { 917 let currentX = 0; 918 let currentY = 0; 919 for (let index = 0; index < children.length; index++) { 920 let child = children[index]; 921 child.layout({ x: currentX, y: currentY }); 922 currentY += child.measureResult.height; 923 } 924 } 925 926 onMeasureSize(selfLayoutInfo, children, constraint) { 927 let sizeResult = { width: Number(constraint.maxWidth), height: 0 }; 928 if (children.length < this.childrenSize) { 929 return sizeResult; 930 } 931 let height = 0; 932 let checkBoxHeight = 0; 933 if (this.checkTips !== null) { 934 let checkboxChild = children[this.checkBoxIndex]; 935 let checkboxConstraint = { 936 maxWidth: constraint.maxWidth, 937 minHeight: CHECKBOX_CONTAINER_HEIGHT(), 938 maxHeight: constraint.maxHeight 939 }; 940 let checkBoxMeasureResult = checkboxChild.measure(checkboxConstraint); 941 checkBoxHeight = checkBoxMeasureResult.height; 942 height += checkBoxHeight; 943 } 944 let imageChild = children[this.imageIndex]; 945 let textMinHeight = 0; 946 if (this.title !== null || this.content !== null) { 947 textMinHeight = TEXT_MIN_HEIGHT + PADDING_LEVEL_8; 948 } 949 let imageMaxHeight = Number(constraint.maxHeight) - checkBoxHeight - textMinHeight; 950 let imageConstraint = { 951 maxWidth: constraint.maxWidth, 952 maxHeight: imageMaxHeight 953 }; 954 let imageMeasureResult = imageChild.measure(imageConstraint); 955 height += imageMeasureResult.height; 956 if (this.title !== null || this.content !== null) { 957 let textChild = children[this.textIndex]; 958 this.updateTextAlign(sizeResult.width); 959 let contentMaxHeight = Number(constraint.maxHeight) - imageMeasureResult.height - checkBoxHeight; 960 let contentConstraint = { 961 maxWidth: constraint.maxWidth, 962 maxHeight: Math.max(contentMaxHeight, TEXT_MIN_HEIGHT) 963 }; 964 let contentMeasureResult = textChild.measure(contentConstraint); 965 height += contentMeasureResult.height; 966 } 967 sizeResult.height = height; 968 this.minContentHeight = 969 Math.max(checkBoxHeight + imageMeasureResult.height + textMinHeight, MIN_CONTENT_HEIGHT); 970 return sizeResult; 971 } 972 973 initialRender() { 974 this.dialogBuilder.bind(this)(); 975 } 976 977 rerender() { 978 this.updateDirtyElements(); 979 } 980} 981 982export class SelectDialog extends ViewPU { 983 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 984 super(parent, __localStorage, elmtId, extraInfo); 985 if (typeof paramsLambda === 'function') { 986 this.paramsGenerator_ = paramsLambda; 987 } 988 this.controller = undefined; 989 this.title = ''; 990 this.content = ''; 991 this.confirm = null; 992 this.radioContent = []; 993 this.buttons = []; 994 this.contentPadding = undefined; 995 this.isFocus = false; 996 this.currentFocusIndex = -1; 997 this.radioHeight = 0; 998 this.itemHeight = 0; 999 this.__selectedIndex = new ObservedPropertySimplePU(-1, this, 'selectedIndex'); 1000 this.contentBuilder = this.buildContent; 1001 this.__fontColorWithTheme = new ObservedPropertyObjectPU({ 1002 'id': -1, 1003 'type': 10001, 1004 params: ['sys.color.font_primary'], 1005 'bundleName': '__harDefaultBundleName__', 1006 'moduleName': '__harDefaultModuleName__' 1007 }, this, 'fontColorWithTheme'); 1008 this.__dividerColorWithTheme = new ObservedPropertyObjectPU({ 1009 'id': -1, 1010 'type': 10001, 1011 params: ['sys.color.comp_divider'], 1012 'bundleName': '__harDefaultBundleName__', 1013 'moduleName': '__harDefaultModuleName__' 1014 }, this, 'dividerColorWithTheme'); 1015 this.theme = new CustomThemeImpl({}); 1016 this.themeColorMode = ThemeColorMode.SYSTEM; 1017 this.contentScroller = new Scroller(); 1018 this.__fontSizeScale = new ObservedPropertySimplePU(1, this, 'fontSizeScale'); 1019 this.__minContentHeight = new ObservedPropertySimplePU(MIN_CONTENT_HEIGHT, this, 'minContentHeight'); 1020 this.setInitiallyProvidedValue(params); 1021 this.finalizeConstruction(); 1022 } 1023 1024 setInitiallyProvidedValue(params) { 1025 if (params.controller !== undefined) { 1026 this.controller = params.controller; 1027 } 1028 if (params.title !== undefined) { 1029 this.title = params.title; 1030 } 1031 if (params.content !== undefined) { 1032 this.content = params.content; 1033 } 1034 if (params.confirm !== undefined) { 1035 this.confirm = params.confirm; 1036 } 1037 if (params.radioContent !== undefined) { 1038 this.radioContent = params.radioContent; 1039 } 1040 if (params.buttons !== undefined) { 1041 this.buttons = params.buttons; 1042 } 1043 if (params.contentPadding !== undefined) { 1044 this.contentPadding = params.contentPadding; 1045 } 1046 if (params.isFocus !== undefined) { 1047 this.isFocus = params.isFocus; 1048 } 1049 if (params.currentFocusIndex !== undefined) { 1050 this.currentFocusIndex = params.currentFocusIndex; 1051 } 1052 if (params.radioHeight !== undefined) { 1053 this.radioHeight = params.radioHeight; 1054 } 1055 if (params.itemHeight !== undefined) { 1056 this.itemHeight = params.itemHeight; 1057 } 1058 if (params.selectedIndex !== undefined) { 1059 this.selectedIndex = params.selectedIndex; 1060 } 1061 if (params.contentBuilder !== undefined) { 1062 this.contentBuilder = params.contentBuilder; 1063 } 1064 if (params.fontColorWithTheme !== undefined) { 1065 this.fontColorWithTheme = params.fontColorWithTheme; 1066 } 1067 if (params.dividerColorWithTheme !== undefined) { 1068 this.dividerColorWithTheme = params.dividerColorWithTheme; 1069 } 1070 if (params.theme !== undefined) { 1071 this.theme = params.theme; 1072 } 1073 if (params.themeColorMode !== undefined) { 1074 this.themeColorMode = params.themeColorMode; 1075 } 1076 if (params.contentScroller !== undefined) { 1077 this.contentScroller = params.contentScroller; 1078 } 1079 if (params.fontSizeScale !== undefined) { 1080 this.fontSizeScale = params.fontSizeScale; 1081 } 1082 if (params.minContentHeight !== undefined) { 1083 this.minContentHeight = params.minContentHeight; 1084 } 1085 } 1086 1087 updateStateVars(params) { 1088 } 1089 1090 purgeVariableDependenciesOnElmtId(rmElmtId) { 1091 this.__selectedIndex.purgeDependencyOnElmtId(rmElmtId); 1092 this.__fontColorWithTheme.purgeDependencyOnElmtId(rmElmtId); 1093 this.__dividerColorWithTheme.purgeDependencyOnElmtId(rmElmtId); 1094 this.__fontSizeScale.purgeDependencyOnElmtId(rmElmtId); 1095 this.__minContentHeight.purgeDependencyOnElmtId(rmElmtId); 1096 } 1097 1098 aboutToBeDeleted() { 1099 this.__selectedIndex.aboutToBeDeleted(); 1100 this.__fontColorWithTheme.aboutToBeDeleted(); 1101 this.__dividerColorWithTheme.aboutToBeDeleted(); 1102 this.__fontSizeScale.aboutToBeDeleted(); 1103 this.__minContentHeight.aboutToBeDeleted(); 1104 SubscriberManager.Get().delete(this.id__()); 1105 this.aboutToBeDeletedInternal(); 1106 } 1107 1108 setController(ctr) { 1109 this.controller = ctr; 1110 } 1111 1112 get selectedIndex() { 1113 return this.__selectedIndex.get(); 1114 } 1115 1116 set selectedIndex(newValue) { 1117 this.__selectedIndex.set(newValue); 1118 } 1119 1120 get fontColorWithTheme() { 1121 return this.__fontColorWithTheme.get(); 1122 } 1123 1124 set fontColorWithTheme(newValue) { 1125 this.__fontColorWithTheme.set(newValue); 1126 } 1127 1128 get dividerColorWithTheme() { 1129 return this.__dividerColorWithTheme.get(); 1130 } 1131 1132 set dividerColorWithTheme(newValue) { 1133 this.__dividerColorWithTheme.set(newValue); 1134 } 1135 1136 get fontSizeScale() { 1137 return this.__fontSizeScale.get(); 1138 } 1139 1140 set fontSizeScale(newValue) { 1141 this.__fontSizeScale.set(newValue); 1142 } 1143 1144 get minContentHeight() { 1145 return this.__minContentHeight.get(); 1146 } 1147 1148 set minContentHeight(newValue) { 1149 this.__minContentHeight.set(newValue); 1150 } 1151 1152 buildContent(parent = null) { 1153 this.observeComponentCreation2((elmtId, isInitialRender) => { 1154 Scroll.create(this.contentScroller); 1155 Scroll.scrollBar(BarState.Auto); 1156 Scroll.nestedScroll({ 1157 scrollForward: NestedScrollMode.PARALLEL, 1158 scrollBackward: NestedScrollMode.PARALLEL 1159 }); 1160 Scroll.onDidScroll((xOffset, yOffset) => { 1161 let scrollHeight = (this.itemHeight - this.radioHeight) / 2; 1162 if (this.isFocus) { 1163 if (this.currentFocusIndex === this.radioContent.length - 1) { 1164 this.contentScroller.scrollEdge(Edge.Bottom); 1165 this.currentFocusIndex = -1; 1166 } else if (this.currentFocusIndex === FIRST_ITEM_INDEX) { 1167 this.contentScroller.scrollEdge(Edge.Top); 1168 this.currentFocusIndex = -1; 1169 } else { 1170 if (yOffset > 0) { 1171 this.contentScroller.scrollBy(0, scrollHeight); 1172 } else if (yOffset < 0) { 1173 this.contentScroller.scrollBy(0, 0 - scrollHeight); 1174 } 1175 } 1176 this.isFocus = false; 1177 } 1178 }); 1179 }, Scroll); 1180 this.observeComponentCreation2((elmtId, isInitialRender) => { 1181 Column.create(); 1182 }, Column); 1183 this.observeComponentCreation2((elmtId, isInitialRender) => { 1184 If.create(); 1185 if (this.content) { 1186 this.ifElseBranchUpdateFunction(0, () => { 1187 this.observeComponentCreation2((elmtId, isInitialRender) => { 1188 Row.create(); 1189 Row.padding({ 1190 left: { 1191 'id': -1, 1192 'type': 10002, 1193 params: ['sys.float.padding_level12'], 1194 'bundleName': '__harDefaultBundleName__', 1195 'moduleName': '__harDefaultModuleName__' 1196 }, 1197 right: { 1198 'id': -1, 1199 'type': 10002, 1200 params: ['sys.float.padding_level12'], 1201 'bundleName': '__harDefaultBundleName__', 1202 'moduleName': '__harDefaultModuleName__' 1203 }, 1204 bottom: { 1205 'id': -1, 1206 'type': 10002, 1207 params: ['sys.float.padding_level4'], 1208 'bundleName': '__harDefaultBundleName__', 1209 'moduleName': '__harDefaultModuleName__' 1210 } 1211 }); 1212 Row.width('100%'); 1213 }, Row); 1214 this.observeComponentCreation2((elmtId, isInitialRender) => { 1215 Text.create(this.content); 1216 Text.fontSize(`${BODY_M}fp`); 1217 Text.fontWeight(FontWeight.Regular); 1218 Text.fontColor(ObservedObject.GetRawObject(this.fontColorWithTheme)); 1219 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 1220 }, Text); 1221 Text.pop(); 1222 Row.pop(); 1223 }); 1224 } else { 1225 this.ifElseBranchUpdateFunction(1, () => { 1226 }); 1227 } 1228 }, If); 1229 If.pop(); 1230 this.observeComponentCreation2((elmtId, isInitialRender) => { 1231 List.create(); 1232 List.width('100%'); 1233 List.clip(false); 1234 List.onFocus(() => { 1235 if (!this.contentScroller.isAtEnd()) { 1236 this.contentScroller.scrollEdge(Edge.Top); 1237 focusControl.requestFocus(String(FIRST_ITEM_INDEX)); 1238 } 1239 }); 1240 List.defaultFocus(this.buttons?.length === 0 ? true : false); 1241 }, List); 1242 this.observeComponentCreation2((elmtId, isInitialRender) => { 1243 ForEach.create(); 1244 const forEachItemGenFunction = (_item, index) => { 1245 const item = _item; 1246 { 1247 const itemCreation = (elmtId, isInitialRender) => { 1248 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 1249 itemCreation2(elmtId, isInitialRender); 1250 if (!isInitialRender) { 1251 ListItem.pop(); 1252 } 1253 ViewStackProcessor.StopGetAccessRecording(); 1254 }; 1255 const itemCreation2 = (elmtId, isInitialRender) => { 1256 ListItem.create(deepRenderFunction, true); 1257 ListItem.padding({ 1258 left: { 1259 'id': -1, 1260 'type': 10002, 1261 params: ['sys.float.padding_level6'], 1262 'bundleName': '__harDefaultBundleName__', 1263 'moduleName': '__harDefaultModuleName__' 1264 }, 1265 right: { 1266 'id': -1, 1267 'type': 10002, 1268 params: ['sys.float.padding_level6'], 1269 'bundleName': '__harDefaultBundleName__', 1270 'moduleName': '__harDefaultModuleName__' 1271 } 1272 }); 1273 ListItem.onSizeChange((oldValue, newValue) => { 1274 this.itemHeight = Number(newValue.height); 1275 }); 1276 }; 1277 const deepRenderFunction = (elmtId, isInitialRender) => { 1278 itemCreation(elmtId, isInitialRender); 1279 this.observeComponentCreation2((elmtId, isInitialRender) => { 1280 Column.create(); 1281 Column.borderRadius({ 1282 'id': -1, 1283 'type': 10002, 1284 params: ['sys.float.corner_radius_level8'], 1285 'bundleName': '__harDefaultBundleName__', 1286 'moduleName': '__harDefaultModuleName__' 1287 }); 1288 Column.focusBox({ 1289 margin: { value: -2, unit: LengthUnit.VP } 1290 }); 1291 Column.accessibilityText(getAccessibilityText(item.title, this.selectedIndex === index)); 1292 Column.onClick(() => { 1293 this.selectedIndex = index; 1294 item.action && item.action(); 1295 this.controller?.close(); 1296 }); 1297 }, Column); 1298 this.observeComponentCreation2((elmtId, isInitialRender) => { 1299 Button.createWithChild(); 1300 Button.type(ButtonType.Normal); 1301 Button.borderRadius({ 1302 'id': -1, 1303 'type': 10002, 1304 params: ['sys.float.corner_radius_level8'], 1305 'bundleName': '__harDefaultBundleName__', 1306 'moduleName': '__harDefaultModuleName__' 1307 }); 1308 Button.buttonStyle(ButtonStyleMode.TEXTUAL); 1309 Button.padding({ 1310 left: { 1311 'id': -1, 1312 'type': 10002, 1313 params: ['sys.float.padding_level6'], 1314 'bundleName': '__harDefaultBundleName__', 1315 'moduleName': '__harDefaultModuleName__' 1316 }, 1317 right: { 1318 'id': -1, 1319 'type': 10002, 1320 params: ['sys.float.padding_level6'], 1321 'bundleName': '__harDefaultBundleName__', 1322 'moduleName': '__harDefaultModuleName__' 1323 } 1324 }); 1325 }, Button); 1326 this.observeComponentCreation2((elmtId, isInitialRender) => { 1327 Row.create(); 1328 Row.constraintSize({ minHeight: LIST_MIN_HEIGHT }); 1329 Row.clip(false); 1330 Row.padding({ 1331 top: { 1332 'id': -1, 1333 'type': 10002, 1334 params: ['sys.float.padding_level4'], 1335 'bundleName': '__harDefaultBundleName__', 1336 'moduleName': '__harDefaultModuleName__' 1337 }, 1338 bottom: { 1339 'id': -1, 1340 'type': 10002, 1341 params: ['sys.float.padding_level4'], 1342 'bundleName': '__harDefaultBundleName__', 1343 'moduleName': '__harDefaultModuleName__' 1344 } 1345 }); 1346 }, Row); 1347 this.observeComponentCreation2((elmtId, isInitialRender) => { 1348 Text.create(item.title); 1349 Text.fontSize(`${BODY_L}fp`); 1350 Text.fontWeight(FontWeight.Medium); 1351 Text.fontColor(ObservedObject.GetRawObject(this.fontColorWithTheme)); 1352 Text.layoutWeight(1); 1353 Text.direction(i18n.isRTL(i18n.System.getSystemLanguage()) ? Direction.Rtl : Direction.Ltr); 1354 }, Text); 1355 Text.pop(); 1356 this.observeComponentCreation2((elmtId, isInitialRender) => { 1357 Radio.create({ value: 'item.title', group: 'radioGroup' }); 1358 Radio.size({ width: CHECKBOX_CONTAINER_LENGTH, height: CHECKBOX_CONTAINER_LENGTH }); 1359 Radio.checked(this.selectedIndex === index); 1360 Radio.hitTestBehavior(HitTestMode.None); 1361 Radio.id(String(index)); 1362 Radio.focusable(false); 1363 Radio.accessibilityLevel('no'); 1364 Radio.onFocus(() => { 1365 this.isFocus = true; 1366 this.currentFocusIndex = index; 1367 if (index === FIRST_ITEM_INDEX) { 1368 this.contentScroller.scrollEdge(Edge.Top); 1369 } else if (index === this.radioContent.length - 1) { 1370 this.contentScroller.scrollEdge(Edge.Bottom); 1371 } 1372 }); 1373 Radio.onSizeChange((oldValue, newValue) => { 1374 this.radioHeight = Number(newValue.height); 1375 }); 1376 }, Radio); 1377 Row.pop(); 1378 Button.pop(); 1379 this.observeComponentCreation2((elmtId, isInitialRender) => { 1380 If.create(); 1381 if (index < this.radioContent.length - 1) { 1382 this.ifElseBranchUpdateFunction(0, () => { 1383 this.observeComponentCreation2((elmtId, isInitialRender) => { 1384 Divider.create(); 1385 Divider.color(ObservedObject.GetRawObject(this.dividerColorWithTheme)); 1386 Divider.padding({ 1387 left: { 1388 'id': -1, 1389 'type': 10002, 1390 params: ['sys.float.padding_level6'], 1391 'bundleName': '__harDefaultBundleName__', 1392 'moduleName': '__harDefaultModuleName__' 1393 }, 1394 right: { 1395 'id': -1, 1396 'type': 10002, 1397 params: ['sys.float.padding_level6'], 1398 'bundleName': '__harDefaultBundleName__', 1399 'moduleName': '__harDefaultModuleName__' 1400 } 1401 }); 1402 }, Divider); 1403 }); 1404 } else { 1405 this.ifElseBranchUpdateFunction(1, () => { 1406 }); 1407 } 1408 }, If); 1409 If.pop(); 1410 Column.pop(); 1411 ListItem.pop(); 1412 }; 1413 this.observeComponentCreation2(itemCreation2, ListItem); 1414 ListItem.pop(); 1415 } 1416 }; 1417 this.forEachUpdateFunction(elmtId, this.radioContent, forEachItemGenFunction, undefined, true, false); 1418 }, ForEach); 1419 ForEach.pop(); 1420 List.pop(); 1421 Column.pop(); 1422 Scroll.pop(); 1423 } 1424 1425 initialRender() { 1426 this.observeComponentCreation2((elmtId, isInitialRender) => { 1427 __Common__.create(); 1428 __Common__.constraintSize({ maxHeight: '100%' }); 1429 }, __Common__); 1430 { 1431 this.observeComponentCreation2((elmtId, isInitialRender) => { 1432 if (isInitialRender) { 1433 let componentCall = new CustomDialogContentComponent(this, { 1434 controller: this.controller, 1435 primaryTitle: this.title, 1436 contentBuilder: () => { 1437 this.contentBuilder(); 1438 }, 1439 buttons: this.buttons, 1440 contentAreaPadding: this.contentPadding, 1441 theme: this.theme, 1442 themeColorMode: this.themeColorMode, 1443 fontSizeScale: this.__fontSizeScale, 1444 minContentHeight: this.__minContentHeight, 1445 }, undefined, elmtId, () => { 1446 }, { page: 'library/src/main/ets/components/dialog.ets', line: 598, col: 5 }); 1447 ViewPU.create(componentCall); 1448 let paramsLambda = () => { 1449 return { 1450 controller: this.controller, 1451 primaryTitle: this.title, 1452 contentBuilder: () => { 1453 this.contentBuilder(); 1454 }, 1455 buttons: this.buttons, 1456 contentAreaPadding: this.contentPadding, 1457 theme: this.theme, 1458 themeColorMode: this.themeColorMode, 1459 fontSizeScale: this.fontSizeScale, 1460 minContentHeight: this.minContentHeight 1461 }; 1462 }; 1463 componentCall.paramsGenerator_ = paramsLambda; 1464 } else { 1465 this.updateStateVarsOfChildByElmtId(elmtId, {}); 1466 } 1467 }, { name: 'CustomDialogContentComponent' }); 1468 } 1469 __Common__.pop(); 1470 } 1471 1472 aboutToAppear() { 1473 this.fontColorWithTheme = this.theme?.colors?.fontPrimary ? 1474 this.theme.colors.fontPrimary : { 1475 'id': -1, 1476 'type': 10001, 1477 params: ['sys.color.font_primary'], 1478 'bundleName': '__harDefaultBundleName__', 1479 'moduleName': '__harDefaultModuleName__' 1480 }; 1481 this.dividerColorWithTheme = this.theme?.colors?.compDivider ? 1482 this.theme.colors.compDivider : { 1483 'id': -1, 1484 'type': 10001, 1485 params: ['sys.color.comp_divider'], 1486 'bundleName': '__harDefaultBundleName__', 1487 'moduleName': '__harDefaultModuleName__' 1488 }; 1489 this.initContentPadding(); 1490 this.initButtons(); 1491 } 1492 1493 initContentPadding() { 1494 this.contentPadding = { 1495 left: { 1496 'id': -1, 1497 'type': 10002, 1498 params: ['sys.float.padding_level0'], 1499 'bundleName': '__harDefaultBundleName__', 1500 'moduleName': '__harDefaultModuleName__' 1501 }, 1502 right: { 1503 'id': -1, 1504 'type': 10002, 1505 params: ['sys.float.padding_level0'], 1506 'bundleName': '__harDefaultBundleName__', 1507 'moduleName': '__harDefaultModuleName__' 1508 } 1509 }; 1510 if (!this.title && !this.confirm) { 1511 this.contentPadding = { 1512 top: { 1513 'id': -1, 1514 'type': 10002, 1515 params: ['sys.float.padding_level12'], 1516 'bundleName': '__harDefaultBundleName__', 1517 'moduleName': '__harDefaultModuleName__' 1518 }, 1519 bottom: { 1520 'id': -1, 1521 'type': 10002, 1522 params: ['sys.float.padding_level12'], 1523 'bundleName': '__harDefaultBundleName__', 1524 'moduleName': '__harDefaultModuleName__' 1525 } 1526 }; 1527 return; 1528 } 1529 if (!this.title) { 1530 this.contentPadding = { 1531 top: { 1532 'id': -1, 1533 'type': 10002, 1534 params: ['sys.float.padding_level12'], 1535 'bundleName': '__harDefaultBundleName__', 1536 'moduleName': '__harDefaultModuleName__' 1537 } 1538 }; 1539 } else if (!this.confirm) { 1540 this.contentPadding = { 1541 bottom: { 1542 'id': -1, 1543 'type': 10002, 1544 params: ['sys.float.padding_level12'], 1545 'bundleName': '__harDefaultBundleName__', 1546 'moduleName': '__harDefaultModuleName__' 1547 } 1548 }; 1549 } 1550 } 1551 1552 initButtons() { 1553 this.buttons = []; 1554 if (this.confirm) { 1555 this.buttons.push(this.confirm); 1556 } 1557 } 1558 1559 rerender() { 1560 this.updateDirtyElements(); 1561 } 1562} 1563 1564class ConfirmDialogContentLayout extends ViewPU { 1565 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 1566 super(parent, __localStorage, elmtId, extraInfo); 1567 if (typeof paramsLambda === 'function') { 1568 this.paramsGenerator_ = paramsLambda; 1569 } 1570 this.textIndex = 0; 1571 this.checkboxIndex = 1; 1572 this.__minContentHeight = new SynchedPropertySimpleTwoWayPU(params.minContentHeight, this, 'minContentHeight'); 1573 this.updateTextAlign = (maxWidth) => { 1574 }; 1575 this.dialogBuilder = this.doNothingBuilder; 1576 this.setInitiallyProvidedValue(params); 1577 this.finalizeConstruction(); 1578 } 1579 1580 setInitiallyProvidedValue(params) { 1581 if (params.textIndex !== undefined) { 1582 this.textIndex = params.textIndex; 1583 } 1584 if (params.checkboxIndex !== undefined) { 1585 this.checkboxIndex = params.checkboxIndex; 1586 } 1587 if (params.updateTextAlign !== undefined) { 1588 this.updateTextAlign = params.updateTextAlign; 1589 } 1590 if (params.dialogBuilder !== undefined) { 1591 this.dialogBuilder = params.dialogBuilder; 1592 } 1593 } 1594 1595 updateStateVars(params) { 1596 } 1597 1598 purgeVariableDependenciesOnElmtId(rmElmtId) { 1599 this.__minContentHeight.purgeDependencyOnElmtId(rmElmtId); 1600 } 1601 1602 aboutToBeDeleted() { 1603 this.__minContentHeight.aboutToBeDeleted(); 1604 SubscriberManager.Get().delete(this.id__()); 1605 this.aboutToBeDeletedInternal(); 1606 } 1607 1608 get minContentHeight() { 1609 return this.__minContentHeight.get(); 1610 } 1611 1612 set minContentHeight(newValue) { 1613 this.__minContentHeight.set(newValue); 1614 } 1615 1616 doNothingBuilder(parent = null) { 1617 } 1618 1619 onPlaceChildren(selfLayoutInfo, children, constraint) { 1620 let currentX = 0; 1621 let currentY = 0; 1622 for (let index = 0; index < children.length; index++) { 1623 let child = children[index]; 1624 child.layout({ x: currentX, y: currentY }); 1625 currentY += child.measureResult.height; 1626 } 1627 } 1628 1629 onMeasureSize(selfLayoutInfo, children, constraint) { 1630 let sizeResult = { width: Number(constraint.maxWidth), height: 0 }; 1631 let childrenSize = 2; 1632 if (children.length < childrenSize) { 1633 return sizeResult; 1634 } 1635 this.updateTextAlign(sizeResult.width); 1636 let height = 0; 1637 let checkboxChild = children[this.checkboxIndex]; 1638 let checkboxConstraint = { 1639 maxWidth: constraint.maxWidth, 1640 minHeight: CHECKBOX_CONTAINER_HEIGHT(), 1641 maxHeight: constraint.maxHeight 1642 }; 1643 let checkBoxMeasureResult = checkboxChild.measure(checkboxConstraint); 1644 height += checkBoxMeasureResult.height; 1645 let textChild = children[this.textIndex]; 1646 let textConstraint = { 1647 maxWidth: constraint.maxWidth, 1648 maxHeight: Number(constraint.maxHeight) - height 1649 }; 1650 let textMeasureResult = textChild.measure(textConstraint); 1651 height += textMeasureResult.height; 1652 sizeResult.height = height; 1653 this.minContentHeight = Math.max(checkBoxMeasureResult.height + TEXT_MIN_HEIGHT, MIN_CONTENT_HEIGHT); 1654 return sizeResult; 1655 } 1656 1657 initialRender() { 1658 this.dialogBuilder.bind(this)(); 1659 } 1660 1661 rerender() { 1662 this.updateDirtyElements(); 1663 } 1664} 1665 1666export class ConfirmDialog extends ViewPU { 1667 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 1668 super(parent, __localStorage, elmtId, extraInfo); 1669 if (typeof paramsLambda === 'function') { 1670 this.paramsGenerator_ = paramsLambda; 1671 } 1672 this.controller = undefined; 1673 this.title = ''; 1674 this.content = ''; 1675 this.checkTips = ''; 1676 this.__isChecked = new ObservedPropertySimplePU(false, this, 'isChecked'); 1677 this.primaryButton = null; 1678 this.secondaryButton = null; 1679 this.__fontColorWithTheme = new ObservedPropertyObjectPU({ 1680 'id': -1, 1681 'type': 10001, 1682 params: ['sys.color.font_primary'], 1683 'bundleName': '__harDefaultBundleName__', 1684 'moduleName': '__harDefaultModuleName__' 1685 }, this, 'fontColorWithTheme'); 1686 this.theme = new CustomThemeImpl({}); 1687 this.themeColorMode = ThemeColorMode.SYSTEM; 1688 this.onCheckedChange = undefined; 1689 this.contentScroller = new Scroller(); 1690 this.buttons = undefined; 1691 this.__textAlign = new ObservedPropertySimplePU(TextAlign.Start, this, 'textAlign'); 1692 this.marginOffset = 0; 1693 this.__fontSizeScale = new ObservedPropertySimplePU(1, this, 'fontSizeScale'); 1694 this.__minContentHeight = new ObservedPropertySimplePU(MIN_CONTENT_HEIGHT, this, 'minContentHeight'); 1695 this.textIndex = 0; 1696 this.checkboxIndex = 1; 1697 this.updateTextAlign = (maxWidth) => { 1698 if (this.content) { 1699 this.textAlign = getTextAlign(maxWidth, this.content, `${BODY_L * this.fontSizeScale}vp`); 1700 } 1701 }; 1702 this.setInitiallyProvidedValue(params); 1703 this.finalizeConstruction(); 1704 } 1705 1706 setInitiallyProvidedValue(params) { 1707 if (params.controller !== undefined) { 1708 this.controller = params.controller; 1709 } 1710 if (params.title !== undefined) { 1711 this.title = params.title; 1712 } 1713 if (params.content !== undefined) { 1714 this.content = params.content; 1715 } 1716 if (params.checkTips !== undefined) { 1717 this.checkTips = params.checkTips; 1718 } 1719 if (params.isChecked !== undefined) { 1720 this.isChecked = params.isChecked; 1721 } 1722 if (params.primaryButton !== undefined) { 1723 this.primaryButton = params.primaryButton; 1724 } 1725 if (params.secondaryButton !== undefined) { 1726 this.secondaryButton = params.secondaryButton; 1727 } 1728 if (params.fontColorWithTheme !== undefined) { 1729 this.fontColorWithTheme = params.fontColorWithTheme; 1730 } 1731 if (params.theme !== undefined) { 1732 this.theme = params.theme; 1733 } 1734 if (params.themeColorMode !== undefined) { 1735 this.themeColorMode = params.themeColorMode; 1736 } 1737 if (params.onCheckedChange !== undefined) { 1738 this.onCheckedChange = params.onCheckedChange; 1739 } 1740 if (params.contentScroller !== undefined) { 1741 this.contentScroller = params.contentScroller; 1742 } 1743 if (params.buttons !== undefined) { 1744 this.buttons = params.buttons; 1745 } 1746 if (params.textAlign !== undefined) { 1747 this.textAlign = params.textAlign; 1748 } 1749 if (params.marginOffset !== undefined) { 1750 this.marginOffset = params.marginOffset; 1751 } 1752 if (params.fontSizeScale !== undefined) { 1753 this.fontSizeScale = params.fontSizeScale; 1754 } 1755 if (params.minContentHeight !== undefined) { 1756 this.minContentHeight = params.minContentHeight; 1757 } 1758 if (params.textIndex !== undefined) { 1759 this.textIndex = params.textIndex; 1760 } 1761 if (params.checkboxIndex !== undefined) { 1762 this.checkboxIndex = params.checkboxIndex; 1763 } 1764 if (params.updateTextAlign !== undefined) { 1765 this.updateTextAlign = params.updateTextAlign; 1766 } 1767 } 1768 1769 updateStateVars(params) { 1770 } 1771 1772 purgeVariableDependenciesOnElmtId(rmElmtId) { 1773 this.__isChecked.purgeDependencyOnElmtId(rmElmtId); 1774 this.__fontColorWithTheme.purgeDependencyOnElmtId(rmElmtId); 1775 this.__textAlign.purgeDependencyOnElmtId(rmElmtId); 1776 this.__fontSizeScale.purgeDependencyOnElmtId(rmElmtId); 1777 this.__minContentHeight.purgeDependencyOnElmtId(rmElmtId); 1778 } 1779 1780 aboutToBeDeleted() { 1781 this.__isChecked.aboutToBeDeleted(); 1782 this.__fontColorWithTheme.aboutToBeDeleted(); 1783 this.__textAlign.aboutToBeDeleted(); 1784 this.__fontSizeScale.aboutToBeDeleted(); 1785 this.__minContentHeight.aboutToBeDeleted(); 1786 SubscriberManager.Get().delete(this.id__()); 1787 this.aboutToBeDeletedInternal(); 1788 } 1789 1790 setController(ctr) { 1791 this.controller = ctr; 1792 } 1793 1794 get isChecked() { 1795 return this.__isChecked.get(); 1796 } 1797 1798 set isChecked(newValue) { 1799 this.__isChecked.set(newValue); 1800 } 1801 1802 get fontColorWithTheme() { 1803 return this.__fontColorWithTheme.get(); 1804 } 1805 1806 set fontColorWithTheme(newValue) { 1807 this.__fontColorWithTheme.set(newValue); 1808 } 1809 1810 get textAlign() { 1811 return this.__textAlign.get(); 1812 } 1813 1814 set textAlign(newValue) { 1815 this.__textAlign.set(newValue); 1816 } 1817 1818 get fontSizeScale() { 1819 return this.__fontSizeScale.get(); 1820 } 1821 1822 set fontSizeScale(newValue) { 1823 this.__fontSizeScale.set(newValue); 1824 } 1825 1826 get minContentHeight() { 1827 return this.__minContentHeight.get(); 1828 } 1829 1830 set minContentHeight(newValue) { 1831 this.__minContentHeight.set(newValue); 1832 } 1833 1834 textBuilder(parent = null) { 1835 this.observeComponentCreation2((elmtId, isInitialRender) => { 1836 Column.create(); 1837 }, Column); 1838 this.observeComponentCreation2((elmtId, isInitialRender) => { 1839 Scroll.create(this.contentScroller); 1840 Scroll.fadingEdge(IS_FADEOUT_ENABLE(), { fadingEdgeLength: LengthMetrics.vp(FADEOUT_GRADIENT_WIDTH) }); 1841 Scroll.nestedScroll({ 1842 scrollForward: NestedScrollMode.PARALLEL, 1843 scrollBackward: NestedScrollMode.PARALLEL 1844 }); 1845 Scroll.margin({ end: LengthMetrics.vp(this.marginOffset) }); 1846 }, Scroll); 1847 this.observeComponentCreation2((elmtId, isInitialRender) => { 1848 Column.create(); 1849 Column.margin({ end: LengthMetrics.vp(CONTENT_END_MARGIN()) }); 1850 }, Column); 1851 this.observeComponentCreation2((elmtId, isInitialRender) => { 1852 Text.create(this.content); 1853 Text.focusable(true); 1854 Text.defaultFocus(!(this.primaryButton?.value || this.secondaryButton?.value)); 1855 Text.focusBox({ 1856 strokeWidth: LengthMetrics.px(0) 1857 }); 1858 Text.fontSize(`${BODY_L}fp`); 1859 Text.fontWeight(CONTENT_FONT_WEIGHT()); 1860 Text.fontColor(ObservedObject.GetRawObject(this.fontColorWithTheme)); 1861 Text.textAlign(this.textAlign); 1862 Text.onKeyEvent((event) => { 1863 if (event) { 1864 resolveKeyEvent(event, this.contentScroller); 1865 } 1866 }); 1867 Text.width('100%'); 1868 }, Text); 1869 Text.pop(); 1870 Column.pop(); 1871 Scroll.pop(); 1872 Column.pop(); 1873 } 1874 1875 checkBoxBuilder(parent = null) { 1876 this.observeComponentCreation2((elmtId, isInitialRender) => { 1877 Row.create(); 1878 Row.accessibilityGroup(true); 1879 Row.accessibilityText(getCheckTipsAccessibilityText(this.checkTips, this.isChecked)); 1880 Row.accessibilityDescription(this.isChecked ? { 1881 'id': -1, 1882 'type': 10003, 1883 params: ['sys.string.advanced_dialog_accessibility_cancel_checked_desc'], 1884 'bundleName': '__harDefaultBundleName__', 1885 'moduleName': '__harDefaultModuleName__' 1886 } : { 1887 'id': -1, 1888 'type': 10003, 1889 params: ['sys.string.slider_accessibility_unselectedDesc'], 1890 'bundleName': '__harDefaultBundleName__', 1891 'moduleName': '__harDefaultModuleName__' 1892 }); 1893 Row.onClick(() => { 1894 this.isChecked = !this.isChecked; 1895 try { 1896 let eventInfo = ({ 1897 type: 'announceForAccessibility', 1898 bundleName: getContext()?.abilityInfo?.bundleName, 1899 triggerAction: 'common', 1900 textAnnouncedForAccessibility: this.isChecked ? 1901 getContext().resourceManager.getStringSync(125833934) : 1902 getContext().resourceManager.getStringSync(125833935) 1903 }); 1904 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 1905 console.info(`Accessibility send event`); 1906 }); 1907 } catch (exception) { 1908 let code = exception.code; 1909 let message = exception.message; 1910 hilog.error(0x3900, 'Ace', `Faild to send event, cause, code: ${code}, message: ${message}`); 1911 } 1912 }); 1913 Row.width('100%'); 1914 Row.padding({ top: TIP_CHECKBOX_TOP_PADDING(), bottom: TIP_CHECKBOX_BOTTOM_PADDING() }); 1915 }, Row); 1916 this.observeComponentCreation2((elmtId, isInitialRender) => { 1917 Checkbox.create({ name: '', group: 'checkboxGroup' }); 1918 Checkbox.select(this.isChecked); 1919 Checkbox.onChange((checked) => { 1920 this.isChecked = checked; 1921 if (this.onCheckedChange) { 1922 this.onCheckedChange(this.isChecked); 1923 } 1924 }); 1925 Checkbox.hitTestBehavior(HitTestMode.Block); 1926 Checkbox.margin({ start: LengthMetrics.vp(0), end: LengthMetrics.vp(TIP_CHECKBOX_END_MARGIN()) }); 1927 }, Checkbox); 1928 Checkbox.pop(); 1929 this.observeComponentCreation2((elmtId, isInitialRender) => { 1930 Text.create(this.checkTips); 1931 Text.fontSize(`${SUBTITLE_SIZE()}fp`); 1932 Text.fontWeight(CONTENT_FONT_WEIGHT()); 1933 Text.fontColor(ObservedObject.GetRawObject(this.fontColorWithTheme)); 1934 Text.maxLines(CONTENT_MAX_LINES); 1935 Text.focusable(false); 1936 Text.layoutWeight(1); 1937 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 1938 }, Text); 1939 Text.pop(); 1940 Row.pop(); 1941 } 1942 1943 buildContent(parent = null) { 1944 { 1945 this.observeComponentCreation2((elmtId, isInitialRender) => { 1946 if (isInitialRender) { 1947 let componentCall = new ConfirmDialogContentLayout(this, { 1948 minContentHeight: this.__minContentHeight, updateTextAlign: this.updateTextAlign, 1949 dialogBuilder: () => { 1950 this.observeComponentCreation2((elmtId, isInitialRender) => { 1951 ForEach.create(); 1952 const forEachItemGenFunction = _item => { 1953 const index = _item; 1954 this.observeComponentCreation2((elmtId, isInitialRender) => { 1955 If.create(); 1956 if (index === this.textIndex) { 1957 this.ifElseBranchUpdateFunction(0, () => { 1958 this.observeComponentCreation2((elmtId, isInitialRender) => { 1959 WithTheme.create({ 1960 theme: this.theme, 1961 colorMode: this.themeColorMode 1962 }); 1963 }, WithTheme); 1964 this.textBuilder.bind(this)(); 1965 WithTheme.pop(); 1966 }); 1967 } else if (index === this.checkboxIndex) { 1968 this.ifElseBranchUpdateFunction(1, () => { 1969 this.observeComponentCreation2((elmtId, isInitialRender) => { 1970 WithTheme.create({ 1971 theme: this.theme, 1972 colorMode: this.themeColorMode 1973 }); 1974 }, WithTheme); 1975 this.checkBoxBuilder.bind(this)(); 1976 WithTheme.pop(); 1977 }); 1978 } else { 1979 this.ifElseBranchUpdateFunction(2, () => { 1980 }); 1981 } 1982 }, If); 1983 If.pop(); 1984 }; 1985 this.forEachUpdateFunction(elmtId, [this.textIndex, this.checkboxIndex], 1986 forEachItemGenFunction); 1987 }, ForEach); 1988 ForEach.pop(); 1989 } 1990 }, undefined, elmtId, () => { 1991 }, { page: 'library/src/main/ets/components/dialog.ets', line: 824, col: 5 }); 1992 ViewPU.create(componentCall); 1993 let paramsLambda = () => { 1994 return { 1995 minContentHeight: this.minContentHeight, 1996 updateTextAlign: this.updateTextAlign, 1997 dialogBuilder: () => { 1998 this.observeComponentCreation2((elmtId, isInitialRender) => { 1999 ForEach.create(); 2000 const forEachItemGenFunction = _item => { 2001 const index = _item; 2002 this.observeComponentCreation2((elmtId, isInitialRender) => { 2003 If.create(); 2004 if (index === this.textIndex) { 2005 this.ifElseBranchUpdateFunction(0, () => { 2006 this.observeComponentCreation2((elmtId, isInitialRender) => { 2007 WithTheme.create({ 2008 theme: this.theme, 2009 colorMode: this.themeColorMode 2010 }); 2011 }, WithTheme); 2012 this.textBuilder.bind(this)(); 2013 WithTheme.pop(); 2014 }); 2015 } else if (index === this.checkboxIndex) { 2016 this.ifElseBranchUpdateFunction(1, () => { 2017 this.observeComponentCreation2((elmtId, isInitialRender) => { 2018 WithTheme.create({ 2019 theme: this.theme, 2020 colorMode: this.themeColorMode 2021 }); 2022 }, WithTheme); 2023 this.checkBoxBuilder.bind(this)(); 2024 WithTheme.pop(); 2025 }); 2026 } else { 2027 this.ifElseBranchUpdateFunction(2, () => { 2028 }); 2029 } 2030 }, If); 2031 If.pop(); 2032 }; 2033 this.forEachUpdateFunction(elmtId, [this.textIndex, this.checkboxIndex], 2034 forEachItemGenFunction); 2035 }, ForEach); 2036 ForEach.pop(); 2037 } 2038 }; 2039 }; 2040 componentCall.paramsGenerator_ = paramsLambda; 2041 } else { 2042 this.updateStateVarsOfChildByElmtId(elmtId, {}); 2043 } 2044 }, { name: 'ConfirmDialogContentLayout' }); 2045 } 2046 } 2047 2048 initialRender() { 2049 this.observeComponentCreation2((elmtId, isInitialRender) => { 2050 __Common__.create(); 2051 __Common__.constraintSize({ maxHeight: '100%' }); 2052 }, __Common__); 2053 { 2054 this.observeComponentCreation2((elmtId, isInitialRender) => { 2055 if (isInitialRender) { 2056 let componentCall = new CustomDialogContentComponent(this, { 2057 primaryTitle: this.title, 2058 controller: this.controller, 2059 contentBuilder: () => { 2060 this.buildContent(); 2061 }, 2062 minContentHeight: this.__minContentHeight, 2063 buttons: this.buttons, 2064 theme: this.theme, 2065 themeColorMode: this.themeColorMode, 2066 fontSizeScale: this.__fontSizeScale, 2067 }, undefined, elmtId, () => { 2068 }, { page: 'library/src/main/ets/components/dialog.ets', line: 840, col: 5 }); 2069 ViewPU.create(componentCall); 2070 let paramsLambda = () => { 2071 return { 2072 primaryTitle: this.title, 2073 controller: this.controller, 2074 contentBuilder: () => { 2075 this.buildContent(); 2076 }, 2077 minContentHeight: this.minContentHeight, 2078 buttons: this.buttons, 2079 theme: this.theme, 2080 themeColorMode: this.themeColorMode, 2081 fontSizeScale: this.fontSizeScale 2082 }; 2083 }; 2084 componentCall.paramsGenerator_ = paramsLambda; 2085 } else { 2086 this.updateStateVarsOfChildByElmtId(elmtId, {}); 2087 } 2088 }, { name: 'CustomDialogContentComponent' }); 2089 } 2090 __Common__.pop(); 2091 } 2092 2093 aboutToAppear() { 2094 this.fontColorWithTheme = this.theme?.colors?.fontPrimary ? 2095 this.theme.colors.fontPrimary : { 2096 'id': -1, 2097 'type': 10001, 2098 params: ['sys.color.font_primary'], 2099 'bundleName': '__harDefaultBundleName__', 2100 'moduleName': '__harDefaultModuleName__' 2101 }; 2102 this.initButtons(); 2103 this.initMargin(); 2104 } 2105 2106 initMargin() { 2107 this.marginOffset = 0 - SCROLL_END_MARGIN(); 2108 } 2109 2110 initButtons() { 2111 if (!this.primaryButton && !this.secondaryButton) { 2112 return; 2113 } 2114 this.buttons = []; 2115 if (this.primaryButton) { 2116 this.buttons.push(this.primaryButton); 2117 } 2118 if (this.secondaryButton) { 2119 this.buttons.push(this.secondaryButton); 2120 } 2121 } 2122 2123 rerender() { 2124 this.updateDirtyElements(); 2125 } 2126} 2127 2128export class AlertDialog extends ViewPU { 2129 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 2130 super(parent, __localStorage, elmtId, extraInfo); 2131 if (typeof paramsLambda === 'function') { 2132 this.paramsGenerator_ = paramsLambda; 2133 } 2134 this.controller = undefined; 2135 this.primaryTitle = undefined; 2136 this.secondaryTitle = undefined; 2137 this.content = ''; 2138 this.primaryButton = null; 2139 this.secondaryButton = null; 2140 this.buttons = undefined; 2141 this.__textAlign = new ObservedPropertySimplePU(TextAlign.Start, this, 'textAlign'); 2142 this.contentScroller = new Scroller(); 2143 this.__fontColorWithTheme = new ObservedPropertyObjectPU({ 2144 'id': -1, 2145 'type': 10001, 2146 params: ['sys.color.font_primary'], 2147 'bundleName': '__harDefaultBundleName__', 2148 'moduleName': '__harDefaultModuleName__' 2149 }, this, 'fontColorWithTheme'); 2150 this.theme = new CustomThemeImpl({}); 2151 this.themeColorMode = ThemeColorMode.SYSTEM; 2152 this.__fontSizeScale = new ObservedPropertySimplePU(1, this, 'fontSizeScale'); 2153 this.__minContentHeight = new ObservedPropertySimplePU(MIN_CONTENT_HEIGHT, this, 'minContentHeight'); 2154 this.setInitiallyProvidedValue(params); 2155 this.finalizeConstruction(); 2156 } 2157 2158 setInitiallyProvidedValue(params) { 2159 if (params.controller !== undefined) { 2160 this.controller = params.controller; 2161 } 2162 if (params.primaryTitle !== undefined) { 2163 this.primaryTitle = params.primaryTitle; 2164 } 2165 if (params.secondaryTitle !== undefined) { 2166 this.secondaryTitle = params.secondaryTitle; 2167 } 2168 if (params.content !== undefined) { 2169 this.content = params.content; 2170 } 2171 if (params.primaryButton !== undefined) { 2172 this.primaryButton = params.primaryButton; 2173 } 2174 if (params.secondaryButton !== undefined) { 2175 this.secondaryButton = params.secondaryButton; 2176 } 2177 if (params.buttons !== undefined) { 2178 this.buttons = params.buttons; 2179 } 2180 if (params.textAlign !== undefined) { 2181 this.textAlign = params.textAlign; 2182 } 2183 if (params.contentScroller !== undefined) { 2184 this.contentScroller = params.contentScroller; 2185 } 2186 if (params.fontColorWithTheme !== undefined) { 2187 this.fontColorWithTheme = params.fontColorWithTheme; 2188 } 2189 if (params.theme !== undefined) { 2190 this.theme = params.theme; 2191 } 2192 if (params.themeColorMode !== undefined) { 2193 this.themeColorMode = params.themeColorMode; 2194 } 2195 if (params.fontSizeScale !== undefined) { 2196 this.fontSizeScale = params.fontSizeScale; 2197 } 2198 if (params.minContentHeight !== undefined) { 2199 this.minContentHeight = params.minContentHeight; 2200 } 2201 } 2202 2203 updateStateVars(params) { 2204 } 2205 2206 purgeVariableDependenciesOnElmtId(rmElmtId) { 2207 this.__textAlign.purgeDependencyOnElmtId(rmElmtId); 2208 this.__fontColorWithTheme.purgeDependencyOnElmtId(rmElmtId); 2209 this.__fontSizeScale.purgeDependencyOnElmtId(rmElmtId); 2210 this.__minContentHeight.purgeDependencyOnElmtId(rmElmtId); 2211 } 2212 2213 aboutToBeDeleted() { 2214 this.__textAlign.aboutToBeDeleted(); 2215 this.__fontColorWithTheme.aboutToBeDeleted(); 2216 this.__fontSizeScale.aboutToBeDeleted(); 2217 this.__minContentHeight.aboutToBeDeleted(); 2218 SubscriberManager.Get().delete(this.id__()); 2219 this.aboutToBeDeletedInternal(); 2220 } 2221 2222 setController(ctr) { 2223 this.controller = ctr; 2224 } 2225 2226 get textAlign() { 2227 return this.__textAlign.get(); 2228 } 2229 2230 set textAlign(newValue) { 2231 this.__textAlign.set(newValue); 2232 } 2233 2234 get fontColorWithTheme() { 2235 return this.__fontColorWithTheme.get(); 2236 } 2237 2238 set fontColorWithTheme(newValue) { 2239 this.__fontColorWithTheme.set(newValue); 2240 } 2241 2242 get fontSizeScale() { 2243 return this.__fontSizeScale.get(); 2244 } 2245 2246 set fontSizeScale(newValue) { 2247 this.__fontSizeScale.set(newValue); 2248 } 2249 2250 get minContentHeight() { 2251 return this.__minContentHeight.get(); 2252 } 2253 2254 set minContentHeight(newValue) { 2255 this.__minContentHeight.set(newValue); 2256 } 2257 2258 initialRender() { 2259 this.observeComponentCreation2((elmtId, isInitialRender) => { 2260 __Common__.create(); 2261 __Common__.constraintSize({ maxHeight: '100%' }); 2262 }, __Common__); 2263 { 2264 this.observeComponentCreation2((elmtId, isInitialRender) => { 2265 if (isInitialRender) { 2266 let componentCall = new CustomDialogContentComponent(this, { 2267 primaryTitle: this.primaryTitle, 2268 secondaryTitle: this.secondaryTitle, 2269 controller: this.controller, 2270 contentBuilder: () => { 2271 this.AlertDialogContentBuilder(); 2272 }, 2273 buttons: this.buttons, 2274 theme: this.theme, 2275 themeColorMode: this.themeColorMode, 2276 fontSizeScale: this.__fontSizeScale, 2277 minContentHeight: this.__minContentHeight, 2278 }, undefined, elmtId, () => { 2279 }, { page: 'library/src/main/ets/components/dialog.ets', line: 898, col: 5 }); 2280 ViewPU.create(componentCall); 2281 let paramsLambda = () => { 2282 return { 2283 primaryTitle: this.primaryTitle, 2284 secondaryTitle: this.secondaryTitle, 2285 controller: this.controller, 2286 contentBuilder: () => { 2287 this.AlertDialogContentBuilder(); 2288 }, 2289 buttons: this.buttons, 2290 theme: this.theme, 2291 themeColorMode: this.themeColorMode, 2292 fontSizeScale: this.fontSizeScale, 2293 minContentHeight: this.minContentHeight 2294 }; 2295 }; 2296 componentCall.paramsGenerator_ = paramsLambda; 2297 } else { 2298 this.updateStateVarsOfChildByElmtId(elmtId, {}); 2299 } 2300 }, { name: 'CustomDialogContentComponent' }); 2301 } 2302 __Common__.pop(); 2303 } 2304 2305 AlertDialogContentBuilder(parent = null) { 2306 this.observeComponentCreation2((elmtId, isInitialRender) => { 2307 Column.create(); 2308 Column.margin({ end: LengthMetrics.vp(0 - SCROLL_BAR_OFFSET) }); 2309 }, Column); 2310 this.observeComponentCreation2((elmtId, isInitialRender) => { 2311 Scroll.create(this.contentScroller); 2312 Scroll.fadingEdge(IS_FADEOUT_ENABLE(), { fadingEdgeLength: LengthMetrics.vp(FADEOUT_GRADIENT_WIDTH) }); 2313 Scroll.nestedScroll({ 2314 scrollForward: NestedScrollMode.PARALLEL, 2315 scrollBackward: NestedScrollMode.PARALLEL 2316 }); 2317 Scroll.width('100%'); 2318 }, Scroll); 2319 this.observeComponentCreation2((elmtId, isInitialRender) => { 2320 Text.create(this.content); 2321 Text.focusable(true); 2322 Text.defaultFocus(!(this.primaryButton || this.secondaryButton)); 2323 Text.focusBox({ 2324 strokeWidth: LengthMetrics.px(0) 2325 }); 2326 Text.fontSize(`${BODY_L}fp`); 2327 Text.fontWeight(this.getFontWeight()); 2328 Text.fontColor(ObservedObject.GetRawObject(this.fontColorWithTheme)); 2329 Text.margin({ end: LengthMetrics.vp(SCROLL_BAR_OFFSET) }); 2330 Text.width(`calc(100% - ${SCROLL_BAR_OFFSET}vp)`); 2331 Text.textAlign(this.textAlign); 2332 Text.onSizeChange((oldValue, newValue) => { 2333 this.updateTextAlign(Number(newValue.width)); 2334 }); 2335 Text.onKeyEvent((event) => { 2336 if (event) { 2337 resolveKeyEvent(event, this.contentScroller); 2338 } 2339 }); 2340 }, Text); 2341 Text.pop(); 2342 Scroll.pop(); 2343 Column.pop(); 2344 } 2345 2346 aboutToAppear() { 2347 this.fontColorWithTheme = this.theme?.colors?.fontPrimary ? 2348 this.theme.colors.fontPrimary : { 2349 'id': -1, 2350 'type': 10001, 2351 params: ['sys.color.font_primary'], 2352 'bundleName': '__harDefaultBundleName__', 2353 'moduleName': '__harDefaultModuleName__' 2354 }; 2355 this.initButtons(); 2356 } 2357 2358 updateTextAlign(maxWidth) { 2359 this.textAlign = getTextAlign(maxWidth, this.content, `${BODY_L * this.fontSizeScale}vp`); 2360 } 2361 2362 initButtons() { 2363 if (!this.primaryButton && !this.secondaryButton) { 2364 return; 2365 } 2366 this.buttons = []; 2367 if (this.primaryButton) { 2368 this.buttons.push(this.primaryButton); 2369 } 2370 if (this.secondaryButton) { 2371 this.buttons.push(this.secondaryButton); 2372 } 2373 } 2374 2375 getFontWeight() { 2376 if (this.primaryTitle || this.secondaryTitle) { 2377 return FontWeight.Regular; 2378 } 2379 return CONTENT_FONT_WEIGHT(); 2380 } 2381 2382 rerender() { 2383 this.updateDirtyElements(); 2384 } 2385} 2386 2387export class CustomContentDialog extends ViewPU { 2388 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 2389 super(parent, __localStorage, elmtId, extraInfo); 2390 if (typeof paramsLambda === 'function') { 2391 this.paramsGenerator_ = paramsLambda; 2392 } 2393 this.controller = undefined; 2394 this.primaryTitle = undefined; 2395 this.secondaryTitle = undefined; 2396 this.contentBuilder = undefined; 2397 this.contentAreaPadding = undefined; 2398 this.localizedContentAreaPadding = undefined; 2399 this.buttons = undefined; 2400 this.theme = new CustomThemeImpl({}); 2401 this.themeColorMode = ThemeColorMode.SYSTEM; 2402 this.__fontSizeScale = new ObservedPropertySimplePU(1, this, 'fontSizeScale'); 2403 this.__minContentHeight = new ObservedPropertySimplePU(MIN_CONTENT_HEIGHT, this, 'minContentHeight'); 2404 this.setInitiallyProvidedValue(params); 2405 this.finalizeConstruction(); 2406 } 2407 2408 setInitiallyProvidedValue(params) { 2409 if (params.controller !== undefined) { 2410 this.controller = params.controller; 2411 } 2412 if (params.primaryTitle !== undefined) { 2413 this.primaryTitle = params.primaryTitle; 2414 } 2415 if (params.secondaryTitle !== undefined) { 2416 this.secondaryTitle = params.secondaryTitle; 2417 } 2418 if (params.contentBuilder !== undefined) { 2419 this.contentBuilder = params.contentBuilder; 2420 } 2421 if (params.contentAreaPadding !== undefined) { 2422 this.contentAreaPadding = params.contentAreaPadding; 2423 } 2424 if (params.localizedContentAreaPadding !== undefined) { 2425 this.localizedContentAreaPadding = params.localizedContentAreaPadding; 2426 } 2427 if (params.buttons !== undefined) { 2428 this.buttons = params.buttons; 2429 } 2430 if (params.theme !== undefined) { 2431 this.theme = params.theme; 2432 } 2433 if (params.themeColorMode !== undefined) { 2434 this.themeColorMode = params.themeColorMode; 2435 } 2436 if (params.fontSizeScale !== undefined) { 2437 this.fontSizeScale = params.fontSizeScale; 2438 } 2439 if (params.minContentHeight !== undefined) { 2440 this.minContentHeight = params.minContentHeight; 2441 } 2442 } 2443 2444 updateStateVars(params) { 2445 } 2446 2447 purgeVariableDependenciesOnElmtId(rmElmtId) { 2448 this.__fontSizeScale.purgeDependencyOnElmtId(rmElmtId); 2449 this.__minContentHeight.purgeDependencyOnElmtId(rmElmtId); 2450 } 2451 2452 aboutToBeDeleted() { 2453 this.__fontSizeScale.aboutToBeDeleted(); 2454 this.__minContentHeight.aboutToBeDeleted(); 2455 SubscriberManager.Get().delete(this.id__()); 2456 this.aboutToBeDeletedInternal(); 2457 } 2458 2459 setController(ctr) { 2460 this.controller = ctr; 2461 } 2462 2463 get fontSizeScale() { 2464 return this.__fontSizeScale.get(); 2465 } 2466 2467 set fontSizeScale(newValue) { 2468 this.__fontSizeScale.set(newValue); 2469 } 2470 2471 get minContentHeight() { 2472 return this.__minContentHeight.get(); 2473 } 2474 2475 set minContentHeight(newValue) { 2476 this.__minContentHeight.set(newValue); 2477 } 2478 2479 initialRender() { 2480 this.observeComponentCreation2((elmtId, isInitialRender) => { 2481 __Common__.create(); 2482 __Common__.constraintSize({ maxHeight: '100%' }); 2483 }, __Common__); 2484 { 2485 this.observeComponentCreation2((elmtId, isInitialRender) => { 2486 if (isInitialRender) { 2487 let componentCall = new CustomDialogContentComponent(this, { 2488 controller: this.controller, 2489 primaryTitle: this.primaryTitle, 2490 secondaryTitle: this.secondaryTitle, 2491 contentBuilder: () => { 2492 this.contentBuilder(); 2493 }, 2494 contentAreaPadding: this.contentAreaPadding, 2495 localizedContentAreaPadding: this.localizedContentAreaPadding, 2496 buttons: this.buttons, 2497 theme: this.theme, 2498 themeColorMode: this.themeColorMode, 2499 fontSizeScale: this.__fontSizeScale, 2500 minContentHeight: this.__minContentHeight, 2501 customStyle: false 2502 }, undefined, elmtId, () => { 2503 }, { page: 'library/src/main/ets/components/dialog.ets', line: 991, col: 5 }); 2504 ViewPU.create(componentCall); 2505 let paramsLambda = () => { 2506 return { 2507 controller: this.controller, 2508 primaryTitle: this.primaryTitle, 2509 secondaryTitle: this.secondaryTitle, 2510 contentBuilder: () => { 2511 this.contentBuilder(); 2512 }, 2513 contentAreaPadding: this.contentAreaPadding, 2514 localizedContentAreaPadding: this.localizedContentAreaPadding, 2515 buttons: this.buttons, 2516 theme: this.theme, 2517 themeColorMode: this.themeColorMode, 2518 fontSizeScale: this.fontSizeScale, 2519 minContentHeight: this.minContentHeight, 2520 customStyle: false 2521 }; 2522 }; 2523 componentCall.paramsGenerator_ = paramsLambda; 2524 } else { 2525 this.updateStateVarsOfChildByElmtId(elmtId, {}); 2526 } 2527 }, { name: 'CustomDialogContentComponent' }); 2528 } 2529 __Common__.pop(); 2530 } 2531 2532 rerender() { 2533 this.updateDirtyElements(); 2534 } 2535} 2536 2537class CustomDialogControllerExtend extends CustomDialogController { 2538 constructor(value) { 2539 super(value); 2540 this.arg_ = value; 2541 } 2542} 2543 2544class CustomDialogLayout extends ViewPU { 2545 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 2546 super(parent, __localStorage, elmtId, extraInfo); 2547 if (typeof paramsLambda === 'function') { 2548 this.paramsGenerator_ = paramsLambda; 2549 } 2550 this.__titleHeight = new SynchedPropertySimpleTwoWayPU(params.titleHeight, this, 'titleHeight'); 2551 this.__buttonHeight = new SynchedPropertySimpleTwoWayPU(params.buttonHeight, this, 'buttonHeight'); 2552 this.__titleMinHeight = new SynchedPropertyObjectTwoWayPU(params.titleMinHeight, this, 'titleMinHeight'); 2553 this.dialogBuilder = this.doNothingBuilder; 2554 this.titleIndex = 0; 2555 this.contentIndex = 1; 2556 this.buttonIndex = 2; 2557 this.setInitiallyProvidedValue(params); 2558 this.finalizeConstruction(); 2559 } 2560 2561 setInitiallyProvidedValue(params) { 2562 if (params.dialogBuilder !== undefined) { 2563 this.dialogBuilder = params.dialogBuilder; 2564 } 2565 if (params.titleIndex !== undefined) { 2566 this.titleIndex = params.titleIndex; 2567 } 2568 if (params.contentIndex !== undefined) { 2569 this.contentIndex = params.contentIndex; 2570 } 2571 if (params.buttonIndex !== undefined) { 2572 this.buttonIndex = params.buttonIndex; 2573 } 2574 } 2575 2576 updateStateVars(params) { 2577 } 2578 2579 purgeVariableDependenciesOnElmtId(rmElmtId) { 2580 this.__titleHeight.purgeDependencyOnElmtId(rmElmtId); 2581 this.__buttonHeight.purgeDependencyOnElmtId(rmElmtId); 2582 this.__titleMinHeight.purgeDependencyOnElmtId(rmElmtId); 2583 } 2584 2585 aboutToBeDeleted() { 2586 this.__titleHeight.aboutToBeDeleted(); 2587 this.__buttonHeight.aboutToBeDeleted(); 2588 this.__titleMinHeight.aboutToBeDeleted(); 2589 SubscriberManager.Get().delete(this.id__()); 2590 this.aboutToBeDeletedInternal(); 2591 } 2592 2593 doNothingBuilder(parent = null) { 2594 } 2595 2596 get titleHeight() { 2597 return this.__titleHeight.get(); 2598 } 2599 2600 set titleHeight(newValue) { 2601 this.__titleHeight.set(newValue); 2602 } 2603 2604 get buttonHeight() { 2605 return this.__buttonHeight.get(); 2606 } 2607 2608 set buttonHeight(newValue) { 2609 this.__buttonHeight.set(newValue); 2610 } 2611 2612 get titleMinHeight() { 2613 return this.__titleMinHeight.get(); 2614 } 2615 2616 set titleMinHeight(newValue) { 2617 this.__titleMinHeight.set(newValue); 2618 } 2619 2620 onPlaceChildren(selfLayoutInfo, children, constraint) { 2621 let currentX = 0; 2622 let currentY = 0; 2623 for (let index = 0; index < children.length; index++) { 2624 let child = children[index]; 2625 child.layout({ x: currentX, y: currentY }); 2626 currentY += child.measureResult.height; 2627 } 2628 } 2629 2630 onMeasureSize(selfLayoutInfo, children, constraint) { 2631 let sizeResult = { width: Number(constraint.maxWidth), height: 0 }; 2632 let childrenSize = 3; 2633 if (children.length < childrenSize) { 2634 return sizeResult; 2635 } 2636 let height = 0; 2637 let titleChild = children[this.titleIndex]; 2638 let titleConstraint = { 2639 maxWidth: constraint.maxWidth, 2640 minHeight: this.titleMinHeight, 2641 maxHeight: constraint.maxHeight 2642 }; 2643 let titleMeasureResult = titleChild.measure(titleConstraint); 2644 this.titleHeight = titleMeasureResult.height; 2645 height += this.titleHeight; 2646 let buttonChild = children[this.buttonIndex]; 2647 let buttonMeasureResult = buttonChild.measure(constraint); 2648 this.buttonHeight = buttonMeasureResult.height; 2649 height += this.buttonHeight; 2650 let contentChild = children[this.contentIndex]; 2651 let contentConstraint = { 2652 maxWidth: constraint.maxWidth, 2653 maxHeight: Number(constraint.maxHeight) - height 2654 }; 2655 let contentMeasureResult = contentChild.measure(contentConstraint); 2656 height += contentMeasureResult.height; 2657 sizeResult.height = height; 2658 return sizeResult; 2659 } 2660 2661 initialRender() { 2662 this.dialogBuilder.bind(this)(); 2663 } 2664 2665 rerender() { 2666 this.updateDirtyElements(); 2667 } 2668} 2669 2670class CustomDialogContentComponent extends ViewPU { 2671 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 2672 super(parent, __localStorage, elmtId, extraInfo); 2673 if (typeof paramsLambda === 'function') { 2674 this.paramsGenerator_ = paramsLambda; 2675 } 2676 this.controller = undefined; 2677 this.primaryTitle = undefined; 2678 this.secondaryTitle = undefined; 2679 this.localizedContentAreaPadding = undefined; 2680 this.contentBuilder = this.defaultContentBuilder; 2681 this.buttons = undefined; 2682 this.contentAreaPadding = undefined; 2683 this.keyIndex = 0; 2684 this.theme = new CustomThemeImpl({}); 2685 this.themeColorMode = ThemeColorMode.SYSTEM; 2686 this.__minContentHeight = new SynchedPropertySimpleTwoWayPU(params.minContentHeight, this, 'minContentHeight'); 2687 this.__titleHeight = new ObservedPropertySimplePU(0, this, 'titleHeight'); 2688 this.__buttonHeight = new ObservedPropertySimplePU(0, this, 'buttonHeight'); 2689 this.__contentMaxHeight = new ObservedPropertyObjectPU('100%', this, 'contentMaxHeight'); 2690 this.__fontSizeScale = new SynchedPropertySimpleTwoWayPU(params.fontSizeScale, this, 'fontSizeScale'); 2691 this.__customStyle = new ObservedPropertySimplePU(undefined, this, 'customStyle'); 2692 this.__buttonMaxFontSize = new ObservedPropertyObjectPU(`${BODY_L}fp`, this, 'buttonMaxFontSize'); 2693 this.__buttonMinFontSize = new ObservedPropertyObjectPU(9, this, 'buttonMinFontSize'); 2694 this.__primaryTitleMaxFontSize = new ObservedPropertyObjectPU(`${TITLE_S}fp`, this, 'primaryTitleMaxFontSize'); 2695 this.__primaryTitleMinFontSize = new ObservedPropertyObjectPU(`${BODY_L}fp`, this, 'primaryTitleMinFontSize'); 2696 this.__secondaryTitleMaxFontSize = 2697 new ObservedPropertyObjectPU(`${SUBTITLE_SIZE()}fp`, this, 'secondaryTitleMaxFontSize'); 2698 this.__secondaryTitleMinFontSize = 2699 new ObservedPropertyObjectPU(`${BODY_S}fp`, this, 'secondaryTitleMinFontSize'); 2700 this.__primaryTitleFontColorWithTheme = new ObservedPropertyObjectPU({ 2701 'id': -1, 2702 'type': 10001, 2703 params: ['sys.color.font_primary'], 2704 'bundleName': '__harDefaultBundleName__', 2705 'moduleName': '__harDefaultModuleName__' 2706 }, this, 'primaryTitleFontColorWithTheme'); 2707 this.__secondaryTitleFontColorWithTheme = new ObservedPropertyObjectPU({ 2708 'id': -1, 2709 'type': 10001, 2710 params: ['sys.color.font_secondary'], 2711 'bundleName': '__harDefaultBundleName__', 2712 'moduleName': '__harDefaultModuleName__' 2713 }, this, 'secondaryTitleFontColorWithTheme'); 2714 this.__titleTextAlign = new ObservedPropertySimplePU(TextAlign.Center, this, 'titleTextAlign'); 2715 this.__isButtonVertical = new ObservedPropertySimplePU(false, this, 'isButtonVertical'); 2716 this.__titleMinHeight = new ObservedPropertyObjectPU(0, this, 'titleMinHeight'); 2717 this.isFollowingSystemFontScale = false; 2718 this.appMaxFontScale = 3.2; 2719 this.titleIndex = 0; 2720 this.contentIndex = 1; 2721 this.buttonIndex = 2; 2722 this.isHasDefaultFocus = false; 2723 this.isAllFocusFalse = false; 2724 this.setInitiallyProvidedValue(params); 2725 this.finalizeConstruction(); 2726 } 2727 2728 setInitiallyProvidedValue(params) { 2729 if (params.controller !== undefined) { 2730 this.controller = params.controller; 2731 } 2732 if (params.primaryTitle !== undefined) { 2733 this.primaryTitle = params.primaryTitle; 2734 } 2735 if (params.secondaryTitle !== undefined) { 2736 this.secondaryTitle = params.secondaryTitle; 2737 } 2738 if (params.localizedContentAreaPadding !== undefined) { 2739 this.localizedContentAreaPadding = params.localizedContentAreaPadding; 2740 } 2741 if (params.contentBuilder !== undefined) { 2742 this.contentBuilder = params.contentBuilder; 2743 } 2744 if (params.buttons !== undefined) { 2745 this.buttons = params.buttons; 2746 } 2747 if (params.contentAreaPadding !== undefined) { 2748 this.contentAreaPadding = params.contentAreaPadding; 2749 } 2750 if (params.keyIndex !== undefined) { 2751 this.keyIndex = params.keyIndex; 2752 } 2753 if (params.theme !== undefined) { 2754 this.theme = params.theme; 2755 } 2756 if (params.themeColorMode !== undefined) { 2757 this.themeColorMode = params.themeColorMode; 2758 } 2759 if (params.titleHeight !== undefined) { 2760 this.titleHeight = params.titleHeight; 2761 } 2762 if (params.buttonHeight !== undefined) { 2763 this.buttonHeight = params.buttonHeight; 2764 } 2765 if (params.contentMaxHeight !== undefined) { 2766 this.contentMaxHeight = params.contentMaxHeight; 2767 } 2768 if (params.customStyle !== undefined) { 2769 this.customStyle = params.customStyle; 2770 } 2771 if (params.buttonMaxFontSize !== undefined) { 2772 this.buttonMaxFontSize = params.buttonMaxFontSize; 2773 } 2774 if (params.buttonMinFontSize !== undefined) { 2775 this.buttonMinFontSize = params.buttonMinFontSize; 2776 } 2777 if (params.primaryTitleMaxFontSize !== undefined) { 2778 this.primaryTitleMaxFontSize = params.primaryTitleMaxFontSize; 2779 } 2780 if (params.primaryTitleMinFontSize !== undefined) { 2781 this.primaryTitleMinFontSize = params.primaryTitleMinFontSize; 2782 } 2783 if (params.secondaryTitleMaxFontSize !== undefined) { 2784 this.secondaryTitleMaxFontSize = params.secondaryTitleMaxFontSize; 2785 } 2786 if (params.secondaryTitleMinFontSize !== undefined) { 2787 this.secondaryTitleMinFontSize = params.secondaryTitleMinFontSize; 2788 } 2789 if (params.primaryTitleFontColorWithTheme !== undefined) { 2790 this.primaryTitleFontColorWithTheme = params.primaryTitleFontColorWithTheme; 2791 } 2792 if (params.secondaryTitleFontColorWithTheme !== undefined) { 2793 this.secondaryTitleFontColorWithTheme = params.secondaryTitleFontColorWithTheme; 2794 } 2795 if (params.titleTextAlign !== undefined) { 2796 this.titleTextAlign = params.titleTextAlign; 2797 } 2798 if (params.isButtonVertical !== undefined) { 2799 this.isButtonVertical = params.isButtonVertical; 2800 } 2801 if (params.titleMinHeight !== undefined) { 2802 this.titleMinHeight = params.titleMinHeight; 2803 } 2804 if (params.isFollowingSystemFontScale !== undefined) { 2805 this.isFollowingSystemFontScale = params.isFollowingSystemFontScale; 2806 } 2807 if (params.appMaxFontScale !== undefined) { 2808 this.appMaxFontScale = params.appMaxFontScale; 2809 } 2810 if (params.titleIndex !== undefined) { 2811 this.titleIndex = params.titleIndex; 2812 } 2813 if (params.contentIndex !== undefined) { 2814 this.contentIndex = params.contentIndex; 2815 } 2816 if (params.buttonIndex !== undefined) { 2817 this.buttonIndex = params.buttonIndex; 2818 } 2819 if (params.isHasDefaultFocus !== undefined) { 2820 this.isHasDefaultFocus = params.isHasDefaultFocus; 2821 } 2822 if (params.isAllFocusFalse !== undefined) { 2823 this.isAllFocusFalse = params.isAllFocusFalse; 2824 } 2825 } 2826 2827 updateStateVars(params) { 2828 } 2829 2830 purgeVariableDependenciesOnElmtId(rmElmtId) { 2831 this.__minContentHeight.purgeDependencyOnElmtId(rmElmtId); 2832 this.__titleHeight.purgeDependencyOnElmtId(rmElmtId); 2833 this.__buttonHeight.purgeDependencyOnElmtId(rmElmtId); 2834 this.__contentMaxHeight.purgeDependencyOnElmtId(rmElmtId); 2835 this.__fontSizeScale.purgeDependencyOnElmtId(rmElmtId); 2836 this.__customStyle.purgeDependencyOnElmtId(rmElmtId); 2837 this.__buttonMaxFontSize.purgeDependencyOnElmtId(rmElmtId); 2838 this.__buttonMinFontSize.purgeDependencyOnElmtId(rmElmtId); 2839 this.__primaryTitleMaxFontSize.purgeDependencyOnElmtId(rmElmtId); 2840 this.__primaryTitleMinFontSize.purgeDependencyOnElmtId(rmElmtId); 2841 this.__secondaryTitleMaxFontSize.purgeDependencyOnElmtId(rmElmtId); 2842 this.__secondaryTitleMinFontSize.purgeDependencyOnElmtId(rmElmtId); 2843 this.__primaryTitleFontColorWithTheme.purgeDependencyOnElmtId(rmElmtId); 2844 this.__secondaryTitleFontColorWithTheme.purgeDependencyOnElmtId(rmElmtId); 2845 this.__titleTextAlign.purgeDependencyOnElmtId(rmElmtId); 2846 this.__isButtonVertical.purgeDependencyOnElmtId(rmElmtId); 2847 this.__titleMinHeight.purgeDependencyOnElmtId(rmElmtId); 2848 } 2849 2850 aboutToBeDeleted() { 2851 this.__minContentHeight.aboutToBeDeleted(); 2852 this.__titleHeight.aboutToBeDeleted(); 2853 this.__buttonHeight.aboutToBeDeleted(); 2854 this.__contentMaxHeight.aboutToBeDeleted(); 2855 this.__fontSizeScale.aboutToBeDeleted(); 2856 this.__customStyle.aboutToBeDeleted(); 2857 this.__buttonMaxFontSize.aboutToBeDeleted(); 2858 this.__buttonMinFontSize.aboutToBeDeleted(); 2859 this.__primaryTitleMaxFontSize.aboutToBeDeleted(); 2860 this.__primaryTitleMinFontSize.aboutToBeDeleted(); 2861 this.__secondaryTitleMaxFontSize.aboutToBeDeleted(); 2862 this.__secondaryTitleMinFontSize.aboutToBeDeleted(); 2863 this.__primaryTitleFontColorWithTheme.aboutToBeDeleted(); 2864 this.__secondaryTitleFontColorWithTheme.aboutToBeDeleted(); 2865 this.__titleTextAlign.aboutToBeDeleted(); 2866 this.__isButtonVertical.aboutToBeDeleted(); 2867 this.__titleMinHeight.aboutToBeDeleted(); 2868 SubscriberManager.Get().delete(this.id__()); 2869 this.aboutToBeDeletedInternal(); 2870 } 2871 2872 get minContentHeight() { 2873 return this.__minContentHeight.get(); 2874 } 2875 2876 set minContentHeight(newValue) { 2877 this.__minContentHeight.set(newValue); 2878 } 2879 2880 defaultContentBuilder(parent = null) { 2881 } 2882 2883 get titleHeight() { 2884 return this.__titleHeight.get(); 2885 } 2886 2887 set titleHeight(newValue) { 2888 this.__titleHeight.set(newValue); 2889 } 2890 2891 get buttonHeight() { 2892 return this.__buttonHeight.get(); 2893 } 2894 2895 set buttonHeight(newValue) { 2896 this.__buttonHeight.set(newValue); 2897 } 2898 2899 get contentMaxHeight() { 2900 return this.__contentMaxHeight.get(); 2901 } 2902 2903 set contentMaxHeight(newValue) { 2904 this.__contentMaxHeight.set(newValue); 2905 } 2906 2907 get fontSizeScale() { 2908 return this.__fontSizeScale.get(); 2909 } 2910 2911 set fontSizeScale(newValue) { 2912 this.__fontSizeScale.set(newValue); 2913 } 2914 2915 get customStyle() { 2916 return this.__customStyle.get(); 2917 } 2918 2919 set customStyle(newValue) { 2920 this.__customStyle.set(newValue); 2921 } 2922 2923 get buttonMaxFontSize() { 2924 return this.__buttonMaxFontSize.get(); 2925 } 2926 2927 set buttonMaxFontSize(newValue) { 2928 this.__buttonMaxFontSize.set(newValue); 2929 } 2930 2931 get buttonMinFontSize() { 2932 return this.__buttonMinFontSize.get(); 2933 } 2934 2935 set buttonMinFontSize(newValue) { 2936 this.__buttonMinFontSize.set(newValue); 2937 } 2938 2939 get primaryTitleMaxFontSize() { 2940 return this.__primaryTitleMaxFontSize.get(); 2941 } 2942 2943 set primaryTitleMaxFontSize(newValue) { 2944 this.__primaryTitleMaxFontSize.set(newValue); 2945 } 2946 2947 get primaryTitleMinFontSize() { 2948 return this.__primaryTitleMinFontSize.get(); 2949 } 2950 2951 set primaryTitleMinFontSize(newValue) { 2952 this.__primaryTitleMinFontSize.set(newValue); 2953 } 2954 2955 get secondaryTitleMaxFontSize() { 2956 return this.__secondaryTitleMaxFontSize.get(); 2957 } 2958 2959 set secondaryTitleMaxFontSize(newValue) { 2960 this.__secondaryTitleMaxFontSize.set(newValue); 2961 } 2962 2963 get secondaryTitleMinFontSize() { 2964 return this.__secondaryTitleMinFontSize.get(); 2965 } 2966 2967 set secondaryTitleMinFontSize(newValue) { 2968 this.__secondaryTitleMinFontSize.set(newValue); 2969 } 2970 2971 get primaryTitleFontColorWithTheme() { 2972 return this.__primaryTitleFontColorWithTheme.get(); 2973 } 2974 2975 set primaryTitleFontColorWithTheme(newValue) { 2976 this.__primaryTitleFontColorWithTheme.set(newValue); 2977 } 2978 2979 get secondaryTitleFontColorWithTheme() { 2980 return this.__secondaryTitleFontColorWithTheme.get(); 2981 } 2982 2983 set secondaryTitleFontColorWithTheme(newValue) { 2984 this.__secondaryTitleFontColorWithTheme.set(newValue); 2985 } 2986 2987 get titleTextAlign() { 2988 return this.__titleTextAlign.get(); 2989 } 2990 2991 set titleTextAlign(newValue) { 2992 this.__titleTextAlign.set(newValue); 2993 } 2994 2995 get isButtonVertical() { 2996 return this.__isButtonVertical.get(); 2997 } 2998 2999 set isButtonVertical(newValue) { 3000 this.__isButtonVertical.set(newValue); 3001 } 3002 3003 get titleMinHeight() { 3004 return this.__titleMinHeight.get(); 3005 } 3006 3007 set titleMinHeight(newValue) { 3008 this.__titleMinHeight.set(newValue); 3009 } 3010 3011 initialRender() { 3012 this.observeComponentCreation2((elmtId, isInitialRender) => { 3013 WithTheme.create({ theme: this.theme, colorMode: this.themeColorMode }); 3014 }, WithTheme); 3015 this.observeComponentCreation2((elmtId, isInitialRender) => { 3016 Scroll.create(); 3017 Scroll.edgeEffect(EdgeEffect.None, { alwaysEnabled: false }); 3018 Scroll.backgroundColor(this.themeColorMode === ThemeColorMode.SYSTEM || undefined ? 3019 Color.Transparent : { 3020 'id': -1, 3021 'type': 10001, 3022 params: ['sys.color.comp_background_primary'], 3023 'bundleName': '__harDefaultBundleName__', 3024 'moduleName': '__harDefaultModuleName__' 3025 }); 3026 }, Scroll); 3027 this.observeComponentCreation2((elmtId, isInitialRender) => { 3028 Column.create(); 3029 Column.constraintSize({ maxHeight: this.contentMaxHeight }); 3030 Column.backgroundBlurStyle(this.customStyle ? BlurStyle.Thick : BlurStyle.NONE); 3031 Column.borderRadius(this.customStyle ? { 3032 'id': -1, 3033 'type': 10002, 3034 params: ['sys.float.ohos_id_corner_radius_dialog'], 3035 'bundleName': '__harDefaultBundleName__', 3036 'moduleName': '__harDefaultModuleName__' 3037 } : 0); 3038 Column.margin(this.customStyle ? { 3039 start: LengthMetrics.resource({ 3040 'id': -1, 3041 'type': 10002, 3042 params: ['sys.float.ohos_id_dialog_margin_start'], 3043 'bundleName': '__harDefaultBundleName__', 3044 'moduleName': '__harDefaultModuleName__' 3045 }), 3046 end: LengthMetrics.resource({ 3047 'id': -1, 3048 'type': 10002, 3049 params: ['sys.float.ohos_id_dialog_margin_end'], 3050 'bundleName': '__harDefaultBundleName__', 3051 'moduleName': '__harDefaultModuleName__' 3052 }), 3053 bottom: LengthMetrics.resource({ 3054 'id': -1, 3055 'type': 10002, 3056 params: ['sys.float.ohos_id_dialog_margin_bottom'], 3057 'bundleName': '__harDefaultBundleName__', 3058 'moduleName': '__harDefaultModuleName__' 3059 }), 3060 } : { left: 0, right: 0, bottom: 0 }); 3061 Column.backgroundColor(this.customStyle ? { 3062 'id': -1, 3063 'type': 10001, 3064 params: ['sys.color.ohos_id_color_dialog_bg'], 3065 'bundleName': '__harDefaultBundleName__', 3066 'moduleName': '__harDefaultModuleName__' 3067 } : Color.Transparent); 3068 }, Column); 3069 { 3070 this.observeComponentCreation2((elmtId, isInitialRender) => { 3071 if (isInitialRender) { 3072 let componentCall = new CustomDialogLayout(this, { 3073 buttonHeight: this.__buttonHeight, 3074 titleHeight: this.__titleHeight, 3075 titleMinHeight: this.__titleMinHeight, 3076 dialogBuilder: () => { 3077 this.observeComponentCreation2((elmtId, isInitialRender) => { 3078 ForEach.create(); 3079 const forEachItemGenFunction = _item => { 3080 const index = _item; 3081 this.observeComponentCreation2((elmtId, isInitialRender) => { 3082 If.create(); 3083 if (index === this.titleIndex) { 3084 this.ifElseBranchUpdateFunction(0, () => { 3085 this.observeComponentCreation2((elmtId, isInitialRender) => { 3086 WithTheme.create({ 3087 theme: this.theme, 3088 colorMode: this.themeColorMode 3089 }); 3090 }, WithTheme); 3091 this.titleBuilder.bind(this)(); 3092 WithTheme.pop(); 3093 }); 3094 } else if (index === this.contentIndex) { 3095 this.ifElseBranchUpdateFunction(1, () => { 3096 this.observeComponentCreation2((elmtId, isInitialRender) => { 3097 Column.create(); 3098 Column.padding(this.getContentPadding()); 3099 }, Column); 3100 this.observeComponentCreation2((elmtId, isInitialRender) => { 3101 WithTheme.create({ 3102 theme: this.theme, 3103 colorMode: this.themeColorMode 3104 }); 3105 }, WithTheme); 3106 this.contentBuilder.bind(this)(); 3107 WithTheme.pop(); 3108 Column.pop(); 3109 }); 3110 } else { 3111 this.ifElseBranchUpdateFunction(2, () => { 3112 this.observeComponentCreation2((elmtId, isInitialRender) => { 3113 WithTheme.create({ 3114 theme: this.theme, 3115 colorMode: this.themeColorMode 3116 }); 3117 }, WithTheme); 3118 this.ButtonBuilder.bind(this)(); 3119 WithTheme.pop(); 3120 }); 3121 } 3122 }, If); 3123 If.pop(); 3124 }; 3125 this.forEachUpdateFunction(elmtId, 3126 [this.titleIndex, this.contentIndex, this.buttonIndex], forEachItemGenFunction); 3127 }, ForEach); 3128 ForEach.pop(); 3129 } 3130 }, undefined, elmtId, () => { 3131 }, { page: 'library/src/main/ets/components/dialog.ets', line: 1131, col: 11 }); 3132 ViewPU.create(componentCall); 3133 let paramsLambda = () => { 3134 return { 3135 buttonHeight: this.buttonHeight, 3136 titleHeight: this.titleHeight, 3137 titleMinHeight: this.titleMinHeight, 3138 dialogBuilder: () => { 3139 this.observeComponentCreation2((elmtId, isInitialRender) => { 3140 ForEach.create(); 3141 const forEachItemGenFunction = _item => { 3142 const index = _item; 3143 this.observeComponentCreation2((elmtId, isInitialRender) => { 3144 If.create(); 3145 if (index === this.titleIndex) { 3146 this.ifElseBranchUpdateFunction(0, () => { 3147 this.observeComponentCreation2((elmtId, isInitialRender) => { 3148 WithTheme.create({ 3149 theme: this.theme, 3150 colorMode: this.themeColorMode 3151 }); 3152 }, WithTheme); 3153 this.titleBuilder.bind(this)(); 3154 WithTheme.pop(); 3155 }); 3156 } else if (index === this.contentIndex) { 3157 this.ifElseBranchUpdateFunction(1, () => { 3158 this.observeComponentCreation2((elmtId, isInitialRender) => { 3159 Column.create(); 3160 Column.padding(this.getContentPadding()); 3161 }, Column); 3162 this.observeComponentCreation2((elmtId, isInitialRender) => { 3163 WithTheme.create({ 3164 theme: this.theme, 3165 colorMode: this.themeColorMode 3166 }); 3167 }, WithTheme); 3168 this.contentBuilder.bind(this)(); 3169 WithTheme.pop(); 3170 Column.pop(); 3171 }); 3172 } else { 3173 this.ifElseBranchUpdateFunction(2, () => { 3174 this.observeComponentCreation2((elmtId, isInitialRender) => { 3175 WithTheme.create({ 3176 theme: this.theme, 3177 colorMode: this.themeColorMode 3178 }); 3179 }, WithTheme); 3180 this.ButtonBuilder.bind(this)(); 3181 WithTheme.pop(); 3182 }); 3183 } 3184 }, If); 3185 If.pop(); 3186 }; 3187 this.forEachUpdateFunction(elmtId, 3188 [this.titleIndex, this.contentIndex, this.buttonIndex], forEachItemGenFunction); 3189 }, ForEach); 3190 ForEach.pop(); 3191 } 3192 }; 3193 }; 3194 componentCall.paramsGenerator_ = paramsLambda; 3195 } else { 3196 this.updateStateVarsOfChildByElmtId(elmtId, {}); 3197 } 3198 }, { name: 'CustomDialogLayout' }); 3199 } 3200 Column.pop(); 3201 Scroll.pop(); 3202 WithTheme.pop(); 3203 } 3204 3205 onMeasureSize(selfLayoutInfo, children, constraint) { 3206 let sizeResult = { width: selfLayoutInfo.width, height: selfLayoutInfo.height }; 3207 let maxWidth = Number(constraint.maxWidth); 3208 let maxHeight = Number(constraint.maxHeight); 3209 this.fontSizeScale = this.updateFontScale(); 3210 this.updateFontSize(); 3211 this.isButtonVertical = this.isVerticalAlignButton(maxWidth - BUTTON_HORIZONTAL_MARGIN * 2); 3212 this.titleMinHeight = this.getTitleAreaMinHeight(); 3213 let height = 0; 3214 children.forEach((child) => { 3215 this.contentMaxHeight = '100%'; 3216 let measureResult = child.measure(constraint); 3217 if (maxHeight - this.buttonHeight - this.titleHeight < this.minContentHeight) { 3218 this.contentMaxHeight = MAX_CONTENT_HEIGHT; 3219 measureResult = child.measure(constraint); 3220 } 3221 height += measureResult.height; 3222 }); 3223 sizeResult.height = height; 3224 sizeResult.width = maxWidth; 3225 return sizeResult; 3226 } 3227 3228 aboutToAppear() { 3229 let uiContext = this.getUIContext(); 3230 this.isFollowingSystemFontScale = uiContext.isFollowingSystemFontScale(); 3231 this.appMaxFontScale = uiContext.getMaxFontScale(); 3232 this.fontSizeScale = this.updateFontScale(); 3233 if (this.controller && this.customStyle === undefined) { 3234 let customController = this.controller; 3235 if (customController.arg_ && customController.arg_.customStyle && 3236 customController.arg_.customStyle === true) { 3237 this.customStyle = true; 3238 } 3239 } 3240 if (this.customStyle === undefined) { 3241 this.customStyle = false; 3242 } 3243 this.primaryTitleFontColorWithTheme = this.theme?.colors?.fontPrimary ? 3244 this.theme.colors.fontPrimary : { 3245 'id': -1, 3246 'type': 10001, 3247 params: ['sys.color.font_primary'], 3248 'bundleName': '__harDefaultBundleName__', 3249 'moduleName': '__harDefaultModuleName__' 3250 }; 3251 this.secondaryTitleFontColorWithTheme = this.theme?.colors?.fontSecondary ? 3252 this.theme.colors.fontSecondary : { 3253 'id': -1, 3254 'type': 10001, 3255 params: ['sys.color.font_secondary'], 3256 'bundleName': '__harDefaultBundleName__', 3257 'moduleName': '__harDefaultModuleName__' 3258 }; 3259 this.initTitleTextAlign(); 3260 this.setDefaultFocusState(this.buttons); 3261 } 3262 3263 updateFontSize() { 3264 if (this.fontSizeScale > MAX_FONT_SCALE) { 3265 this.buttonMaxFontSize = BUTTON_MAX_FONT_SIZE() * MAX_FONT_SCALE + 'vp'; 3266 this.buttonMinFontSize = BUTTON_MIN_FONT_SIZE() * MAX_FONT_SCALE + 'vp'; 3267 } else { 3268 this.buttonMaxFontSize = BUTTON_MAX_FONT_SIZE() + 'fp'; 3269 this.buttonMinFontSize = BUTTON_MIN_FONT_SIZE() + 'fp'; 3270 } 3271 } 3272 3273 updateFontScale() { 3274 try { 3275 let uiContext = this.getUIContext(); 3276 let systemFontScale = uiContext.getHostContext()?.config?.fontSizeScale ?? 1; 3277 if (!this.isFollowingSystemFontScale) { 3278 return 1; 3279 } 3280 return Math.min(systemFontScale, this.appMaxFontScale); 3281 } catch (exception) { 3282 let code = exception.code; 3283 let message = exception.message; 3284 hilog.error(0x3900, 'Ace', `Faild to init fontsizescale info,cause, code: ${code}, message: ${message}`); 3285 return 1; 3286 } 3287 } 3288 3289 /** 3290 * get dialog content padding 3291 * 3292 * @returns content padding 3293 */ 3294 getContentPadding() { 3295 if (this.localizedContentAreaPadding) { 3296 return this.localizedContentAreaPadding; 3297 } 3298 if (this.contentAreaPadding) { 3299 return this.contentAreaPadding; 3300 } 3301 if ((this.primaryTitle || this.secondaryTitle) && this.buttons && this.buttons.length > 0) { 3302 return { 3303 top: 0, 3304 right: { 3305 'id': -1, 3306 'type': 10002, 3307 params: ['sys.float.alert_content_default_padding'], 3308 'bundleName': '__harDefaultBundleName__', 3309 'moduleName': '__harDefaultModuleName__' 3310 }, 3311 bottom: 0, 3312 left: { 3313 'id': -1, 3314 'type': 10002, 3315 params: ['sys.float.alert_content_default_padding'], 3316 'bundleName': '__harDefaultBundleName__', 3317 'moduleName': '__harDefaultModuleName__' 3318 }, 3319 }; 3320 } else if (this.primaryTitle || this.secondaryTitle) { 3321 return { 3322 top: 0, 3323 right: { 3324 'id': -1, 3325 'type': 10002, 3326 params: ['sys.float.alert_content_default_padding'], 3327 'bundleName': '__harDefaultBundleName__', 3328 'moduleName': '__harDefaultModuleName__' 3329 }, 3330 bottom: { 3331 'id': -1, 3332 'type': 10002, 3333 params: ['sys.float.alert_content_default_padding'], 3334 'bundleName': '__harDefaultBundleName__', 3335 'moduleName': '__harDefaultModuleName__' 3336 }, 3337 left: { 3338 'id': -1, 3339 'type': 10002, 3340 params: ['sys.float.alert_content_default_padding'], 3341 'bundleName': '__harDefaultBundleName__', 3342 'moduleName': '__harDefaultModuleName__' 3343 }, 3344 }; 3345 } else if (this.buttons && this.buttons.length > 0) { 3346 return { 3347 top: { 3348 'id': -1, 3349 'type': 10002, 3350 params: ['sys.float.alert_content_default_padding'], 3351 'bundleName': '__harDefaultBundleName__', 3352 'moduleName': '__harDefaultModuleName__' 3353 }, 3354 right: { 3355 'id': -1, 3356 'type': 10002, 3357 params: ['sys.float.alert_content_default_padding'], 3358 'bundleName': '__harDefaultBundleName__', 3359 'moduleName': '__harDefaultModuleName__' 3360 }, 3361 bottom: 0, 3362 left: { 3363 'id': -1, 3364 'type': 10002, 3365 params: ['sys.float.alert_content_default_padding'], 3366 'bundleName': '__harDefaultBundleName__', 3367 'moduleName': '__harDefaultModuleName__' 3368 }, 3369 }; 3370 } else { 3371 return { 3372 top: { 3373 'id': -1, 3374 'type': 10002, 3375 params: ['sys.float.alert_content_default_padding'], 3376 'bundleName': '__harDefaultBundleName__', 3377 'moduleName': '__harDefaultModuleName__' 3378 }, 3379 right: { 3380 'id': -1, 3381 'type': 10002, 3382 params: ['sys.float.alert_content_default_padding'], 3383 'bundleName': '__harDefaultBundleName__', 3384 'moduleName': '__harDefaultModuleName__' 3385 }, 3386 bottom: { 3387 'id': -1, 3388 'type': 10002, 3389 params: ['sys.float.alert_content_default_padding'], 3390 'bundleName': '__harDefaultBundleName__', 3391 'moduleName': '__harDefaultModuleName__' 3392 }, 3393 left: { 3394 'id': -1, 3395 'type': 10002, 3396 params: ['sys.float.alert_content_default_padding'], 3397 'bundleName': '__harDefaultBundleName__', 3398 'moduleName': '__harDefaultModuleName__' 3399 }, 3400 }; 3401 } 3402 } 3403 3404 titleBuilder(parent = null) { 3405 this.observeComponentCreation2((elmtId, isInitialRender) => { 3406 Column.create(); 3407 Column.justifyContent(FlexAlign.Center); 3408 Column.width('100%'); 3409 Column.padding(this.getTitleAreaPadding()); 3410 }, Column); 3411 this.observeComponentCreation2((elmtId, isInitialRender) => { 3412 Row.create(); 3413 Row.width('100%'); 3414 }, Row); 3415 this.observeComponentCreation2((elmtId, isInitialRender) => { 3416 Text.create(this.primaryTitle); 3417 Text.fontWeight(TITLE_FONT_WEIGHT()); 3418 Text.fontColor(ObservedObject.GetRawObject(this.primaryTitleFontColorWithTheme)); 3419 Text.textAlign(this.titleTextAlign); 3420 Text.maxFontSize(ObservedObject.GetRawObject(this.primaryTitleMaxFontSize)); 3421 Text.minFontSize(ObservedObject.GetRawObject(this.primaryTitleMinFontSize)); 3422 Text.maxFontScale(Math.min(this.appMaxFontScale, MAX_FONT_SCALE)); 3423 Text.maxLines(TITLE_MAX_LINES); 3424 Text.heightAdaptivePolicy(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST); 3425 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 3426 Text.width('100%'); 3427 }, Text); 3428 Text.pop(); 3429 Row.pop(); 3430 this.observeComponentCreation2((elmtId, isInitialRender) => { 3431 If.create(); 3432 if (this.primaryTitle && this.secondaryTitle) { 3433 this.ifElseBranchUpdateFunction(0, () => { 3434 this.observeComponentCreation2((elmtId, isInitialRender) => { 3435 Row.create(); 3436 Row.height({ 3437 'id': -1, 3438 'type': 10002, 3439 params: ['sys.float.padding_level1'], 3440 'bundleName': '__harDefaultBundleName__', 3441 'moduleName': '__harDefaultModuleName__' 3442 }); 3443 }, Row); 3444 Row.pop(); 3445 }); 3446 } else { 3447 this.ifElseBranchUpdateFunction(1, () => { 3448 }); 3449 } 3450 }, If); 3451 If.pop(); 3452 this.observeComponentCreation2((elmtId, isInitialRender) => { 3453 Row.create(); 3454 Row.width('100%'); 3455 }, Row); 3456 this.observeComponentCreation2((elmtId, isInitialRender) => { 3457 Text.create(this.secondaryTitle); 3458 Text.fontWeight(FontWeight.Regular); 3459 Text.fontColor(ObservedObject.GetRawObject(this.secondaryTitleFontColorWithTheme)); 3460 Text.textAlign(this.titleTextAlign); 3461 Text.maxFontSize(ObservedObject.GetRawObject(this.secondaryTitleMaxFontSize)); 3462 Text.minFontSize(ObservedObject.GetRawObject(this.secondaryTitleMinFontSize)); 3463 Text.maxFontScale(Math.min(this.appMaxFontScale, MAX_FONT_SCALE)); 3464 Text.maxLines(TITLE_MAX_LINES); 3465 Text.heightAdaptivePolicy(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST); 3466 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 3467 Text.width('100%'); 3468 }, Text); 3469 Text.pop(); 3470 Row.pop(); 3471 Column.pop(); 3472 } 3473 3474 /** 3475 * get title area padding 3476 * 3477 * @returns padding 3478 */ 3479 getTitleAreaPadding() { 3480 if (this.primaryTitle || this.secondaryTitle) { 3481 return { 3482 top: { 3483 'id': -1, 3484 'type': 10002, 3485 params: ['sys.float.alert_title_padding_top'], 3486 'bundleName': '__harDefaultBundleName__', 3487 'moduleName': '__harDefaultModuleName__' 3488 }, 3489 right: { 3490 'id': -1, 3491 'type': 10002, 3492 params: ['sys.float.alert_title_padding_right'], 3493 'bundleName': '__harDefaultBundleName__', 3494 'moduleName': '__harDefaultModuleName__' 3495 }, 3496 left: { 3497 'id': -1, 3498 'type': 10002, 3499 params: ['sys.float.alert_title_padding_left'], 3500 'bundleName': '__harDefaultBundleName__', 3501 'moduleName': '__harDefaultModuleName__' 3502 }, 3503 bottom: { 3504 'id': -1, 3505 'type': 10002, 3506 params: ['sys.float.alert_title_padding_bottom'], 3507 'bundleName': '__harDefaultBundleName__', 3508 'moduleName': '__harDefaultModuleName__' 3509 }, 3510 }; 3511 } 3512 return { 3513 top: 0, 3514 right: { 3515 'id': -1, 3516 'type': 10002, 3517 params: ['sys.float.alert_title_padding_right'], 3518 'bundleName': '__harDefaultBundleName__', 3519 'moduleName': '__harDefaultModuleName__' 3520 }, 3521 left: { 3522 'id': -1, 3523 'type': 10002, 3524 params: ['sys.float.alert_title_padding_left'], 3525 'bundleName': '__harDefaultBundleName__', 3526 'moduleName': '__harDefaultModuleName__' 3527 }, 3528 bottom: 0, 3529 }; 3530 } 3531 3532 /** 3533 * get tile TextAlign 3534 * @returns TextAlign 3535 */ 3536 initTitleTextAlign() { 3537 let textAlign = ALERT_TITLE_ALIGNMENT(); 3538 if (textAlign === TextAlign.Start) { 3539 this.titleTextAlign = TextAlign.Start; 3540 } else if (textAlign === TextAlign.Center) { 3541 this.titleTextAlign = TextAlign.Center; 3542 } else if (textAlign === TextAlign.End) { 3543 this.titleTextAlign = TextAlign.End; 3544 } else if (textAlign === TextAlign.JUSTIFY) { 3545 this.titleTextAlign = TextAlign.JUSTIFY; 3546 } else { 3547 this.titleTextAlign = TextAlign.Center; 3548 } 3549 } 3550 3551 /** 3552 * get title area min height 3553 * 3554 * @returns min height 3555 */ 3556 getTitleAreaMinHeight() { 3557 if (this.secondaryTitle) { 3558 return { 3559 'id': -1, 3560 'type': 10002, 3561 params: ['sys.float.alert_title_secondary_height'], 3562 'bundleName': '__harDefaultBundleName__', 3563 'moduleName': '__harDefaultModuleName__' 3564 }; 3565 } else if (this.primaryTitle) { 3566 return { 3567 'id': -1, 3568 'type': 10002, 3569 params: ['sys.float.alert_title_primary_height'], 3570 'bundleName': '__harDefaultBundleName__', 3571 'moduleName': '__harDefaultModuleName__' 3572 }; 3573 } else { 3574 return 0; 3575 } 3576 } 3577 3578 /** 3579 * set state of button focus 3580 */ 3581 setDefaultFocusState(buttonList) { 3582 if (!buttonList) { 3583 return; 3584 } 3585 let falseNum = 0; 3586 buttonList.forEach((button) => { 3587 // 遍历查询按钮中存在是否存在默认按钮 3588 if (button.defaultFocus) { 3589 this.isHasDefaultFocus = true; 3590 } 3591 if (button.defaultFocus === false) { 3592 falseNum++; 3593 } 3594 }); 3595 // 所有按钮defaultFocus都设置为false 3596 if (falseNum === buttonList.length) { 3597 this.isAllFocusFalse = true; 3598 } 3599 } 3600 3601 ButtonBuilder(parent = null) { 3602 this.observeComponentCreation2((elmtId, isInitialRender) => { 3603 Column.create(); 3604 Column.width('100%'); 3605 Column.padding(this.getOperationAreaPadding()); 3606 }, Column); 3607 this.observeComponentCreation2((elmtId, isInitialRender) => { 3608 If.create(); 3609 if (this.buttons && this.buttons.length > 0) { 3610 this.ifElseBranchUpdateFunction(0, () => { 3611 this.observeComponentCreation2((elmtId, isInitialRender) => { 3612 If.create(); 3613 if (this.isButtonVertical) { 3614 this.ifElseBranchUpdateFunction(0, () => { 3615 this.buildVerticalAlignButtons.bind(this)(); 3616 }); 3617 } else { 3618 this.ifElseBranchUpdateFunction(1, () => { 3619 this.buildHorizontalAlignButtons.bind(this)(); 3620 }); 3621 } 3622 }, If); 3623 If.pop(); 3624 }); 3625 } else { 3626 this.ifElseBranchUpdateFunction(1, () => { 3627 }); 3628 } 3629 }, If); 3630 If.pop(); 3631 Column.pop(); 3632 } 3633 3634 /** 3635 * get operation area padding 3636 * 3637 * @returns padding 3638 */ 3639 getOperationAreaPadding() { 3640 if (this.isButtonVertical) { 3641 return { 3642 top: { 3643 'id': -1, 3644 'type': 10002, 3645 params: ['sys.float.alert_button_top_padding'], 3646 'bundleName': '__harDefaultBundleName__', 3647 'moduleName': '__harDefaultModuleName__' 3648 }, 3649 right: { 3650 'id': -1, 3651 'type': 10002, 3652 params: ['sys.float.alert_right_padding_vertical'], 3653 'bundleName': '__harDefaultBundleName__', 3654 'moduleName': '__harDefaultModuleName__' 3655 }, 3656 left: { 3657 'id': -1, 3658 'type': 10002, 3659 params: ['sys.float.alert_left_padding_vertical'], 3660 'bundleName': '__harDefaultBundleName__', 3661 'moduleName': '__harDefaultModuleName__' 3662 }, 3663 bottom: { 3664 'id': -1, 3665 'type': 10002, 3666 params: ['sys.float.alert_button_bottom_padding_vertical'], 3667 'bundleName': '__harDefaultBundleName__', 3668 'moduleName': '__harDefaultModuleName__' 3669 }, 3670 }; 3671 } 3672 return { 3673 top: { 3674 'id': -1, 3675 'type': 10002, 3676 params: ['sys.float.alert_button_top_padding'], 3677 'bundleName': '__harDefaultBundleName__', 3678 'moduleName': '__harDefaultModuleName__' 3679 }, 3680 right: { 3681 'id': -1, 3682 'type': 10002, 3683 params: ['sys.float.alert_right_padding_horizontal'], 3684 'bundleName': '__harDefaultBundleName__', 3685 'moduleName': '__harDefaultModuleName__' 3686 }, 3687 left: { 3688 'id': -1, 3689 'type': 10002, 3690 params: ['sys.float.alert_left_padding_horizontal'], 3691 'bundleName': '__harDefaultBundleName__', 3692 'moduleName': '__harDefaultModuleName__' 3693 }, 3694 bottom: { 3695 'id': -1, 3696 'type': 10002, 3697 params: ['sys.float.alert_button_bottom_padding_horizontal'], 3698 'bundleName': '__harDefaultBundleName__', 3699 'moduleName': '__harDefaultModuleName__' 3700 }, 3701 }; 3702 } 3703 3704 buildSingleButton(buttonOptions, parent = null) { 3705 this.observeComponentCreation2((elmtId, isInitialRender) => { 3706 If.create(); 3707 if (this.isNewPropertiesHighPriority(buttonOptions)) { 3708 this.ifElseBranchUpdateFunction(0, () => { 3709 this.observeComponentCreation2((elmtId, isInitialRender) => { 3710 Button.createWithLabel(buttonOptions.value); 3711 __Button__setButtonProperties(buttonOptions, this.isHasDefaultFocus, this.isAllFocusFalse, 3712 this.controller); 3713 Button.role(buttonOptions.role ?? ButtonRole.NORMAL); 3714 Button.key(`advanced_dialog_button_${this.keyIndex++}`); 3715 Button.labelStyle({ 3716 maxLines: 1, 3717 overflow: IS_FADEOUT_ENABLE() ? TextOverflow.MARQUEE : TextOverflow.Ellipsis, 3718 maxFontSize: this.buttonMaxFontSize, 3719 minFontSize: this.buttonMinFontSize 3720 }); 3721 }, Button); 3722 Button.pop(); 3723 }); 3724 } else if (buttonOptions.background !== undefined && buttonOptions.fontColor !== undefined) { 3725 this.ifElseBranchUpdateFunction(1, () => { 3726 this.observeComponentCreation2((elmtId, isInitialRender) => { 3727 Button.createWithLabel(buttonOptions.value); 3728 __Button__setButtonProperties(buttonOptions, this.isHasDefaultFocus, this.isAllFocusFalse, 3729 this.controller); 3730 Button.backgroundColor(buttonOptions.background); 3731 Button.fontColor(buttonOptions.fontColor); 3732 Button.key(`advanced_dialog_button_${this.keyIndex++}`); 3733 Button.labelStyle({ 3734 maxLines: 1, 3735 overflow: IS_FADEOUT_ENABLE() ? TextOverflow.MARQUEE : TextOverflow.Ellipsis, 3736 maxFontSize: this.buttonMaxFontSize, 3737 minFontSize: this.buttonMinFontSize 3738 }); 3739 }, Button); 3740 Button.pop(); 3741 }); 3742 } else if (buttonOptions.background !== undefined) { 3743 this.ifElseBranchUpdateFunction(2, () => { 3744 this.observeComponentCreation2((elmtId, isInitialRender) => { 3745 Button.createWithLabel(buttonOptions.value); 3746 __Button__setButtonProperties(buttonOptions, this.isHasDefaultFocus, this.isAllFocusFalse, 3747 this.controller); 3748 Button.backgroundColor(buttonOptions.background); 3749 Button.key(`advanced_dialog_button_${this.keyIndex++}`); 3750 Button.labelStyle({ 3751 maxLines: 1, 3752 overflow: IS_FADEOUT_ENABLE() ? TextOverflow.MARQUEE : TextOverflow.Ellipsis, 3753 maxFontSize: this.buttonMaxFontSize, 3754 minFontSize: this.buttonMinFontSize 3755 }); 3756 }, Button); 3757 Button.pop(); 3758 }); 3759 } else { 3760 this.ifElseBranchUpdateFunction(3, () => { 3761 this.observeComponentCreation2((elmtId, isInitialRender) => { 3762 Button.createWithLabel(buttonOptions.value); 3763 __Button__setButtonProperties(buttonOptions, this.isHasDefaultFocus, this.isAllFocusFalse, 3764 this.controller); 3765 Button.fontColor(buttonOptions.fontColor); 3766 Button.key(`advanced_dialog_button_${this.keyIndex++}`); 3767 Button.labelStyle({ 3768 maxLines: 1, 3769 overflow: IS_FADEOUT_ENABLE() ? TextOverflow.MARQUEE : TextOverflow.Ellipsis, 3770 maxFontSize: this.buttonMaxFontSize, 3771 minFontSize: this.buttonMinFontSize 3772 }); 3773 }, Button); 3774 Button.pop(); 3775 }); 3776 } 3777 }, If); 3778 If.pop(); 3779 } 3780 3781 buildHorizontalAlignButtons(parent = null) { 3782 this.observeComponentCreation2((elmtId, isInitialRender) => { 3783 If.create(); 3784 if (this.buttons && this.buttons.length > 0) { 3785 this.ifElseBranchUpdateFunction(0, () => { 3786 this.observeComponentCreation2((elmtId, isInitialRender) => { 3787 Row.create(); 3788 }, Row); 3789 this.buildSingleButton.bind(this)(this.buttons[0]); 3790 this.observeComponentCreation2((elmtId, isInitialRender) => { 3791 If.create(); 3792 if (this.buttons.length === HORIZON_BUTTON_MAX_COUNT) { 3793 this.ifElseBranchUpdateFunction(0, () => { 3794 this.observeComponentCreation2((elmtId, isInitialRender) => { 3795 Row.create(); 3796 Row.width(BUTTON_HORIZONTAL_SPACE * 2); 3797 Row.justifyContent(FlexAlign.Center); 3798 }, Row); 3799 this.observeComponentCreation2((elmtId, isInitialRender) => { 3800 Divider.create(); 3801 Divider.width({ 3802 'id': -1, 3803 'type': 10002, 3804 params: ['sys.float.alert_divider_width'], 3805 'bundleName': '__harDefaultBundleName__', 3806 'moduleName': '__harDefaultModuleName__' 3807 }); 3808 Divider.height({ 3809 'id': -1, 3810 'type': 10002, 3811 params: ['sys.float.alert_divider_height'], 3812 'bundleName': '__harDefaultBundleName__', 3813 'moduleName': '__harDefaultModuleName__' 3814 }); 3815 Divider.color(this.getDividerColor()); 3816 Divider.vertical(true); 3817 }, Divider); 3818 Row.pop(); 3819 this.buildSingleButton.bind(this)(this.buttons[HORIZON_BUTTON_MAX_COUNT - 1]); 3820 }); 3821 } else { 3822 this.ifElseBranchUpdateFunction(1, () => { 3823 }); 3824 } 3825 }, If); 3826 If.pop(); 3827 Row.pop(); 3828 }); 3829 } else { 3830 this.ifElseBranchUpdateFunction(1, () => { 3831 }); 3832 } 3833 }, If); 3834 If.pop(); 3835 } 3836 3837 buildVerticalAlignButtons(parent = null) { 3838 this.observeComponentCreation2((elmtId, isInitialRender) => { 3839 If.create(); 3840 if (this.buttons) { 3841 this.ifElseBranchUpdateFunction(0, () => { 3842 this.observeComponentCreation2((elmtId, isInitialRender) => { 3843 Column.create(); 3844 }, Column); 3845 this.observeComponentCreation2((elmtId, isInitialRender) => { 3846 ForEach.create(); 3847 const forEachItemGenFunction = (_item, index) => { 3848 const item = _item; 3849 this.buildButtonWithDivider.bind(this)(this.buttons?.length === HORIZON_BUTTON_MAX_COUNT ? 3850 HORIZON_BUTTON_MAX_COUNT - index - 1 : index); 3851 }; 3852 this.forEachUpdateFunction(elmtId, this.buttons.slice(0, VERTICAL_BUTTON_MAX_COUNT), 3853 forEachItemGenFunction, (item) => item.value.toString(), true, false); 3854 }, ForEach); 3855 ForEach.pop(); 3856 Column.pop(); 3857 }); 3858 } else { 3859 this.ifElseBranchUpdateFunction(1, () => { 3860 }); 3861 } 3862 }, If); 3863 If.pop(); 3864 } 3865 3866 /** 3867 * get divider color 3868 * 3869 * @returns divider color 3870 */ 3871 getDividerColor() { 3872 if (!this.buttons || this.buttons.length === 0 || !DIALOG_DIVIDER_SHOW()) { 3873 return Color.Transparent; 3874 } 3875 if (this.buttons[0].buttonStyle === ButtonStyleMode.TEXTUAL || this.buttons[0].buttonStyle === undefined) { 3876 if (this.buttons[HORIZON_BUTTON_MAX_COUNT - 1].buttonStyle === ButtonStyleMode.TEXTUAL || 3877 this.buttons[HORIZON_BUTTON_MAX_COUNT - 1].buttonStyle === undefined) { 3878 return { 3879 'id': -1, 3880 'type': 10001, 3881 params: ['sys.color.alert_divider_color'], 3882 'bundleName': '__harDefaultBundleName__', 3883 'moduleName': '__harDefaultModuleName__' 3884 }; 3885 } 3886 } 3887 return Color.Transparent; 3888 } 3889 3890 /** 3891 * is button buttonStyle and role properties high priority 3892 * 3893 * @param buttonOptions button properties 3894 * @returns check result 3895 */ 3896 isNewPropertiesHighPriority(buttonOptions) { 3897 if (buttonOptions.role === ButtonRole.ERROR) { 3898 return true; 3899 } 3900 if (buttonOptions.buttonStyle !== undefined && 3901 buttonOptions.buttonStyle !== ALERT_BUTTON_STYLE()) { 3902 return true; 3903 } 3904 if (buttonOptions.background === undefined && buttonOptions.fontColor === undefined) { 3905 return true; 3906 } 3907 return false; 3908 } 3909 3910 buildButtonWithDivider(index, parent = null) { 3911 this.observeComponentCreation2((elmtId, isInitialRender) => { 3912 If.create(); 3913 if (this.buttons && this.buttons[index]) { 3914 this.ifElseBranchUpdateFunction(0, () => { 3915 this.observeComponentCreation2((elmtId, isInitialRender) => { 3916 Row.create(); 3917 }, Row); 3918 this.buildSingleButton.bind(this)(this.buttons[index]); 3919 Row.pop(); 3920 this.observeComponentCreation2((elmtId, isInitialRender) => { 3921 If.create(); 3922 if ((this.buttons.length === HORIZON_BUTTON_MAX_COUNT ? HORIZON_BUTTON_MAX_COUNT - index - 1 : 3923 index) < 3924 Math.min(this.buttons.length, VERTICAL_BUTTON_MAX_COUNT) - 1) { 3925 this.ifElseBranchUpdateFunction(0, () => { 3926 this.observeComponentCreation2((elmtId, isInitialRender) => { 3927 Row.create(); 3928 Row.height({ 3929 'id': -1, 3930 'type': 10002, 3931 params: ['sys.float.alert_button_vertical_space'], 3932 'bundleName': '__harDefaultBundleName__', 3933 'moduleName': '__harDefaultModuleName__' 3934 }); 3935 }, Row); 3936 Row.pop(); 3937 }); 3938 } else { 3939 this.ifElseBranchUpdateFunction(1, () => { 3940 }); 3941 } 3942 }, If); 3943 If.pop(); 3944 }); 3945 } else { 3946 this.ifElseBranchUpdateFunction(1, () => { 3947 }); 3948 } 3949 }, If); 3950 If.pop(); 3951 } 3952 3953 isVerticalAlignButton(width) { 3954 if (this.buttons) { 3955 if (this.buttons.length === 1) { 3956 return false; 3957 } 3958 if (this.buttons.length !== HORIZON_BUTTON_MAX_COUNT) { 3959 return true; 3960 } 3961 let isVertical = false; 3962 let maxButtonTextSize = vp2px(width / HORIZON_BUTTON_MAX_COUNT - BUTTON_HORIZONTAL_MARGIN - 3963 BUTTON_HORIZONTAL_SPACE - 2 * BUTTON_HORIZONTAL_PADDING); 3964 this.buttons.forEach((button) => { 3965 try { 3966 let contentSize = measure.measureTextSize({ 3967 textContent: button.value, 3968 fontSize: this.buttonMaxFontSize 3969 }); 3970 if (Number(contentSize?.width) > maxButtonTextSize) { 3971 isVertical = true; 3972 } 3973 } catch (err) { 3974 let code = (err).code; 3975 let message = (err).message; 3976 hilog.error(0x3900, 'Ace', `Faild to dialog isVerticalAlignButton measureTextSize,cause, 3977 code: ${code}, message: ${message}`); 3978 } 3979 }); 3980 return isVertical; 3981 } 3982 return false; 3983 } 3984 3985 rerender() { 3986 this.updateDirtyElements(); 3987 } 3988} 3989 3990function __Button__setButtonProperties(buttonOptions, isHasDefaultFocus, isAllFocusFalse, controller) { 3991 Button.onKeyEvent((event) => { 3992 if (!event) { 3993 return; 3994 } 3995 if ((event.keyCode === KeyCode.KEYCODE_SPACE || event.keyCode === KeyCode.KEYCODE_ENTER) && 3996 event.type === KeyType.Down) { 3997 if (buttonOptions.action) { 3998 buttonOptions.action(); 3999 } 4000 controller?.close(); 4001 event.stopPropagation(); 4002 } 4003 }); 4004 Button.onClick(() => { 4005 if (buttonOptions.action) { 4006 buttonOptions.action(); 4007 } 4008 controller?.close(); 4009 }); 4010 Button.defaultFocus(isDefaultFocus(buttonOptions, isHasDefaultFocus, isAllFocusFalse)); 4011 Button.buttonStyle(buttonOptions.buttonStyle ?? 4012 (buttonOptions.role === ButtonRole.ERROR ? ERROR_BUTTON_STYLE() : ALERT_BUTTON_STYLE())); 4013 Button.layoutWeight(BUTTON_LAYOUT_WEIGHT); 4014 Button.type(ButtonType.ROUNDED_RECTANGLE); 4015} 4016 4017/** 4018 * is button set default focus 4019 * 4020 * @param singleButton button options 4021 * @param isHasDefaultFocus is button list has default focus button 4022 * @param isAllFocusFalse is all button in button list default focus false 4023 * @returns boolean 4024 */ 4025function isDefaultFocus(singleButton, isHasDefaultFocus, isAllFocusFalse) { 4026 try { 4027 // 当前按钮为默认按钮 4028 if (singleButton.defaultFocus) { 4029 return true; 4030 } 4031 let isDefaultFocus = false; 4032 if (isHasDefaultFocus || isAllFocusFalse) { 4033 isDefaultFocus = false; // 存在默认按钮或者所有按钮的defaultFocus都为false 4034 } else { 4035 isDefaultFocus = true; // 默认第一个按钮获焦 4036 } 4037 return isDefaultFocus; 4038 } catch (error) { 4039 let code = error.code; 4040 let message = error.message; 4041 hilog.error(0x3900, 'Ace', `get defaultFocus exist error, code: ${code}, message: ${message}`); 4042 return true; 4043 } 4044} 4045 4046/** 4047 * get resource size 4048 * 4049 * @param resourceId resource id 4050 * @param defaultValue default value 4051 * @returns resource size 4052 */ 4053function getNumberByResourceId(resourceId, defaultValue, allowZero) { 4054 try { 4055 let sourceValue = resourceManager.getSystemResourceManager().getNumber(resourceId); 4056 if (sourceValue > 0 || allowZero) { 4057 return sourceValue; 4058 } else { 4059 return defaultValue; 4060 } 4061 } catch (error) { 4062 let code = error.code; 4063 let message = error.message; 4064 hilog.error(0x3900, 'Ace', 4065 `CustomContentDialog getNumberByResourceId error, code: ${code}, message: ${message}`); 4066 return defaultValue; 4067 } 4068} 4069 4070/** 4071 * lazy init 4072 * 4073 * @param initializer lazy initializer 4074 * @returns lazy init result 4075 */ 4076function lazyInit(initializer) { 4077 let value = null; 4078 return () => { 4079 if (value === null) { 4080 value = initializer(); 4081 } 4082 return value; 4083 }; 4084} 4085 4086/** 4087 * get LengthMetrics size 4088 * 4089 * @param resource resource 4090 * @param defaultValue default value 4091 * @param isAllowZero allow value zero 4092 * @returns LengthMetrics size 4093 */ 4094function getLengthMetricsByResource(resource, defaultValue, isAllowZero) { 4095 if (!resource) { 4096 hilog.error(0x3900, 'Ace', 'CustomContentDialog getLengthMetricsByResource error'); 4097 return defaultValue; 4098 } 4099 try { 4100 let sourceValue = LengthMetrics.resource(resource).value; 4101 if (sourceValue === 0) { 4102 return isAllowZero ? sourceValue : defaultValue; 4103 } 4104 return sourceValue; 4105 } catch (error) { 4106 let code = error.code; 4107 let message = error.message; 4108 hilog.error(0x3900, 'Ace', 4109 `CustomContentDialog getLengthMetricsByResource error, code: ${code}, message: ${message}`); 4110 return defaultValue; 4111 } 4112} 4113 4114/** 4115 * get string value 4116 * 4117 * @param resourceId Resource id 4118 * @returns resource value 4119 */ 4120function getString(resourceId) { 4121 let res = ''; 4122 if (resourceId <= 0) { 4123 hilog.error(0x3900, 'Ace', 'CustomContentDialog getString error'); 4124 return res; 4125 } 4126 try { 4127 res = getContext().resourceManager.getStringSync(resourceId); 4128 } catch (error) { 4129 let code = error.code; 4130 let message = error.message; 4131 hilog.error(0x3900, 'Ace', `CustomContentDialog getString error, code: ${code}, message: ${message}`); 4132 } 4133 return res; 4134} 4135 4136/** 4137 * 获取SelectDialog无障碍文本 4138 * 4139 * @param resource 资源 4140 * @param selected select state 4141 * @returns string 4142 */ 4143function getAccessibilityText(resource, selected) { 4144 try { 4145 let selectText = getContext().resourceManager.getStringSync(125833934); 4146 let resourceString = ''; 4147 if (typeof resource === 'string') { 4148 resourceString = resource; 4149 } else { 4150 resourceString = getContext().resourceManager.getStringSync(resource); 4151 } 4152 return selected ? `${selectText},${resourceString}` : resourceString; 4153 } catch (error) { 4154 let code = error.code; 4155 let message = error.message; 4156 hilog.error(0x3900, 'Ace', `getAccessibilityText error, code: ${code}, message: ${message}`); 4157 return ''; 4158 } 4159} 4160 4161/** 4162 * get Text Align 4163 * 4164 * @param maxWidth maxWidth 4165 * @param content textContent 4166 * @param fontSize fontSize 4167 * @returns textAlign 4168 */ 4169function getTextAlign(maxWidth, content, fontSize) { 4170 let contentSize = measure.measureTextSize({ 4171 textContent: content, 4172 fontSize: fontSize, 4173 constraintWidth: maxWidth, 4174 }); 4175 let oneLineSize = measure.measureTextSize({ 4176 textContent: content, 4177 fontSize: fontSize, 4178 }); 4179 if (getTextHeight(contentSize) <= getTextHeight(oneLineSize)) { 4180 return TextAlign.Center; 4181 } 4182 return TextAlign.Start; 4183} 4184 4185/** 4186 * get text height 4187 * 4188 * @param textSize textSize 4189 * @returns text height 4190 */ 4191function getTextHeight(textSize) { 4192 if (textSize && textSize.height !== null && textSize.height !== undefined) { 4193 return Number(textSize.height); 4194 } 4195 return 0; 4196} 4197 4198/** 4199 * resolve content area keyEvent 4200 * 4201 * @param event keyEvent 4202 * @param controller the controller of content area 4203 * @returns undefined 4204 */ 4205function resolveKeyEvent(event, controller) { 4206 if (event.type === IGNORE_KEY_EVENT_TYPE) { 4207 return; 4208 } 4209 if (event.keyCode === KEYCODE_UP) { 4210 controller.scrollPage({ next: false }); 4211 event.stopPropagation(); 4212 } else if (event.keyCode === KEYCODE_DOWN) { 4213 if (controller.isAtEnd()) { 4214 return; 4215 } else { 4216 controller.scrollPage({ next: true }); 4217 event.stopPropagation(); 4218 } 4219 } 4220} 4221 4222/** 4223 * 获取checkTips无障碍文本 4224 * 4225 * @param resource 资源 4226 * @param selected select state 4227 * @returns string 4228 */ 4229function getCheckTipsAccessibilityText(resource, selected) { 4230 try { 4231 // 'sys.string.slider_accessibility_selected' 4232 let selectText = getContext().resourceManager.getStringSync(125833934); 4233 // 'sys.string.slider_accessibility_unselected' 4234 let unselectText = getContext().resourceManager.getStringSync(125833935); 4235 // 'sys.string.advanced_dialog_accessibility_checkbox' 4236 let checkBoxText = getContext().resourceManager.getStringSync(125834354); 4237 let resourceString = ''; 4238 if (typeof resource === 'string') { 4239 resourceString = resource; 4240 } else { 4241 resourceString = getContext().resourceManager.getStringSync(resource); 4242 } 4243 return selected ? `${selectText},${resourceString},${checkBoxText}` : 4244 `${unselectText},${resourceString},${checkBoxText}`; 4245 } catch (error) { 4246 let code = error.code; 4247 let message = error.message; 4248 hilog.error(0x3900, 'Ace', `getCheckTipsAccessibilityText error, code: ${code}, message: ${message}`); 4249 return ''; 4250 } 4251} 4252 4253export class LoadingDialog extends ViewPU { 4254 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 4255 super(parent, __localStorage, elmtId, extraInfo); 4256 if (typeof paramsLambda === 'function') { 4257 this.paramsGenerator_ = paramsLambda; 4258 } 4259 this.controller = undefined; 4260 this.content = ''; 4261 this.__fontColorWithTheme = new ObservedPropertyObjectPU({ 4262 'id': -1, 4263 'type': 10001, 4264 params: ['sys.color.font_primary'], 4265 'bundleName': '__harDefaultBundleName__', 4266 'moduleName': '__harDefaultModuleName__' 4267 }, this, 'fontColorWithTheme'); 4268 this.__loadingProgressIconColorWithTheme = new ObservedPropertyObjectPU({ 4269 'id': -1, 4270 'type': 10001, 4271 params: ['sys.color.icon_secondary'], 4272 'bundleName': '__harDefaultBundleName__', 4273 'moduleName': '__harDefaultModuleName__' 4274 }, this, 'loadingProgressIconColorWithTheme'); 4275 this.theme = new CustomThemeImpl({}); 4276 this.themeColorMode = ThemeColorMode.SYSTEM; 4277 this.__fontSizeScale = new ObservedPropertySimplePU(1, this, 'fontSizeScale'); 4278 this.__minContentHeight = new ObservedPropertySimplePU(MIN_CONTENT_HEIGHT, this, 'minContentHeight'); 4279 this.setInitiallyProvidedValue(params); 4280 this.finalizeConstruction(); 4281 } 4282 4283 setInitiallyProvidedValue(params) { 4284 if (params.controller !== undefined) { 4285 this.controller = params.controller; 4286 } 4287 if (params.content !== undefined) { 4288 this.content = params.content; 4289 } 4290 if (params.fontColorWithTheme !== undefined) { 4291 this.fontColorWithTheme = params.fontColorWithTheme; 4292 } 4293 if (params.loadingProgressIconColorWithTheme !== undefined) { 4294 this.loadingProgressIconColorWithTheme = params.loadingProgressIconColorWithTheme; 4295 } 4296 if (params.theme !== undefined) { 4297 this.theme = params.theme; 4298 } 4299 if (params.themeColorMode !== undefined) { 4300 this.themeColorMode = params.themeColorMode; 4301 } 4302 if (params.fontSizeScale !== undefined) { 4303 this.fontSizeScale = params.fontSizeScale; 4304 } 4305 if (params.minContentHeight !== undefined) { 4306 this.minContentHeight = params.minContentHeight; 4307 } 4308 } 4309 4310 updateStateVars(params) { 4311 } 4312 4313 purgeVariableDependenciesOnElmtId(rmElmtId) { 4314 this.__fontColorWithTheme.purgeDependencyOnElmtId(rmElmtId); 4315 this.__loadingProgressIconColorWithTheme.purgeDependencyOnElmtId(rmElmtId); 4316 this.__fontSizeScale.purgeDependencyOnElmtId(rmElmtId); 4317 this.__minContentHeight.purgeDependencyOnElmtId(rmElmtId); 4318 } 4319 4320 aboutToBeDeleted() { 4321 this.__fontColorWithTheme.aboutToBeDeleted(); 4322 this.__loadingProgressIconColorWithTheme.aboutToBeDeleted(); 4323 this.__fontSizeScale.aboutToBeDeleted(); 4324 this.__minContentHeight.aboutToBeDeleted(); 4325 SubscriberManager.Get().delete(this.id__()); 4326 this.aboutToBeDeletedInternal(); 4327 } 4328 4329 setController(ctr) { 4330 this.controller = ctr; 4331 } 4332 4333 get fontColorWithTheme() { 4334 return this.__fontColorWithTheme.get(); 4335 } 4336 4337 set fontColorWithTheme(newValue) { 4338 this.__fontColorWithTheme.set(newValue); 4339 } 4340 4341 get loadingProgressIconColorWithTheme() { 4342 return this.__loadingProgressIconColorWithTheme.get(); 4343 } 4344 4345 set loadingProgressIconColorWithTheme(newValue) { 4346 this.__loadingProgressIconColorWithTheme.set(newValue); 4347 } 4348 4349 get fontSizeScale() { 4350 return this.__fontSizeScale.get(); 4351 } 4352 4353 set fontSizeScale(newValue) { 4354 this.__fontSizeScale.set(newValue); 4355 } 4356 4357 get minContentHeight() { 4358 return this.__minContentHeight.get(); 4359 } 4360 4361 set minContentHeight(newValue) { 4362 this.__minContentHeight.set(newValue); 4363 } 4364 4365 initialRender() { 4366 this.observeComponentCreation2((elmtId, isInitialRender) => { 4367 Column.create(); 4368 }, Column); 4369 this.observeComponentCreation2((elmtId, isInitialRender) => { 4370 __Common__.create(); 4371 __Common__.constraintSize({ maxHeight: '100%' }); 4372 }, __Common__); 4373 { 4374 this.observeComponentCreation2((elmtId, isInitialRender) => { 4375 if (isInitialRender) { 4376 let componentCall = new CustomDialogContentComponent(this, { 4377 controller: this.controller, 4378 contentBuilder: () => { 4379 this.contentBuilder(); 4380 }, 4381 theme: this.theme, 4382 themeColorMode: this.themeColorMode, 4383 fontSizeScale: this.__fontSizeScale, 4384 minContentHeight: this.__minContentHeight, 4385 }, undefined, elmtId, () => { 4386 }, { page: 'library/src/main/ets/components/dialog.ets', line: 1892, col: 7 }); 4387 ViewPU.create(componentCall); 4388 let paramsLambda = () => { 4389 return { 4390 controller: this.controller, 4391 contentBuilder: () => { 4392 this.contentBuilder(); 4393 }, 4394 theme: this.theme, 4395 themeColorMode: this.themeColorMode, 4396 fontSizeScale: this.fontSizeScale, 4397 minContentHeight: this.minContentHeight 4398 }; 4399 }; 4400 componentCall.paramsGenerator_ = paramsLambda; 4401 } else { 4402 this.updateStateVarsOfChildByElmtId(elmtId, {}); 4403 } 4404 }, { name: 'CustomDialogContentComponent' }); 4405 } 4406 __Common__.pop(); 4407 Column.pop(); 4408 } 4409 4410 contentBuilder(parent = null) { 4411 this.observeComponentCreation2((elmtId, isInitialRender) => { 4412 Column.create(); 4413 }, Column); 4414 this.observeComponentCreation2((elmtId, isInitialRender) => { 4415 Row.create(); 4416 Row.constraintSize({ minHeight: LOADING_MIN_HEIGHT }); 4417 }, Row); 4418 this.observeComponentCreation2((elmtId, isInitialRender) => { 4419 Text.create(this.content); 4420 Text.fontSize(`${BODY_L}fp`); 4421 Text.fontWeight(FontWeight.Regular); 4422 Text.fontColor(ObservedObject.GetRawObject(this.fontColorWithTheme)); 4423 Text.layoutWeight(LOADING_TEXT_LAYOUT_WEIGHT); 4424 Text.maxLines(this.fontSizeScale > MAX_FONT_SCALE ? LOADING_MAX_LINES_BIG_FONT : LOADING_MAX_LINES); 4425 Text.focusable(true); 4426 Text.defaultFocus(true); 4427 Text.focusBox({ 4428 strokeWidth: LengthMetrics.px(0) 4429 }); 4430 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 4431 }, Text); 4432 Text.pop(); 4433 this.observeComponentCreation2((elmtId, isInitialRender) => { 4434 LoadingProgress.create(); 4435 LoadingProgress.color(ObservedObject.GetRawObject(this.loadingProgressIconColorWithTheme)); 4436 LoadingProgress.width(LOADING_PROGRESS_WIDTH); 4437 LoadingProgress.height(LOADING_PROGRESS_HEIGHT); 4438 LoadingProgress.margin({ start: LengthMetrics.vp(LOADING_TEXT_MARGIN_LEFT) }); 4439 }, LoadingProgress); 4440 Row.pop(); 4441 Column.pop(); 4442 } 4443 4444 aboutToAppear() { 4445 this.fontColorWithTheme = this.theme?.colors?.fontPrimary ? 4446 this.theme.colors.fontPrimary : { 4447 'id': -1, 4448 'type': 10001, 4449 params: ['sys.color.font_primary'], 4450 'bundleName': '__harDefaultBundleName__', 4451 'moduleName': '__harDefaultModuleName__' 4452 }; 4453 this.loadingProgressIconColorWithTheme = this.theme?.colors?.iconSecondary ? 4454 this.theme.colors.iconSecondary : { 4455 'id': -1, 4456 'type': 10001, 4457 params: ['sys.color.icon_secondary'], 4458 'bundleName': '__harDefaultBundleName__', 4459 'moduleName': '__harDefaultModuleName__' 4460 }; 4461 } 4462 4463 rerender() { 4464 this.updateDirtyElements(); 4465 } 4466} 4467 4468export class PopoverDialog extends ViewPU { 4469 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 4470 super(parent, __localStorage, elmtId, extraInfo); 4471 if (typeof paramsLambda === 'function') { 4472 this.paramsGenerator_ = paramsLambda; 4473 } 4474 this.__visible = new SynchedPropertySimpleTwoWayPU(params.visible, this, 'visible'); 4475 this.__popover = new SynchedPropertyObjectOneWayPU(params.popover, this, 'popover'); 4476 this.targetBuilder = undefined; 4477 this.__dialogWidth = new ObservedPropertyObjectPU(this.popover?.width, this, 'dialogWidth'); 4478 this.setInitiallyProvidedValue(params); 4479 this.finalizeConstruction(); 4480 } 4481 4482 setInitiallyProvidedValue(params) { 4483 if (params.targetBuilder !== undefined) { 4484 this.targetBuilder = params.targetBuilder; 4485 } 4486 if (params.dialogWidth !== undefined) { 4487 this.dialogWidth = params.dialogWidth; 4488 } 4489 } 4490 4491 updateStateVars(params) { 4492 this.__popover.reset(params.popover); 4493 } 4494 4495 purgeVariableDependenciesOnElmtId(rmElmtId) { 4496 this.__visible.purgeDependencyOnElmtId(rmElmtId); 4497 this.__popover.purgeDependencyOnElmtId(rmElmtId); 4498 this.__dialogWidth.purgeDependencyOnElmtId(rmElmtId); 4499 } 4500 4501 aboutToBeDeleted() { 4502 this.__visible.aboutToBeDeleted(); 4503 this.__popover.aboutToBeDeleted(); 4504 this.__dialogWidth.aboutToBeDeleted(); 4505 SubscriberManager.Get().delete(this.id__()); 4506 this.aboutToBeDeletedInternal(); 4507 } 4508 4509 get visible() { 4510 return this.__visible.get(); 4511 } 4512 4513 set visible(newValue) { 4514 this.__visible.set(newValue); 4515 } 4516 4517 get popover() { 4518 return this.__popover.get(); 4519 } 4520 4521 set popover(newValue) { 4522 this.__popover.set(newValue); 4523 } 4524 4525 get dialogWidth() { 4526 return this.__dialogWidth.get(); 4527 } 4528 4529 set dialogWidth(newValue) { 4530 this.__dialogWidth.set(newValue); 4531 } 4532 4533 emptyBuilder(parent = null) { 4534 } 4535 4536 aboutToAppear() { 4537 if (this.targetBuilder === undefined || this.targetBuilder === null) { 4538 this.targetBuilder = this.emptyBuilder; 4539 } 4540 } 4541 4542 initialRender() { 4543 this.observeComponentCreation2((elmtId, isInitialRender) => { 4544 Column.create(); 4545 Column.onClick(() => { 4546 try { 4547 let screenSize = display.getDefaultDisplaySync(); 4548 let screenWidth = px2vp(screenSize.width); 4549 if (screenWidth - BUTTON_HORIZONTAL_MARGIN - BUTTON_HORIZONTAL_MARGIN > MAX_DIALOG_WIDTH) { 4550 this.popover.width = this.popover?.width ?? MAX_DIALOG_WIDTH; 4551 } else { 4552 this.popover.width = this.dialogWidth; 4553 } 4554 this.visible = !this.visible; 4555 } catch (error) { 4556 let code = error.code; 4557 let message = error.message; 4558 hilog.error(0x3900, 'Ace', `dialog popup error, code: ${code}, message: ${message}`); 4559 } 4560 }); 4561 Column.bindPopup(this.visible, { 4562 builder: this.popover?.builder, 4563 placement: this.popover?.placement ?? Placement.Bottom, 4564 popupColor: this.popover?.popupColor, 4565 enableArrow: this.popover?.enableArrow ?? true, 4566 autoCancel: this.popover?.autoCancel, 4567 onStateChange: this.popover?.onStateChange ?? ((e) => { 4568 if (!e.isVisible) { 4569 this.visible = false; 4570 } 4571 }), 4572 arrowOffset: this.popover?.arrowOffset, 4573 showInSubWindow: this.popover?.showInSubWindow, 4574 mask: this.popover?.mask, 4575 targetSpace: this.popover?.targetSpace, 4576 offset: this.popover?.offset, 4577 width: this.popover?.width, 4578 arrowPointPosition: this.popover?.arrowPointPosition, 4579 arrowWidth: this.popover?.arrowWidth, 4580 arrowHeight: this.popover?.arrowHeight, 4581 radius: this.popover?.radius ?? { 4582 'id': -1, 4583 'type': 10002, 4584 params: ['sys.float.corner_radius_level16'], 4585 'bundleName': '__harDefaultBundleName__', 4586 'moduleName': '__harDefaultModuleName__' 4587 }, 4588 shadow: this.popover?.shadow ?? ShadowStyle.OUTER_DEFAULT_MD, 4589 backgroundBlurStyle: this.popover?.backgroundBlurStyle ?? BlurStyle.COMPONENT_ULTRA_THICK, 4590 focusable: this.popover?.focusable, 4591 transition: this.popover?.transition, 4592 onWillDismiss: this.popover?.onWillDismiss 4593 }); 4594 }, Column); 4595 this.targetBuilder.bind(this)(); 4596 Column.pop(); 4597 } 4598 4599 rerender() { 4600 this.updateDirtyElements(); 4601 } 4602} 4603 4604export default { 4605 TipsDialog, 4606 ConfirmDialog, 4607 SelectDialog, 4608 AlertDialog, 4609 LoadingDialog, 4610 CustomContentDialog, 4611 PopoverDialog 4612};