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