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