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