1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the 'License'); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an 'AS IS' BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 17 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 18 if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function') r = Reflect.decorate(decorators, target, key, desc); 19 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 20 return c > 3 && r && Object.defineProperty(target, key, r), r; 21}; 22if (!('finalizeConstruction' in ViewPU.prototype)) { 23 Reflect.set(ViewPU.prototype, 'finalizeConstruction', () => { }); 24} 25const display = requireNapi('display'); 26const hilog = requireNapi('hilog'); 27const measure = requireNapi('measure'); 28const resourceManager = requireNapi('resourceManager'); 29const LengthMetrics = requireNapi('arkui.node').LengthMetrics; 30const LengthUnit = requireNapi('arkui.node').LengthUnit; 31const accessibility = requireNapi('accessibility'); 32const KeyCode = requireNapi('multimodalInput.keyCode').KeyCode; 33const i18n = requireNapi('i18n'); 34const TITLE_MAX_LINES = 2; 35const HORIZON_BUTTON_MAX_COUNT = 2; 36const VERTICAL_BUTTON_MAX_COUNT = 4; 37const BUTTON_LAYOUT_WEIGHT = 1; 38const CHECKBOX_CONTAINER_HEIGHT = 48; 39const CONTENT_MAX_LINES = 2; 40const LOADING_PROGRESS_WIDTH = 40; 41const LOADING_PROGRESS_HEIGHT = 40; 42const LOADING_MAX_LINES = 10; 43const LOADING_MAX_LINES_BIG_FONT = 4; 44const LOADING_TEXT_LAYOUT_WEIGHT = 1; 45const LOADING_TEXT_MARGIN_LEFT = 12; 46const LOADING_MIN_HEIGHT = 48; 47const LIST_MIN_HEIGHT = 48; 48const CHECKBOX_CONTAINER_LENGTH = 20; 49const TEXT_MIN_HEIGHT = 48; 50const DEFAULT_IMAGE_SIZE = 64; 51const MIN_CONTENT_HEIGHT = 100; 52const MAX_CONTENT_HEIGHT = 30000; 53const KEYCODE_UP = 2012; 54const KEYCODE_DOWN = 2013; 55const IGNORE_KEY_EVENT_TYPE = 1; 56const FIRST_ITEM_INDEX = 0; 57const VERSION_TWELVE = 50000012; 58const BUTTON_MIN_FONT_SIZE = 9; 59const MAX_FONT_SCALE = 2; 60// 'sys.float.alert_container_max_width' 61const MAX_DIALOG_WIDTH = getNumberByResourceId(125831042, 400); 62// 'sys.float.alert_right_padding_horizontal' 63const BUTTON_HORIZONTAL_MARGIN = getNumberByResourceId(125831054, 16); 64// 'sys.float.padding_level8' 65const BUTTON_HORIZONTAL_PADDING = getNumberByResourceId(125830927, 16); 66// 'sys.float.padding_level4' 67const CHECK_BOX_MARGIN_END = getNumberByResourceId(125830923, 8); 68// 'sys.float.alert_button_horizontal_space' 69const BUTTON_HORIZONTAL_SPACE = getNumberByResourceId(125831051, 8); 70// 'sys.float.Body_L' 71const BODY_L = getNumberByResourceId(125830970, 16); 72// 'sys.float.Body_M' 73const BODY_M = getNumberByResourceId(125830971, 14); 74// 'sys.float.Body_S' 75const BODY_S = getNumberByResourceId(125830972, 12); 76// 'sys.float.Title_S' 77const TITLE_S = getNumberByResourceId(125830966, 20); 78// 'sys.float.Subtitle_S' 79const SUBTITLE_S = getNumberByResourceId(125830969, 14); 80// 'sys.float.padding_level8' 81const PADDING_LEVEL_8 = getNumberByResourceId(125830927, 16); 82// 'sys.float.dialog_divider_show' 83const DIALOG_DIVIDER_SHOW = getNumberByResourceId(125831202, 1, true); 84// 'sys.float.alert_button_style' 85const ALERT_BUTTON_STYLE = getNumberByResourceId(125831085, 2, true); 86// 'sys.float.alert_title_alignment' 87const ALERT_TITLE_ALIGNMENT = getEnumNumberByResourceId(125831126, 1); 88// 'sys.float.dialog_content_font_size' 89const CONTENT_FONT_SIZE = getNumberByResourceId(125835677, BODY_L); 90const SCROLL_BAR_OFFSET = 20; 91const SELECT_DIALOG_SCROLL_BAR_OFFSET = 4; 92let AdvancedDialogV2Button = class AdvancedDialogV2Button { 93 constructor(options) { 94 this.content = ''; 95 this.content = options.content; 96 this.action = options.action; 97 this.background = options.background; 98 this.fontColor = options.fontColor; 99 this.buttonStyle = options.buttonStyle; 100 this.role = options.role; 101 this.defaultFocus = options.defaultFocus; 102 this.enabled = options.enabled; 103 } 104 ; 105}; 106__decorate([ 107 Trace 108], AdvancedDialogV2Button.prototype, 'content', void 0); 109__decorate([ 110 Trace 111], AdvancedDialogV2Button.prototype, 'action', void 0); 112__decorate([ 113 Trace 114], AdvancedDialogV2Button.prototype, 'background', void 0); 115__decorate([ 116 Trace 117], AdvancedDialogV2Button.prototype, 'fontColor', void 0); 118__decorate([ 119 Trace 120], AdvancedDialogV2Button.prototype, 'buttonStyle', void 0); 121__decorate([ 122 Trace 123], AdvancedDialogV2Button.prototype, 'role', void 0); 124__decorate([ 125 Trace 126], AdvancedDialogV2Button.prototype, 'defaultFocus', void 0); 127__decorate([ 128 Trace 129], AdvancedDialogV2Button.prototype, 'enabled', void 0); 130AdvancedDialogV2Button = __decorate([ 131 ObservedV2 132], AdvancedDialogV2Button); 133export { AdvancedDialogV2Button }; 134export class TipsDialogV2 extends ViewV2 { 135 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda, extraInfo) { 136 super(parent, elmtId, extraInfo); 137 this.initParam('imageRes', (params && 'imageRes' in params) ? params.imageRes : undefined); 138 this.initParam('imageSize', (params && 'imageSize' in params) ? params.imageSize : { width: DEFAULT_IMAGE_SIZE, height: DEFAULT_IMAGE_SIZE }); 139 this.initParam('imageBorderColor', (params && 'imageBorderColor' in params) ? params.imageBorderColor : undefined); 140 this.initParam('imageBorderWidth', (params && 'imageBorderWidth' in params) ? params.imageBorderWidth : undefined); 141 this.initParam('title', (params && 'title' in params) ? params.title : null); 142 this.initParam('content', (params && 'content' in params) ? params.content : null); 143 this.initParam('onCheckedChange', (params && 'onCheckedChange' in params) ? params.onCheckedChange : undefined); 144 this.initParam('checkTips', (params && 'checkTips' in params) ? params.checkTips : null); 145 this.initParam('checked', (params && 'checked' in params) ? params.checked : false); 146 this.checkedInner = false; 147 this.initParam('primaryButton', (params && 'primaryButton' in params) ? params.primaryButton : null); 148 this.initParam('secondaryButton', (params && 'secondaryButton' in params) ? params.secondaryButton : null); 149 this.marginOffset = 0 - PADDING_LEVEL_8; 150 this.contentScroller = new Scroller(); 151 this.fontColorWithTheme = { 'id': -1, 'type': 10001, params: ['sys.color.font_primary'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }; 152 this.fontSizeScale = 1; 153 this.minContentHeight = 160; 154 this.imageIndex = 0; 155 this.textIndex = 1; 156 this.checkBoxIndex = 2; 157 this.appMaxFontScale = 3.2; 158 this.finalizeConstruction(); 159 } 160 checkedChangeMonitor(monitor) { 161 this.checkedInner = monitor.value('checked')?.now; 162 } 163 get buttons() { 164 if (!this.primaryButton && !this.secondaryButton) { 165 return undefined; 166 } 167 let buttons = []; 168 if (this.primaryButton) { 169 buttons.push(this.primaryButton); 170 } 171 if (this.secondaryButton) { 172 buttons.push(this.secondaryButton); 173 } 174 return buttons; 175 } 176 onWillApplyTheme(theme) { 177 this.fontColorWithTheme = theme.colors.fontPrimary; 178 } 179 initialRender() { 180 this.observeComponentCreation2((elmtId, isInitialRender) => { 181 __Common__.create(); 182 __Common__.constraintSize({ maxHeight: '100%' }); 183 }, __Common__); 184 { 185 this.observeComponentCreation2((elmtId, isInitialRender) => { 186 if (isInitialRender) { 187 let componentCall = new CustomDialogContentComponent(this, { 188 contentBuilder: () => { 189 this.contentBuilder(); 190 }, 191 buttons: this.buttons, 192 minContentHeight: this.minContentHeight, 193 $minContentHeight: value => { this.minContentHeight = value; } 194 }, undefined, elmtId, () => { }, { page: 'library/src/main/ets/components/dialog.ets', line: 182, col: 5 }); 195 ViewV2.create(componentCall); 196 let paramsLambda = () => { 197 return { 198 contentBuilder: () => { 199 this.contentBuilder(); 200 }, 201 buttons: this.buttons, 202 minContentHeight: this.minContentHeight 203 }; 204 }; 205 componentCall.paramsGenerator_ = paramsLambda; 206 } 207 else { 208 this.updateStateVarsOfChildByElmtId(elmtId, { 209 buttons: this.buttons, 210 minContentHeight: this.minContentHeight 211 }); 212 } 213 }, { name: 'CustomDialogContentComponent' }); 214 } 215 __Common__.pop(); 216 } 217 contentBuilder(parent = null) { 218 { 219 this.observeComponentCreation2((elmtId, isInitialRender) => { 220 if (isInitialRender) { 221 let componentCall = new TipsDialogContentLayout(this, { 222 title: this.title, 223 content: this.content, 224 checkTips: this.checkTips, 225 minContentHeight: this.minContentHeight, 226 dialogBuilder: () => { 227 this.observeComponentCreation2((elmtId, isInitialRender) => { 228 ForEach.create(); 229 const forEachItemGenFunction = _item => { 230 const index = _item; 231 this.observeComponentCreation2((elmtId, isInitialRender) => { 232 If.create(); 233 if (index === this.imageIndex) { 234 this.ifElseBranchUpdateFunction(0, () => { 235 this.imagePart.bind(this)(); 236 }); 237 } 238 else if (index === this.textIndex) { 239 this.ifElseBranchUpdateFunction(1, () => { 240 this.observeComponentCreation2((elmtId, isInitialRender) => { 241 Column.create(); 242 Column.padding({ top: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level8'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } }); 243 }, Column); 244 this.textPart.bind(this)(); 245 Column.pop(); 246 }); 247 } 248 else { 249 this.ifElseBranchUpdateFunction(2, () => { 250 this.checkBoxPart.bind(this)(); 251 }); 252 } 253 }, If); 254 If.pop(); 255 }; 256 this.forEachUpdateFunction(elmtId, [this.imageIndex, this.textIndex, this.checkBoxIndex], forEachItemGenFunction); 257 }, ForEach); 258 ForEach.pop(); 259 }, 260 $minContentHeight: value => { this.minContentHeight = value; } 261 }, undefined, elmtId, () => { }, { page: 'library/src/main/ets/components/dialog.ets', line: 193, col: 5 }); 262 ViewV2.create(componentCall); 263 let paramsLambda = () => { 264 return { 265 title: this.title, 266 content: this.content, 267 checkTips: this.checkTips, 268 minContentHeight: this.minContentHeight, 269 dialogBuilder: () => { 270 this.observeComponentCreation2((elmtId, isInitialRender) => { 271 ForEach.create(); 272 const forEachItemGenFunction = _item => { 273 const index = _item; 274 this.observeComponentCreation2((elmtId, isInitialRender) => { 275 If.create(); 276 if (index === this.imageIndex) { 277 this.ifElseBranchUpdateFunction(0, () => { 278 this.imagePart.bind(this)(); 279 }); 280 } 281 else if (index === this.textIndex) { 282 this.ifElseBranchUpdateFunction(1, () => { 283 this.observeComponentCreation2((elmtId, isInitialRender) => { 284 Column.create(); 285 Column.padding({ top: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level8'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } }); 286 }, Column); 287 this.textPart.bind(this)(); 288 Column.pop(); 289 }); 290 } 291 else { 292 this.ifElseBranchUpdateFunction(2, () => { 293 this.checkBoxPart.bind(this)(); 294 }); 295 } 296 }, If); 297 If.pop(); 298 }; 299 this.forEachUpdateFunction(elmtId, [this.imageIndex, this.textIndex, this.checkBoxIndex], forEachItemGenFunction); 300 }, ForEach); 301 ForEach.pop(); 302 } 303 }; 304 }; 305 componentCall.paramsGenerator_ = paramsLambda; 306 } 307 else { 308 this.updateStateVarsOfChildByElmtId(elmtId, { 309 title: this.title, 310 content: this.content, 311 checkTips: this.checkTips, 312 minContentHeight: this.minContentHeight 313 }); 314 } 315 }, { name: 'TipsDialogContentLayout' }); 316 } 317 } 318 checkBoxPart(parent = null) { 319 this.observeComponentCreation2((elmtId, isInitialRender) => { 320 Row.create(); 321 Row.accessibilityGroup(true); 322 Row.accessibilityText(getCheckTipsAccessibilityText(this.checkTips, this.checkedInner)); 323 Row.accessibilityDescription(this.checkedInner ? { 'id': -1, 'type': 10003, params: ['sys.string.advanced_dialog_accessibility_cancel_checked_desc'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } : { 'id': -1, 'type': 10003, params: ['sys.string.slider_accessibility_unselectedDesc'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 324 Row.onClick(() => { 325 this.checkedInner = !this.checkedInner; 326 try { 327 let eventInfo = ({ 328 type: 'announceForAccessibility', 329 bundleName: getContext()?.abilityInfo?.bundleName, 330 triggerAction: 'common', 331 textAnnouncedForAccessibility: this.checkedInner ? getContext().resourceManager.getStringSync(125833934) : 332 getContext().resourceManager.getStringSync(125833935) 333 }); 334 accessibility.sendAccessibilityEvent(eventInfo); 335 } 336 catch (exception) { 337 let code = exception.code; 338 let message = exception.message; 339 hilog.error(0x3900, 'Ace', `Faild to send event, cause, code: ${code}, message: ${message}`); 340 } 341 }); 342 Row.padding({ top: 8, bottom: 8 }); 343 Row.constraintSize({ minHeight: CHECKBOX_CONTAINER_HEIGHT }); 344 Row.width('100%'); 345 }, Row); 346 this.observeComponentCreation2((elmtId, isInitialRender) => { 347 If.create(); 348 if (this.checkTips !== null && this.checkTips !== undefined) { 349 this.ifElseBranchUpdateFunction(0, () => { 350 this.observeComponentCreation2((elmtId, isInitialRender) => { 351 Checkbox.create({ name: '', group: 'checkboxGroup' }); 352 Checkbox.select(this.checkedInner); 353 Checkbox.onChange((checked) => { 354 this.checkedInner = checked; 355 this.onCheckedChange?.(checked); 356 }); 357 Checkbox.margin({ start: LengthMetrics.vp(0), end: LengthMetrics.vp(CHECK_BOX_MARGIN_END) }); 358 }, Checkbox); 359 Checkbox.pop(); 360 this.observeComponentCreation2((elmtId, isInitialRender) => { 361 Text.create(this.checkTips); 362 Text.fontSize(`${CONTENT_FONT_SIZE}fp`); 363 Text.fontWeight(FontWeight.Regular); 364 Text.fontColor(this.fontColorWithTheme); 365 Text.maxLines(CONTENT_MAX_LINES); 366 Text.layoutWeight(1); 367 Text.focusable(false); 368 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 369 }, Text); 370 Text.pop(); 371 }); 372 } 373 else { 374 this.ifElseBranchUpdateFunction(1, () => { 375 }); 376 } 377 }, If); 378 If.pop(); 379 Row.pop(); 380 } 381 imagePart(parent = null) { 382 this.observeComponentCreation2((elmtId, isInitialRender) => { 383 Column.create(); 384 Column.width('100%'); 385 }, Column); 386 this.observeComponentCreation2((elmtId, isInitialRender) => { 387 Image.create(this.imageRes); 388 Image.objectFit(ImageFit.Contain); 389 Image.borderRadius({ 'id': -1, 'type': 10002, params: ['sys.float.corner_radius_level6'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 390 Image.constraintSize({ 391 maxWidth: this.imageSize?.width ?? DEFAULT_IMAGE_SIZE, 392 maxHeight: this.imageSize?.height ?? DEFAULT_IMAGE_SIZE 393 }); 394 Image.outline({ 395 width: `${lengthMetricsToPX(this.imageBorderWidth)}px`, 396 radius: `${lengthMetricsToPX(LengthMetrics.resource({ 'id': -1, 'type': 10002, params: ['sys.float.corner_radius_level6'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' })) + 397 lengthMetricsToPX(this.imageBorderWidth)}px`, 398 color: this.imageBorderColor?.color 399 }); 400 }, Image); 401 Column.pop(); 402 } 403 textPart(parent = null) { 404 this.observeComponentCreation2((elmtId, isInitialRender) => { 405 Scroll.create(this.contentScroller); 406 Scroll.nestedScroll({ scrollForward: NestedScrollMode.PARALLEL, scrollBackward: NestedScrollMode.PARALLEL }); 407 Scroll.margin({ end: LengthMetrics.vp(0 - SCROLL_BAR_OFFSET) }); 408 }, Scroll); 409 this.observeComponentCreation2((elmtId, isInitialRender) => { 410 Column.create(); 411 Column.margin({ end: LengthMetrics.vp(SCROLL_BAR_OFFSET) }); 412 Column.width(`calc(100% - ${SCROLL_BAR_OFFSET}vp)`); 413 }, Column); 414 this.observeComponentCreation2((elmtId, isInitialRender) => { 415 If.create(); 416 if (this.title !== null) { 417 this.ifElseBranchUpdateFunction(0, () => { 418 this.observeComponentCreation2((elmtId, isInitialRender) => { 419 Row.create(); 420 Row.padding({ bottom: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level8'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } }); 421 }, Row); 422 this.observeComponentCreation2((elmtId, isInitialRender) => { 423 Text.create(this.title); 424 Text.fontSize(`${TITLE_S}fp`); 425 Text.maxFontScale(Math.min(this.appMaxFontScale, MAX_FONT_SCALE)); 426 Text.fontWeight(FontWeight.Bold); 427 Text.fontColor(this.fontColorWithTheme); 428 Text.textAlign(TextAlign.Center); 429 Text.maxLines(CONTENT_MAX_LINES); 430 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 431 Text.width('100%'); 432 }, Text); 433 Text.pop(); 434 Row.pop(); 435 }); 436 } 437 else { 438 this.ifElseBranchUpdateFunction(1, () => { 439 }); 440 } 441 }, If); 442 If.pop(); 443 this.observeComponentCreation2((elmtId, isInitialRender) => { 444 If.create(); 445 if (this.content !== null) { 446 this.ifElseBranchUpdateFunction(0, () => { 447 this.observeComponentCreation2((elmtId, isInitialRender) => { 448 Row.create(); 449 }, Row); 450 this.observeComponentCreation2((elmtId, isInitialRender) => { 451 Text.create(this.content); 452 Text.focusable(true); 453 Text.defaultFocus(!(this.primaryButton || this.secondaryButton)); 454 Text.focusBox({ 455 strokeWidth: LengthMetrics.px(0) 456 }); 457 Text.fontSize(this.getContentFontSize()); 458 Text.fontWeight(FontWeight.Medium); 459 Text.fontColor(this.fontColorWithTheme); 460 Text.textAlign(TextAlign.Center); 461 Text.width('100%'); 462 Text.onKeyEvent((event) => { 463 if (event) { 464 resolveKeyEvent(event, this.contentScroller); 465 } 466 }); 467 }, Text); 468 Text.pop(); 469 Row.pop(); 470 }); 471 } 472 else { 473 this.ifElseBranchUpdateFunction(1, () => { 474 }); 475 } 476 }, If); 477 If.pop(); 478 Column.pop(); 479 Scroll.pop(); 480 } 481 aboutToAppear() { 482 let uiContext = this.getUIContext(); 483 this.appMaxFontScale = uiContext.getMaxFontScale(); 484 this.checkedInner = this.checked; 485 } 486 getContentFontSize() { 487 return CONTENT_FONT_SIZE + 'fp'; 488 } 489 updateStateVars(params) { 490 if (params === undefined) { 491 return; 492 } 493 if ('imageRes' in params) { 494 this.updateParam('imageRes', params.imageRes); 495 } 496 if ('imageSize' in params) { 497 this.updateParam('imageSize', params.imageSize); 498 } 499 if ('imageBorderColor' in params) { 500 this.updateParam('imageBorderColor', params.imageBorderColor); 501 } 502 if ('imageBorderWidth' in params) { 503 this.updateParam('imageBorderWidth', params.imageBorderWidth); 504 } 505 if ('title' in params) { 506 this.updateParam('title', params.title); 507 } 508 if ('content' in params) { 509 this.updateParam('content', params.content); 510 } 511 if ('onCheckedChange' in params) { 512 this.updateParam('onCheckedChange', params.onCheckedChange); 513 } 514 if ('checkTips' in params) { 515 this.updateParam('checkTips', params.checkTips); 516 } 517 if ('checked' in params) { 518 this.updateParam('checked', params.checked); 519 } 520 if ('primaryButton' in params) { 521 this.updateParam('primaryButton', params.primaryButton); 522 } 523 if ('secondaryButton' in params) { 524 this.updateParam('secondaryButton', params.secondaryButton); 525 } 526 } 527 rerender() { 528 this.updateDirtyElements(); 529 } 530} 531__decorate([ 532 Param 533], TipsDialogV2.prototype, 'imageRes', void 0); 534__decorate([ 535 Param 536], TipsDialogV2.prototype, 'imageSize', void 0); 537__decorate([ 538 Param 539], TipsDialogV2.prototype, 'imageBorderColor', void 0); 540__decorate([ 541 Param 542], TipsDialogV2.prototype, 'imageBorderWidth', void 0); 543__decorate([ 544 Param 545], TipsDialogV2.prototype, 'title', void 0); 546__decorate([ 547 Param 548], TipsDialogV2.prototype, 'content', void 0); 549__decorate([ 550 Param 551], TipsDialogV2.prototype, 'onCheckedChange', void 0); 552__decorate([ 553 Param 554], TipsDialogV2.prototype, 'checkTips', void 0); 555__decorate([ 556 Param 557], TipsDialogV2.prototype, 'checked', void 0); 558__decorate([ 559 Local 560], TipsDialogV2.prototype, 'checkedInner', void 0); 561__decorate([ 562 Monitor('checked') 563], TipsDialogV2.prototype, 'checkedChangeMonitor', null); 564__decorate([ 565 Computed 566], TipsDialogV2.prototype, 'buttons', null); 567__decorate([ 568 Param 569], TipsDialogV2.prototype, 'primaryButton', void 0); 570__decorate([ 571 Param 572], TipsDialogV2.prototype, 'secondaryButton', void 0); 573__decorate([ 574 Local 575], TipsDialogV2.prototype, 'fontColorWithTheme', void 0); 576__decorate([ 577 Provider() 578], TipsDialogV2.prototype, 'fontSizeScale', void 0); 579__decorate([ 580 Local 581], TipsDialogV2.prototype, 'minContentHeight', void 0); 582class TipsDialogContentLayout extends ViewV2 { 583 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda, extraInfo) { 584 super(parent, elmtId, extraInfo); 585 this.initParam('title', (params && 'title' in params) ? params.title : null); 586 this.initParam('content', (params && 'content' in params) ? params.content : null); 587 this.initParam('checkTips', (params && 'checkTips' in params) ? params.checkTips : null); 588 this.initParam('minContentHeight', (params && 'minContentHeight' in params) ? params.minContentHeight : 0); 589 this.$minContentHeight = '$minContentHeight' in params ? params.$minContentHeight : undefined; 590 this.dialogBuilder = 'dialogBuilder' in params ? params.dialogBuilder : this.doNothingBuilder; 591 this.imageIndex = 0; 592 this.textIndex = 1; 593 this.checkBoxIndex = 2; 594 this.childrenSize = 3; 595 this.finalizeConstruction(); 596 } 597 doNothingBuilder(parent = null) { 598 } 599 ; 600 onPlaceChildren(selfLayoutInfo, children, constraint) { 601 let currentX = 0; 602 let currentY = 0; 603 for (let index = 0; index < children.length; index++) { 604 let child = children[index]; 605 child.layout({ x: currentX, y: currentY }); 606 currentY += child.measureResult.height; 607 } 608 } 609 onMeasureSize(selfLayoutInfo, children, constraint) { 610 let sizeResult = { width: Number(constraint.maxWidth), height: 0 }; 611 if (children.length < this.childrenSize) { 612 return sizeResult; 613 } 614 let height = 0; 615 let checkBoxHeight = 0; 616 if (this.checkTips !== null && this.checkTips !== undefined) { 617 let checkboxChild = children[this.checkBoxIndex]; 618 let checkboxConstraint = { 619 maxWidth: constraint.maxWidth, 620 minHeight: CHECKBOX_CONTAINER_HEIGHT, 621 maxHeight: constraint.maxHeight 622 }; 623 let checkBoxMeasureResult = checkboxChild.measure(checkboxConstraint); 624 checkBoxHeight = checkBoxMeasureResult.height; 625 height += checkBoxHeight; 626 } 627 let imageChild = children[this.imageIndex]; 628 let textMinHeight = 0; 629 if (this.title !== null || this.content !== null) { 630 textMinHeight = TEXT_MIN_HEIGHT + PADDING_LEVEL_8; 631 } 632 let imageMaxHeight = Number(constraint.maxHeight) - checkBoxHeight - textMinHeight; 633 let imageConstraint = { 634 maxWidth: constraint.maxWidth, 635 maxHeight: imageMaxHeight 636 }; 637 let imageMeasureResult = imageChild.measure(imageConstraint); 638 height += imageMeasureResult.height; 639 if (this.title !== null || this.content !== null) { 640 let textChild = children[this.textIndex]; 641 let contentMaxHeight = Number(constraint.maxHeight) - imageMeasureResult.height - checkBoxHeight; 642 let contentConstraint = { 643 maxWidth: constraint.maxWidth, 644 maxHeight: Math.max(contentMaxHeight, TEXT_MIN_HEIGHT) 645 }; 646 let contentMeasureResult = textChild.measure(contentConstraint); 647 height += contentMeasureResult.height; 648 } 649 sizeResult.height = height; 650 this.$minContentHeight?.(Math.max(checkBoxHeight + imageMeasureResult.height + textMinHeight, MIN_CONTENT_HEIGHT)); 651 return sizeResult; 652 } 653 initialRender() { 654 this.dialogBuilder.bind(this)(); 655 } 656 updateStateVars(params) { 657 if (params === undefined) { 658 return; 659 } 660 if ('title' in params) { 661 this.updateParam('title', params.title); 662 } 663 if ('content' in params) { 664 this.updateParam('content', params.content); 665 } 666 if ('checkTips' in params) { 667 this.updateParam('checkTips', params.checkTips); 668 } 669 if ('minContentHeight' in params) { 670 this.updateParam('minContentHeight', params.minContentHeight); 671 } 672 } 673 rerender() { 674 this.updateDirtyElements(); 675 } 676} 677__decorate([ 678 Param 679], TipsDialogContentLayout.prototype, 'title', void 0); 680__decorate([ 681 Param 682], TipsDialogContentLayout.prototype, 'content', void 0); 683__decorate([ 684 Param 685], TipsDialogContentLayout.prototype, 'checkTips', void 0); 686__decorate([ 687 Param 688], TipsDialogContentLayout.prototype, 'minContentHeight', void 0); 689__decorate([ 690 Event 691], TipsDialogContentLayout.prototype, '$minContentHeight', void 0); 692export class SelectDialogV2 extends ViewV2 { 693 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda, extraInfo) { 694 super(parent, elmtId, extraInfo); 695 this.initParam('title', (params && 'title' in params) ? params.title : ''); 696 this.initParam('content', (params && 'content' in params) ? params.content : ''); 697 this.initParam('confirm', (params && 'confirm' in params) ? params.confirm : null); 698 this.initParam('radioContent', (params && 'radioContent' in params) ? params.radioContent : []); 699 this.initParam('selectedIndex', (params && 'selectedIndex' in params) ? params.selectedIndex : -1); 700 this.selectedIndexInner = -1; 701 this.isFocus = false; 702 this.currentFocusIndex = -1; 703 this.radioHeight = 0; 704 this.itemHeight = 0; 705 this.contentBuilder = 'contentBuilder' in params ? params.contentBuilder : this.buildContent; 706 this.fontColorWithTheme = { 'id': -1, 'type': 10001, params: ['sys.color.font_primary'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }; 707 this.dividerColorWithTheme = { 'id': -1, 'type': 10001, params: ['sys.color.comp_divider'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }; 708 this.contentScroller = new Scroller(); 709 this.fontSizeScale = 1; 710 this.minContentHeight = MIN_CONTENT_HEIGHT; 711 this.finalizeConstruction(); 712 } 713 selectedIndexMonitor(monitor) { 714 this.selectedIndexInner = monitor.value('selectedIndex')?.now; 715 } 716 get buttons() { 717 let buttons = []; 718 if (this.confirm) { 719 buttons.push(this.confirm); 720 } 721 return buttons; 722 } 723 get contentPadding() { 724 if (!this.title && !this.confirm) { 725 return { 726 top: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level12'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 727 bottom: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level12'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } 728 }; 729 } 730 if (!this.title) { 731 return { 732 top: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level12'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } 733 }; 734 } 735 else if (!this.confirm) { 736 return { 737 bottom: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level12'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } 738 }; 739 } 740 return { 741 left: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level0'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 742 right: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level0'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } 743 }; 744 } 745 buildContent(parent = null) { 746 this.observeComponentCreation2((elmtId, isInitialRender) => { 747 Scroll.create(this.contentScroller); 748 Scroll.scrollBar(BarState.Auto); 749 Scroll.nestedScroll({ scrollForward: NestedScrollMode.PARALLEL, scrollBackward: NestedScrollMode.PARALLEL }); 750 Scroll.onDidScroll((xOffset, yOffset) => { 751 let scrollHeight = (this.itemHeight - this.radioHeight) / 2; 752 if (this.isFocus) { 753 if (this.currentFocusIndex === this.radioContent.length - 1) { 754 this.contentScroller.scrollEdge(Edge.Bottom); 755 this.currentFocusIndex = -1; 756 } 757 else if (this.currentFocusIndex === FIRST_ITEM_INDEX) { 758 this.contentScroller.scrollEdge(Edge.Top); 759 this.currentFocusIndex = -1; 760 } 761 else { 762 if (yOffset > 0) { 763 this.contentScroller.scrollBy(0, scrollHeight); 764 } 765 else if (yOffset < 0) { 766 this.contentScroller.scrollBy(0, 0 - scrollHeight); 767 } 768 } 769 this.isFocus = false; 770 } 771 }); 772 Scroll.margin({ end: LengthMetrics.vp(SELECT_DIALOG_SCROLL_BAR_OFFSET) }); 773 }, Scroll); 774 this.observeComponentCreation2((elmtId, isInitialRender) => { 775 Column.create(); 776 }, Column); 777 this.observeComponentCreation2((elmtId, isInitialRender) => { 778 If.create(); 779 if (this.content) { 780 this.ifElseBranchUpdateFunction(0, () => { 781 this.observeComponentCreation2((elmtId, isInitialRender) => { 782 Row.create(); 783 Row.padding({ 784 left: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level12'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 785 right: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level12'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 786 bottom: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level4'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } 787 }); 788 Row.width('100%'); 789 }, Row); 790 this.observeComponentCreation2((elmtId, isInitialRender) => { 791 Text.create(this.content); 792 Text.fontSize(`${BODY_M}fp`); 793 Text.fontWeight(FontWeight.Regular); 794 Text.fontColor(this.fontColorWithTheme); 795 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 796 }, Text); 797 Text.pop(); 798 Row.pop(); 799 }); 800 } 801 else { 802 this.ifElseBranchUpdateFunction(1, () => { 803 }); 804 } 805 }, If); 806 If.pop(); 807 this.observeComponentCreation2((elmtId, isInitialRender) => { 808 List.create(); 809 List.width('100%'); 810 List.clip(false); 811 List.onFocus(() => { 812 if (!this.contentScroller.isAtEnd()) { 813 this.contentScroller.scrollEdge(Edge.Top); 814 focusControl.requestFocus(String(FIRST_ITEM_INDEX)); 815 } 816 }); 817 List.defaultFocus(this.buttons?.length === 0 ? true : false); 818 }, List); 819 this.observeComponentCreation2((elmtId, isInitialRender) => { 820 ForEach.create(); 821 const forEachItemGenFunction = (_item, index) => { 822 const item = _item; 823 { 824 const itemCreation = (elmtId, isInitialRender) => { 825 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 826 itemCreation2(elmtId, isInitialRender); 827 if (!isInitialRender) { 828 ListItem.pop(); 829 } 830 ViewStackProcessor.StopGetAccessRecording(); 831 }; 832 const itemCreation2 = (elmtId, isInitialRender) => { 833 ListItem.create(deepRenderFunction, true); 834 ListItem.padding({ 835 left: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level6'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 836 right: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level6'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } 837 }); 838 ListItem.onSizeChange((oldValue, newValue) => { 839 this.itemHeight = Number(newValue.height); 840 }); 841 }; 842 const deepRenderFunction = (elmtId, isInitialRender) => { 843 itemCreation(elmtId, isInitialRender); 844 this.observeComponentCreation2((elmtId, isInitialRender) => { 845 Column.create(); 846 Column.borderRadius({ 'id': -1, 'type': 10002, params: ['sys.float.corner_radius_level8'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 847 Column.focusBox({ 848 margin: { value: -2, unit: LengthUnit.VP } 849 }); 850 Column.accessibilityText(getAccessibilityText(item.title, this.selectedIndexInner === index)); 851 Column.onClick(() => { 852 this.selectedIndexInner = index; 853 item.action && item.action(); 854 closeDialog(this.getDialogController(), 'onClick'); 855 }); 856 }, Column); 857 this.observeComponentCreation2((elmtId, isInitialRender) => { 858 Button.createWithChild(); 859 Button.type(ButtonType.Normal); 860 Button.borderRadius({ 'id': -1, 'type': 10002, params: ['sys.float.corner_radius_level8'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 861 Button.buttonStyle(ButtonStyleMode.TEXTUAL); 862 Button.padding({ 863 left: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level6'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 864 right: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level6'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } 865 }); 866 }, Button); 867 this.observeComponentCreation2((elmtId, isInitialRender) => { 868 Row.create(); 869 Row.constraintSize({ minHeight: LIST_MIN_HEIGHT }); 870 Row.clip(false); 871 Row.padding({ top: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level4'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, bottom: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level4'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } }); 872 }, Row); 873 this.observeComponentCreation2((elmtId, isInitialRender) => { 874 Text.create(item.title); 875 Text.fontSize(`${BODY_L}fp`); 876 Text.fontWeight(FontWeight.Medium); 877 Text.fontColor(this.fontColorWithTheme); 878 Text.layoutWeight(1); 879 Text.direction(i18n.isRTL(i18n.System.getSystemLanguage()) ? Direction.Rtl : Direction.Ltr); 880 }, Text); 881 Text.pop(); 882 this.observeComponentCreation2((elmtId, isInitialRender) => { 883 Radio.create({ value: 'item.title', group: 'radioGroup' }); 884 Radio.size({ width: CHECKBOX_CONTAINER_LENGTH, height: CHECKBOX_CONTAINER_LENGTH }); 885 Radio.checked(this.selectedIndexInner === index); 886 Radio.hitTestBehavior(HitTestMode.None); 887 Radio.id(String(index)); 888 Radio.focusable(false); 889 Radio.accessibilityLevel('no'); 890 Radio.visibility(this.selectedIndex === index ? Visibility.Visible : Visibility.Hidden); 891 Radio.radioStyle({ uncheckedBorderColor: Color.Transparent }); 892 Radio.onFocus(() => { 893 this.isFocus = true; 894 this.currentFocusIndex = index; 895 if (index === FIRST_ITEM_INDEX) { 896 this.contentScroller.scrollEdge(Edge.Top); 897 } 898 else if (index === this.radioContent.length - 1) { 899 this.contentScroller.scrollEdge(Edge.Bottom); 900 } 901 }); 902 Radio.onSizeChange((oldValue, newValue) => { 903 this.radioHeight = Number(newValue.height); 904 }); 905 }, Radio); 906 Row.pop(); 907 Button.pop(); 908 this.observeComponentCreation2((elmtId, isInitialRender) => { 909 If.create(); 910 if (index < this.radioContent.length - 1) { 911 this.ifElseBranchUpdateFunction(0, () => { 912 this.observeComponentCreation2((elmtId, isInitialRender) => { 913 Divider.create(); 914 Divider.color(this.dividerColorWithTheme); 915 Divider.padding({ 916 left: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level6'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 917 right: { 'id': -1, 'type': 10002, params: ['sys.float.padding_level6'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } 918 }); 919 }, Divider); 920 }); 921 } 922 else { 923 this.ifElseBranchUpdateFunction(1, () => { 924 }); 925 } 926 }, If); 927 If.pop(); 928 Column.pop(); 929 ListItem.pop(); 930 }; 931 this.observeComponentCreation2(itemCreation2, ListItem); 932 ListItem.pop(); 933 } 934 }; 935 this.forEachUpdateFunction(elmtId, this.radioContent, forEachItemGenFunction, undefined, true, false); 936 }, ForEach); 937 ForEach.pop(); 938 List.pop(); 939 Column.pop(); 940 Scroll.pop(); 941 } 942 initialRender() { 943 this.observeComponentCreation2((elmtId, isInitialRender) => { 944 __Common__.create(); 945 __Common__.constraintSize({ maxHeight: '100%' }); 946 }, __Common__); 947 { 948 this.observeComponentCreation2((elmtId, isInitialRender) => { 949 if (isInitialRender) { 950 let componentCall = new CustomDialogContentComponent(this, { 951 primaryTitle: this.title, 952 contentBuilder: () => { 953 this.contentBuilder(); 954 }, 955 buttons: this.buttons, 956 contentAreaPadding: this.contentPadding, 957 minContentHeight: this.minContentHeight, 958 $minContentHeight: value => { this.minContentHeight = value; } 959 }, undefined, elmtId, () => { }, { page: 'library/src/main/ets/components/dialog.ets', line: 603, col: 5 }); 960 ViewV2.create(componentCall); 961 let paramsLambda = () => { 962 return { 963 primaryTitle: this.title, 964 contentBuilder: () => { 965 this.contentBuilder(); 966 }, 967 buttons: this.buttons, 968 contentAreaPadding: this.contentPadding, 969 minContentHeight: this.minContentHeight 970 }; 971 }; 972 componentCall.paramsGenerator_ = paramsLambda; 973 } 974 else { 975 this.updateStateVarsOfChildByElmtId(elmtId, { 976 primaryTitle: this.title, 977 buttons: this.buttons, 978 contentAreaPadding: this.contentPadding, 979 minContentHeight: this.minContentHeight 980 }); 981 } 982 }, { name: 'CustomDialogContentComponent' }); 983 } 984 __Common__.pop(); 985 } 986 onWillApplyTheme(theme) { 987 this.fontColorWithTheme = theme.colors.fontPrimary; 988 this.dividerColorWithTheme = theme.colors.compDivider; 989 } 990 aboutToAppear() { 991 this.selectedIndexInner = this.selectedIndex; 992 } 993 updateStateVars(params) { 994 if (params === undefined) { 995 return; 996 } 997 if ('title' in params) { 998 this.updateParam('title', params.title); 999 } 1000 if ('content' in params) { 1001 this.updateParam('content', params.content); 1002 } 1003 if ('confirm' in params) { 1004 this.updateParam('confirm', params.confirm); 1005 } 1006 if ('radioContent' in params) { 1007 this.updateParam('radioContent', params.radioContent); 1008 } 1009 if ('selectedIndex' in params) { 1010 this.updateParam('selectedIndex', params.selectedIndex); 1011 } 1012 } 1013 rerender() { 1014 this.updateDirtyElements(); 1015 } 1016} 1017__decorate([ 1018 Param 1019], SelectDialogV2.prototype, 'title', void 0); 1020__decorate([ 1021 Param 1022], SelectDialogV2.prototype, 'content', void 0); 1023__decorate([ 1024 Param 1025], SelectDialogV2.prototype, 'confirm', void 0); 1026__decorate([ 1027 Param 1028], SelectDialogV2.prototype, 'radioContent', void 0); 1029__decorate([ 1030 Param 1031], SelectDialogV2.prototype, 'selectedIndex', void 0); 1032__decorate([ 1033 Local 1034], SelectDialogV2.prototype, 'selectedIndexInner', void 0); 1035__decorate([ 1036 Monitor('selectedIndex') 1037], SelectDialogV2.prototype, 'selectedIndexMonitor', null); 1038__decorate([ 1039 Local 1040], SelectDialogV2.prototype, 'isFocus', void 0); 1041__decorate([ 1042 Local 1043], SelectDialogV2.prototype, 'currentFocusIndex', void 0); 1044__decorate([ 1045 Local 1046], SelectDialogV2.prototype, 'radioHeight', void 0); 1047__decorate([ 1048 Local 1049], SelectDialogV2.prototype, 'itemHeight', void 0); 1050__decorate([ 1051 Local 1052], SelectDialogV2.prototype, 'fontColorWithTheme', void 0); 1053__decorate([ 1054 Local 1055], SelectDialogV2.prototype, 'dividerColorWithTheme', void 0); 1056__decorate([ 1057 Provider() 1058], SelectDialogV2.prototype, 'fontSizeScale', void 0); 1059__decorate([ 1060 Local 1061], SelectDialogV2.prototype, 'minContentHeight', void 0); 1062__decorate([ 1063 Computed 1064], SelectDialogV2.prototype, 'buttons', null); 1065__decorate([ 1066 Computed 1067], SelectDialogV2.prototype, 'contentPadding', null); 1068class ConfirmDialogContentLayout extends ViewV2 { 1069 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda, extraInfo) { 1070 super(parent, elmtId, extraInfo); 1071 this.textIndex = 0; 1072 this.checkboxIndex = 1; 1073 this.initParam('minContentHeight', (params && 'minContentHeight' in params) ? params.minContentHeight : 0); 1074 this.$minContentHeight = '$minContentHeight' in params ? params.$minContentHeight : undefined; 1075 this.dialogBuilder = 'dialogBuilder' in params ? params.dialogBuilder : this.doNothingBuilder; 1076 this.finalizeConstruction(); 1077 } 1078 doNothingBuilder(parent = null) { 1079 } 1080 ; 1081 onPlaceChildren(selfLayoutInfo, children, constraint) { 1082 let currentX = 0; 1083 let currentY = 0; 1084 for (let index = 0; index < children.length; index++) { 1085 let child = children[index]; 1086 child.layout({ x: currentX, y: currentY }); 1087 currentY += child.measureResult.height; 1088 } 1089 } 1090 onMeasureSize(selfLayoutInfo, children, constraint) { 1091 let sizeResult = { width: Number(constraint.maxWidth), height: 0 }; 1092 let childrenSize = 2; 1093 if (children.length < childrenSize) { 1094 return sizeResult; 1095 } 1096 let height = 0; 1097 let checkboxChild = children[this.checkboxIndex]; 1098 let checkboxConstraint = { 1099 maxWidth: constraint.maxWidth, 1100 minHeight: CHECKBOX_CONTAINER_HEIGHT, 1101 maxHeight: constraint.maxHeight 1102 }; 1103 let checkBoxMeasureResult = checkboxChild.measure(checkboxConstraint); 1104 height += checkBoxMeasureResult.height; 1105 let textChild = children[this.textIndex]; 1106 let textConstraint = { 1107 maxWidth: constraint.maxWidth, 1108 maxHeight: Number(constraint.maxHeight) - height 1109 }; 1110 let textMeasureResult = textChild.measure(textConstraint); 1111 height += textMeasureResult.height; 1112 sizeResult.height = height; 1113 this.$minContentHeight?.(Math.max(checkBoxMeasureResult.height + TEXT_MIN_HEIGHT, MIN_CONTENT_HEIGHT)); 1114 return sizeResult; 1115 } 1116 initialRender() { 1117 this.dialogBuilder.bind(this)(); 1118 } 1119 updateStateVars(params) { 1120 if (params === undefined) { 1121 return; 1122 } 1123 if ('minContentHeight' in params) { 1124 this.updateParam('minContentHeight', params.minContentHeight); 1125 } 1126 } 1127 rerender() { 1128 this.updateDirtyElements(); 1129 } 1130} 1131__decorate([ 1132 Param 1133], ConfirmDialogContentLayout.prototype, 'minContentHeight', void 0); 1134__decorate([ 1135 Event 1136], ConfirmDialogContentLayout.prototype, '$minContentHeight', void 0); 1137export class ConfirmDialogV2 extends ViewV2 { 1138 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda, extraInfo) { 1139 super(parent, elmtId, extraInfo); 1140 this.initParam('title', (params && 'title' in params) ? params.title : ''); 1141 this.initParam('content', (params && 'content' in params) ? params.content : ''); 1142 this.initParam('checkTips', (params && 'checkTips' in params) ? params.checkTips : ''); 1143 this.initParam('checked', (params && 'checked' in params) ? params.checked : false); 1144 this.checkedInner = this.checked; 1145 this.initParam('primaryButton', (params && 'primaryButton' in params) ? params.primaryButton : new AdvancedDialogV2Button({ content: '' })); 1146 this.initParam('secondaryButton', (params && 'secondaryButton' in params) ? params.secondaryButton : new AdvancedDialogV2Button({ content: '' })); 1147 this.fontColorWithTheme = { 'id': -1, 'type': 10001, params: ['sys.color.font_primary'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }; 1148 this.initParam('onCheckedChange', (params && 'onCheckedChange' in params) ? params.onCheckedChange : undefined); 1149 this.contentScroller = new Scroller(); 1150 this.marginOffset = 0 - PADDING_LEVEL_8; 1151 this.fontSizeScale = 1; 1152 this.minContentHeight = MIN_CONTENT_HEIGHT; 1153 this.textIndex = 0; 1154 this.checkboxIndex = 1; 1155 this.finalizeConstruction(); 1156 } 1157 checkedMonitor(monitor) { 1158 this.checkedInner = monitor.value('checked')?.now; 1159 } 1160 get buttons() { 1161 if (!this.primaryButton && !this.secondaryButton) { 1162 return undefined; 1163 } 1164 let buttons = []; 1165 if (this.primaryButton) { 1166 buttons.push(this.primaryButton); 1167 } 1168 if (this.secondaryButton) { 1169 buttons.push(this.secondaryButton); 1170 } 1171 return buttons; 1172 } 1173 textBuilder(parent = null) { 1174 this.observeComponentCreation2((elmtId, isInitialRender) => { 1175 Column.create(); 1176 }, Column); 1177 this.observeComponentCreation2((elmtId, isInitialRender) => { 1178 Scroll.create(this.contentScroller); 1179 Scroll.nestedScroll({ scrollForward: NestedScrollMode.PARALLEL, scrollBackward: NestedScrollMode.PARALLEL }); 1180 Scroll.margin({ end: LengthMetrics.vp(0 - SCROLL_BAR_OFFSET) }); 1181 }, Scroll); 1182 this.observeComponentCreation2((elmtId, isInitialRender) => { 1183 Column.create(); 1184 Column.margin({ end: LengthMetrics.vp(SCROLL_BAR_OFFSET) }); 1185 Column.width(`calc(100% - ${SCROLL_BAR_OFFSET}vp)`); 1186 }, Column); 1187 this.observeComponentCreation2((elmtId, isInitialRender) => { 1188 Text.create(this.content); 1189 Text.focusable(true); 1190 Text.defaultFocus(!(this.primaryButton?.content || this.secondaryButton?.content)); 1191 Text.focusBox({ 1192 strokeWidth: LengthMetrics.px(0) 1193 }); 1194 Text.fontSize(`${CONTENT_FONT_SIZE}fp`); 1195 Text.fontWeight(FontWeight.Medium); 1196 Text.fontColor(this.fontColorWithTheme); 1197 Text.textAlign(TextAlign.Center); 1198 Text.onKeyEvent((event) => { 1199 if (event) { 1200 resolveKeyEvent(event, this.contentScroller); 1201 } 1202 }); 1203 Text.width('100%'); 1204 }, Text); 1205 Text.pop(); 1206 Column.pop(); 1207 Scroll.pop(); 1208 Column.pop(); 1209 } 1210 checkBoxBuilder(parent = null) { 1211 this.observeComponentCreation2((elmtId, isInitialRender) => { 1212 Row.create(); 1213 Row.accessibilityGroup(true); 1214 Row.accessibilityText(getCheckTipsAccessibilityText(this.checkTips, this.checkedInner)); 1215 Row.accessibilityDescription(this.checkedInner ? { 'id': -1, 'type': 10003, params: ['sys.string.advanced_dialog_accessibility_cancel_checked_desc'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } : { 'id': -1, 'type': 10003, params: ['sys.string.slider_accessibility_unselectedDesc'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 1216 Row.onClick(() => { 1217 this.checkedInner = !this.checkedInner; 1218 try { 1219 let eventInfo = ({ 1220 type: 'announceForAccessibility', 1221 bundleName: getContext()?.abilityInfo?.bundleName, 1222 triggerAction: 'common', 1223 textAnnouncedForAccessibility: this.checkedInner ? getContext().resourceManager.getStringSync(125833934) : 1224 getContext().resourceManager.getStringSync(125833935) 1225 }); 1226 accessibility.sendAccessibilityEvent(eventInfo); 1227 } 1228 catch (exception) { 1229 let code = exception.code; 1230 let message = exception.message; 1231 hilog.error(0x3900, 'Ace', `Faild to send event, cause, code: ${code}, message: ${message}`); 1232 } 1233 }); 1234 Row.width('100%'); 1235 Row.padding({ top: 8, bottom: 8 }); 1236 }, Row); 1237 this.observeComponentCreation2((elmtId, isInitialRender) => { 1238 Checkbox.create({ name: '', group: 'checkboxGroup' }); 1239 Checkbox.select(this.checkedInner); 1240 Checkbox.onChange((checked) => { 1241 this.checkedInner = checked; 1242 if (this.onCheckedChange) { 1243 this.onCheckedChange(this.checkedInner); 1244 } 1245 }); 1246 Checkbox.hitTestBehavior(HitTestMode.Block); 1247 Checkbox.margin({ start: LengthMetrics.vp(0), end: LengthMetrics.vp(CHECK_BOX_MARGIN_END) }); 1248 }, Checkbox); 1249 Checkbox.pop(); 1250 this.observeComponentCreation2((elmtId, isInitialRender) => { 1251 Text.create(this.checkTips); 1252 Text.fontSize(`${BODY_M}fp`); 1253 Text.fontWeight(FontWeight.Medium); 1254 Text.fontColor(this.fontColorWithTheme); 1255 Text.maxLines(CONTENT_MAX_LINES); 1256 Text.focusable(false); 1257 Text.layoutWeight(1); 1258 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 1259 }, Text); 1260 Text.pop(); 1261 Row.pop(); 1262 } 1263 buildContent(parent = null) { 1264 { 1265 this.observeComponentCreation2((elmtId, isInitialRender) => { 1266 if (isInitialRender) { 1267 let componentCall = new ConfirmDialogContentLayout(this, { 1268 minContentHeight: this.minContentHeight, 1269 dialogBuilder: () => { 1270 this.observeComponentCreation2((elmtId, isInitialRender) => { 1271 ForEach.create(); 1272 const forEachItemGenFunction = _item => { 1273 const index = _item; 1274 this.observeComponentCreation2((elmtId, isInitialRender) => { 1275 If.create(); 1276 if (index === this.textIndex) { 1277 this.ifElseBranchUpdateFunction(0, () => { 1278 this.textBuilder.bind(this)(); 1279 }); 1280 } 1281 else if (index === this.checkboxIndex) { 1282 this.ifElseBranchUpdateFunction(1, () => { 1283 this.checkBoxBuilder.bind(this)(); 1284 }); 1285 } 1286 else { 1287 this.ifElseBranchUpdateFunction(2, () => { 1288 }); 1289 } 1290 }, If); 1291 If.pop(); 1292 }; 1293 this.forEachUpdateFunction(elmtId, [this.textIndex, this.checkboxIndex], forEachItemGenFunction); 1294 }, ForEach); 1295 ForEach.pop(); 1296 }, 1297 $minContentHeight: value => { this.minContentHeight = value; } 1298 }, undefined, elmtId, () => { }, { page: 'library/src/main/ets/components/dialog.ets', line: 801, col: 5 }); 1299 ViewV2.create(componentCall); 1300 let paramsLambda = () => { 1301 return { 1302 minContentHeight: this.minContentHeight, 1303 dialogBuilder: () => { 1304 this.observeComponentCreation2((elmtId, isInitialRender) => { 1305 ForEach.create(); 1306 const forEachItemGenFunction = _item => { 1307 const index = _item; 1308 this.observeComponentCreation2((elmtId, isInitialRender) => { 1309 If.create(); 1310 if (index === this.textIndex) { 1311 this.ifElseBranchUpdateFunction(0, () => { 1312 this.textBuilder.bind(this)(); 1313 }); 1314 } 1315 else if (index === this.checkboxIndex) { 1316 this.ifElseBranchUpdateFunction(1, () => { 1317 this.checkBoxBuilder.bind(this)(); 1318 }); 1319 } 1320 else { 1321 this.ifElseBranchUpdateFunction(2, () => { 1322 }); 1323 } 1324 }, If); 1325 If.pop(); 1326 }; 1327 this.forEachUpdateFunction(elmtId, [this.textIndex, this.checkboxIndex], forEachItemGenFunction); 1328 }, ForEach); 1329 ForEach.pop(); 1330 } 1331 }; 1332 }; 1333 componentCall.paramsGenerator_ = paramsLambda; 1334 } 1335 else { 1336 this.updateStateVarsOfChildByElmtId(elmtId, { 1337 minContentHeight: this.minContentHeight 1338 }); 1339 } 1340 }, { name: 'ConfirmDialogContentLayout' }); 1341 } 1342 } 1343 initialRender() { 1344 this.observeComponentCreation2((elmtId, isInitialRender) => { 1345 __Common__.create(); 1346 __Common__.constraintSize({ maxHeight: '100%' }); 1347 }, __Common__); 1348 { 1349 this.observeComponentCreation2((elmtId, isInitialRender) => { 1350 if (isInitialRender) { 1351 let componentCall = new CustomDialogContentComponent(this, { 1352 primaryTitle: this.title, 1353 contentBuilder: () => { 1354 this.buildContent(); 1355 }, 1356 minContentHeight: this.minContentHeight, 1357 buttons: this.buttons, 1358 $minContentHeight: value => { this.minContentHeight = value; } 1359 }, undefined, elmtId, () => { }, { page: 'library/src/main/ets/components/dialog.ets', line: 813, col: 5 }); 1360 ViewV2.create(componentCall); 1361 let paramsLambda = () => { 1362 return { 1363 primaryTitle: this.title, 1364 contentBuilder: () => { 1365 this.buildContent(); 1366 }, 1367 minContentHeight: this.minContentHeight, 1368 buttons: this.buttons 1369 }; 1370 }; 1371 componentCall.paramsGenerator_ = paramsLambda; 1372 } 1373 else { 1374 this.updateStateVarsOfChildByElmtId(elmtId, { 1375 primaryTitle: this.title, 1376 minContentHeight: this.minContentHeight, 1377 buttons: this.buttons 1378 }); 1379 } 1380 }, { name: 'CustomDialogContentComponent' }); 1381 } 1382 __Common__.pop(); 1383 } 1384 onWillApplyTheme(theme) { 1385 this.fontColorWithTheme = theme.colors.fontPrimary; 1386 } 1387 updateStateVars(params) { 1388 if (params === undefined) { 1389 return; 1390 } 1391 if ('title' in params) { 1392 this.updateParam('title', params.title); 1393 } 1394 if ('content' in params) { 1395 this.updateParam('content', params.content); 1396 } 1397 if ('checkTips' in params) { 1398 this.updateParam('checkTips', params.checkTips); 1399 } 1400 if ('checked' in params) { 1401 this.updateParam('checked', params.checked); 1402 } 1403 if ('primaryButton' in params) { 1404 this.updateParam('primaryButton', params.primaryButton); 1405 } 1406 if ('secondaryButton' in params) { 1407 this.updateParam('secondaryButton', params.secondaryButton); 1408 } 1409 if ('onCheckedChange' in params) { 1410 this.updateParam('onCheckedChange', params.onCheckedChange); 1411 } 1412 } 1413 rerender() { 1414 this.updateDirtyElements(); 1415 } 1416} 1417__decorate([ 1418 Param 1419], ConfirmDialogV2.prototype, 'title', void 0); 1420__decorate([ 1421 Param 1422], ConfirmDialogV2.prototype, 'content', void 0); 1423__decorate([ 1424 Param 1425], ConfirmDialogV2.prototype, 'checkTips', void 0); 1426__decorate([ 1427 Param 1428], ConfirmDialogV2.prototype, 'checked', void 0); 1429__decorate([ 1430 Local 1431], ConfirmDialogV2.prototype, 'checkedInner', void 0); 1432__decorate([ 1433 Monitor('checked') 1434], ConfirmDialogV2.prototype, 'checkedMonitor', null); 1435__decorate([ 1436 Param 1437], ConfirmDialogV2.prototype, 'primaryButton', void 0); 1438__decorate([ 1439 Param 1440], ConfirmDialogV2.prototype, 'secondaryButton', void 0); 1441__decorate([ 1442 Local 1443], ConfirmDialogV2.prototype, 'fontColorWithTheme', void 0); 1444__decorate([ 1445 Param 1446], ConfirmDialogV2.prototype, 'onCheckedChange', void 0); 1447__decorate([ 1448 Provider() 1449], ConfirmDialogV2.prototype, 'fontSizeScale', void 0); 1450__decorate([ 1451 Local 1452], ConfirmDialogV2.prototype, 'minContentHeight', void 0); 1453__decorate([ 1454 Computed 1455], ConfirmDialogV2.prototype, 'buttons', null); 1456export class AlertDialogV2 extends ViewV2 { 1457 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda, extraInfo) { 1458 super(parent, elmtId, extraInfo); 1459 this.initParam('primaryTitle', (params && 'primaryTitle' in params) ? params.primaryTitle : undefined); 1460 this.initParam('secondaryTitle', (params && 'secondaryTitle' in params) ? params.secondaryTitle : undefined); 1461 this.initParam('content', (params && 'content' in params) ? params.content : ''); 1462 this.initParam('primaryButton', (params && 'primaryButton' in params) ? params.primaryButton : null); 1463 this.initParam('secondaryButton', (params && 'secondaryButton' in params) ? params.secondaryButton : null); 1464 this.textAlign = TextAlign.Center; 1465 this.contentScroller = new Scroller(); 1466 this.fontColorWithTheme = { 'id': -1, 'type': 10001, params: ['sys.color.font_primary'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }; 1467 this.fontSizeScale = 1; 1468 this.minContentHeight = MIN_CONTENT_HEIGHT; 1469 this.finalizeConstruction(); 1470 } 1471 get buttons() { 1472 if (!this.primaryButton && !this.secondaryButton) { 1473 return undefined; 1474 } 1475 let buttons = []; 1476 if (this.primaryButton) { 1477 buttons.push(this.primaryButton); 1478 } 1479 if (this.secondaryButton) { 1480 buttons.push(this.secondaryButton); 1481 } 1482 return buttons; 1483 } 1484 initialRender() { 1485 this.observeComponentCreation2((elmtId, isInitialRender) => { 1486 __Common__.create(); 1487 __Common__.constraintSize({ maxHeight: '100%' }); 1488 }, __Common__); 1489 { 1490 this.observeComponentCreation2((elmtId, isInitialRender) => { 1491 if (isInitialRender) { 1492 let componentCall = new CustomDialogContentComponent(this, { 1493 primaryTitle: this.primaryTitle, 1494 secondaryTitle: this.secondaryTitle, 1495 contentBuilder: () => { 1496 this.AlertDialogContentBuilder(); 1497 }, 1498 buttons: this.buttons, 1499 minContentHeight: this.minContentHeight, 1500 $minContentHeight: value => { this.minContentHeight = value; } 1501 }, undefined, elmtId, () => { }, { page: 'library/src/main/ets/components/dialog.ets', line: 858, col: 5 }); 1502 ViewV2.create(componentCall); 1503 let paramsLambda = () => { 1504 return { 1505 primaryTitle: this.primaryTitle, 1506 secondaryTitle: this.secondaryTitle, 1507 contentBuilder: () => { 1508 this.AlertDialogContentBuilder(); 1509 }, 1510 buttons: this.buttons, 1511 minContentHeight: this.minContentHeight 1512 }; 1513 }; 1514 componentCall.paramsGenerator_ = paramsLambda; 1515 } 1516 else { 1517 this.updateStateVarsOfChildByElmtId(elmtId, { 1518 primaryTitle: this.primaryTitle, 1519 secondaryTitle: this.secondaryTitle, 1520 buttons: this.buttons, 1521 minContentHeight: this.minContentHeight 1522 }); 1523 } 1524 }, { name: 'CustomDialogContentComponent' }); 1525 } 1526 __Common__.pop(); 1527 } 1528 AlertDialogContentBuilder(parent = null) { 1529 this.observeComponentCreation2((elmtId, isInitialRender) => { 1530 Column.create(); 1531 Column.margin({ end: LengthMetrics.vp(0 - SCROLL_BAR_OFFSET) }); 1532 }, Column); 1533 this.observeComponentCreation2((elmtId, isInitialRender) => { 1534 Scroll.create(this.contentScroller); 1535 Scroll.nestedScroll({ scrollForward: NestedScrollMode.PARALLEL, scrollBackward: NestedScrollMode.PARALLEL }); 1536 Scroll.width('100%'); 1537 }, Scroll); 1538 this.observeComponentCreation2((elmtId, isInitialRender) => { 1539 Text.create(this.content); 1540 Text.focusable(true); 1541 Text.defaultFocus(!(this.primaryButton || this.secondaryButton)); 1542 Text.focusBox({ 1543 strokeWidth: LengthMetrics.px(0) 1544 }); 1545 Text.fontSize(`${CONTENT_FONT_SIZE}fp`); 1546 Text.fontWeight(this.getFontWeight()); 1547 Text.fontColor(this.fontColorWithTheme); 1548 Text.margin({ end: LengthMetrics.vp(SCROLL_BAR_OFFSET) }); 1549 Text.width(`calc(100% - ${SCROLL_BAR_OFFSET}vp)`); 1550 Text.textAlign(this.textAlign); 1551 Text.onKeyEvent((event) => { 1552 if (event) { 1553 resolveKeyEvent(event, this.contentScroller); 1554 } 1555 }); 1556 }, Text); 1557 Text.pop(); 1558 Scroll.pop(); 1559 Column.pop(); 1560 } 1561 onWillApplyTheme(theme) { 1562 this.fontColorWithTheme = theme.colors.fontPrimary; 1563 } 1564 getFontWeight() { 1565 if (this.primaryTitle || this.secondaryTitle) { 1566 return FontWeight.Regular; 1567 } 1568 return FontWeight.Medium; 1569 } 1570 updateStateVars(params) { 1571 if (params === undefined) { 1572 return; 1573 } 1574 if ('primaryTitle' in params) { 1575 this.updateParam('primaryTitle', params.primaryTitle); 1576 } 1577 if ('secondaryTitle' in params) { 1578 this.updateParam('secondaryTitle', params.secondaryTitle); 1579 } 1580 if ('content' in params) { 1581 this.updateParam('content', params.content); 1582 } 1583 if ('primaryButton' in params) { 1584 this.updateParam('primaryButton', params.primaryButton); 1585 } 1586 if ('secondaryButton' in params) { 1587 this.updateParam('secondaryButton', params.secondaryButton); 1588 } 1589 } 1590 rerender() { 1591 this.updateDirtyElements(); 1592 } 1593} 1594__decorate([ 1595 Param 1596], AlertDialogV2.prototype, 'primaryTitle', void 0); 1597__decorate([ 1598 Param 1599], AlertDialogV2.prototype, 'secondaryTitle', void 0); 1600__decorate([ 1601 Param 1602], AlertDialogV2.prototype, 'content', void 0); 1603__decorate([ 1604 Param 1605], AlertDialogV2.prototype, 'primaryButton', void 0); 1606__decorate([ 1607 Param 1608], AlertDialogV2.prototype, 'secondaryButton', void 0); 1609__decorate([ 1610 Local 1611], AlertDialogV2.prototype, 'fontColorWithTheme', void 0); 1612__decorate([ 1613 Provider() 1614], AlertDialogV2.prototype, 'fontSizeScale', void 0); 1615__decorate([ 1616 Local 1617], AlertDialogV2.prototype, 'minContentHeight', void 0); 1618__decorate([ 1619 Computed 1620], AlertDialogV2.prototype, 'buttons', null); 1621export class CustomContentDialogV2 extends ViewV2 { 1622 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda, extraInfo) { 1623 super(parent, elmtId, extraInfo); 1624 this.initParam('primaryTitle', (params && 'primaryTitle' in params) ? params.primaryTitle : undefined); 1625 this.initParam('secondaryTitle', (params && 'secondaryTitle' in params) ? params.secondaryTitle : undefined); 1626 this.contentBuilder = 'contentBuilder' in params ? params.contentBuilder : undefined; 1627 this.initParam('contentAreaPadding', (params && 'contentAreaPadding' in params) ? params.contentAreaPadding : undefined); 1628 this.initParam('buttons', (params && 'buttons' in params) ? params.buttons : undefined); 1629 this.fontSizeScale = 1; 1630 this.minContentHeight = MIN_CONTENT_HEIGHT; 1631 this.finalizeConstruction(); 1632 } 1633 initialRender() { 1634 this.observeComponentCreation2((elmtId, isInitialRender) => { 1635 __Common__.create(); 1636 __Common__.constraintSize({ maxHeight: '100%' }); 1637 }, __Common__); 1638 { 1639 this.observeComponentCreation2((elmtId, isInitialRender) => { 1640 if (isInitialRender) { 1641 let componentCall = new CustomDialogContentComponent(this, { 1642 primaryTitle: this.primaryTitle, 1643 secondaryTitle: this.secondaryTitle, 1644 contentBuilder: () => { 1645 if (typeof this.contentBuilder === 'function') { 1646 this.contentBuilder(); 1647 } 1648 }, 1649 contentAreaPadding: this.contentAreaPadding, 1650 buttons: this.buttons, 1651 minContentHeight: this.minContentHeight, 1652 $minContentHeight: value => { this.minContentHeight = value; } 1653 }, undefined, elmtId, () => { }, { page: 'library/src/main/ets/components/dialog.ets', line: 920, col: 5 }); 1654 ViewV2.create(componentCall); 1655 let paramsLambda = () => { 1656 return { 1657 primaryTitle: this.primaryTitle, 1658 secondaryTitle: this.secondaryTitle, 1659 contentBuilder: () => { 1660 if (typeof this.contentBuilder === 'function') { 1661 this.contentBuilder(); 1662 } 1663 }, 1664 contentAreaPadding: this.contentAreaPadding, 1665 buttons: this.buttons, 1666 minContentHeight: this.minContentHeight 1667 }; 1668 }; 1669 componentCall.paramsGenerator_ = paramsLambda; 1670 } 1671 else { 1672 this.updateStateVarsOfChildByElmtId(elmtId, { 1673 primaryTitle: this.primaryTitle, 1674 secondaryTitle: this.secondaryTitle, 1675 contentAreaPadding: this.contentAreaPadding, 1676 buttons: this.buttons, 1677 minContentHeight: this.minContentHeight 1678 }); 1679 } 1680 }, { name: 'CustomDialogContentComponent' }); 1681 } 1682 __Common__.pop(); 1683 } 1684 updateStateVars(params) { 1685 if (params === undefined) { 1686 return; 1687 } 1688 if ('primaryTitle' in params) { 1689 this.updateParam('primaryTitle', params.primaryTitle); 1690 } 1691 if ('secondaryTitle' in params) { 1692 this.updateParam('secondaryTitle', params.secondaryTitle); 1693 } 1694 if ('contentAreaPadding' in params) { 1695 this.updateParam('contentAreaPadding', params.contentAreaPadding); 1696 } 1697 if ('buttons' in params) { 1698 this.updateParam('buttons', params.buttons); 1699 } 1700 } 1701 rerender() { 1702 this.updateDirtyElements(); 1703 } 1704} 1705__decorate([ 1706 Param 1707], CustomContentDialogV2.prototype, 'primaryTitle', void 0); 1708__decorate([ 1709 Param 1710], CustomContentDialogV2.prototype, 'secondaryTitle', void 0); 1711__decorate([ 1712 Param 1713], CustomContentDialogV2.prototype, 'contentAreaPadding', void 0); 1714__decorate([ 1715 Param 1716], CustomContentDialogV2.prototype, 'buttons', void 0); 1717__decorate([ 1718 Provider() 1719], CustomContentDialogV2.prototype, 'fontSizeScale', void 0); 1720__decorate([ 1721 Local 1722], CustomContentDialogV2.prototype, 'minContentHeight', void 0); 1723class CustomDialogLayout extends ViewV2 { 1724 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda, extraInfo) { 1725 super(parent, elmtId, extraInfo); 1726 this.initParam('titleHeight', (params && 'titleHeight' in params) ? params.titleHeight : 0); 1727 this.$titleHeight = '$titleHeight' in params ? params.$titleHeight : undefined; 1728 this.initParam('buttonHeight', (params && 'buttonHeight' in params) ? params.buttonHeight : 0); 1729 this.$buttonHeight = '$buttonHeight' in params ? params.$buttonHeight : undefined; 1730 this.initParam('titleMinHeight', (params && 'titleMinHeight' in params) ? params.titleMinHeight : 0); 1731 this.dialogBuilder = 'dialogBuilder' in params ? params.dialogBuilder : this.doNothingBuilder; 1732 this.titleIndex = 0; 1733 this.contentIndex = 1; 1734 this.buttonIndex = 2; 1735 this.finalizeConstruction(); 1736 } 1737 doNothingBuilder(parent = null) { 1738 } 1739 ; 1740 onPlaceChildren(selfLayoutInfo, children, constraint) { 1741 let currentX = 0; 1742 let currentY = 0; 1743 for (let index = 0; index < children.length; index++) { 1744 let child = children[index]; 1745 child.layout({ x: currentX, y: currentY }); 1746 currentY += child.measureResult.height; 1747 } 1748 } 1749 onMeasureSize(selfLayoutInfo, children, constraint) { 1750 let sizeResult = { width: Number(constraint.maxWidth), height: 0 }; 1751 let childrenSize = 3; 1752 if (children.length < childrenSize) { 1753 return sizeResult; 1754 } 1755 let height = 0; 1756 let titleChild = children[this.titleIndex]; 1757 let titleConstraint = { 1758 maxWidth: constraint.maxWidth, 1759 minHeight: this.titleMinHeight, 1760 maxHeight: constraint.maxHeight 1761 }; 1762 let titleMeasureResult = titleChild.measure(titleConstraint); 1763 this.$titleHeight?.(titleMeasureResult.height); 1764 height += titleMeasureResult.height; 1765 let buttonChild = children[this.buttonIndex]; 1766 let buttonMeasureResult = buttonChild.measure(constraint); 1767 this.$buttonHeight?.(buttonMeasureResult.height); 1768 height += buttonMeasureResult.height; 1769 let contentChild = children[this.contentIndex]; 1770 let contentConstraint = { 1771 maxWidth: constraint.maxWidth, 1772 maxHeight: Number(constraint.maxHeight) - height 1773 }; 1774 let contentMeasureResult = contentChild.measure(contentConstraint); 1775 height += contentMeasureResult.height; 1776 sizeResult.height = height; 1777 return sizeResult; 1778 } 1779 initialRender() { 1780 this.dialogBuilder.bind(this)(); 1781 } 1782 updateStateVars(params) { 1783 if (params === undefined) { 1784 return; 1785 } 1786 if ('titleHeight' in params) { 1787 this.updateParam('titleHeight', params.titleHeight); 1788 } 1789 if ('buttonHeight' in params) { 1790 this.updateParam('buttonHeight', params.buttonHeight); 1791 } 1792 if ('titleMinHeight' in params) { 1793 this.updateParam('titleMinHeight', params.titleMinHeight); 1794 } 1795 } 1796 rerender() { 1797 this.updateDirtyElements(); 1798 } 1799} 1800__decorate([ 1801 Param 1802], CustomDialogLayout.prototype, 'titleHeight', void 0); 1803__decorate([ 1804 Event 1805], CustomDialogLayout.prototype, '$titleHeight', void 0); 1806__decorate([ 1807 Param 1808], CustomDialogLayout.prototype, 'buttonHeight', void 0); 1809__decorate([ 1810 Event 1811], CustomDialogLayout.prototype, '$buttonHeight', void 0); 1812__decorate([ 1813 Param 1814], CustomDialogLayout.prototype, 'titleMinHeight', void 0); 1815class CustomDialogContentComponent extends ViewV2 { 1816 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda, extraInfo) { 1817 super(parent, elmtId, extraInfo); 1818 this.initParam('primaryTitle', (params && 'primaryTitle' in params) ? params.primaryTitle : undefined); 1819 this.initParam('secondaryTitle', (params && 'secondaryTitle' in params) ? params.secondaryTitle : undefined); 1820 this.contentBuilder = 'contentBuilder' in params ? params.contentBuilder : this.defaultContentBuilder; 1821 this.initParam('buttons', (params && 'buttons' in params) ? params.buttons : undefined); 1822 this.initParam('contentAreaPadding', (params && 'contentAreaPadding' in params) ? params.contentAreaPadding : undefined); 1823 this.initParam('minContentHeight', (params && 'minContentHeight' in params) ? params.minContentHeight : undefined); 1824 this.$minContentHeight = '$minContentHeight' in params ? params.$minContentHeight : undefined; 1825 this.keyIndex = 0; 1826 this.titleHeight = 0; 1827 this.buttonHeight = 0; 1828 this.contentMaxHeight = '100%'; 1829 this.fontSizeScale = -1; 1830 this.customStyle = undefined; 1831 this.buttonMaxFontSize = `${BODY_L}fp`; 1832 this.buttonMinFontSize = 9; 1833 this.primaryTitleFontColorWithTheme = { 'id': -1, 'type': 10001, params: ['sys.color.font_primary'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }; 1834 this.secondaryTitleFontColorWithTheme = { 'id': -1, 'type': 10001, params: ['sys.color.font_secondary'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }; 1835 this.titleTextAlign = TextAlign.Center; 1836 this.isButtonVertical = false; 1837 this.isFollowingSystemFontScale = false; 1838 this.appMaxFontScale = 3.2; 1839 this.titleIndex = 0; 1840 this.contentIndex = 1; 1841 this.buttonIndex = 2; 1842 this.primaryTitleFontSize = `${TITLE_S}fp`; 1843 this.secondaryTitleFontSize = `${SUBTITLE_S}fp`; 1844 this.scroller = new Scroller(); 1845 this.initParam('isHasDefaultFocus', (params && 'isHasDefaultFocus' in params) ? params.isHasDefaultFocus : false); 1846 this.initParam('isAllFocusFalse', (params && 'isAllFocusFalse' in params) ? params.isAllFocusFalse : false); 1847 this.finalizeConstruction(); 1848 } 1849 defaultContentBuilder(parent = null) { 1850 } 1851 initialRender() { 1852 this.observeComponentCreation2((elmtId, isInitialRender) => { 1853 RelativeContainer.create(); 1854 RelativeContainer.height('auto'); 1855 } , RelativeContainer); 1856 this.observeComponentCreation2((elmtId, isInitialRender) => { 1857 Scroll.create(this.scroller); 1858 Scroll.edgeEffect(EdgeEffect.None, { alwaysEnabled: false }); 1859 Scroll.backgroundColor(Color.Transparent); 1860 Scroll.scrollBar(BarState.Off); 1861 Scroll.id('CustomDialogContentComponent'); 1862 }, Scroll); 1863 this.observeComponentCreation2((elmtId, isInitialRender) => { 1864 Column.create(); 1865 Column.constraintSize({ maxHeight: this.contentMaxHeight }); 1866 Column.backgroundBlurStyle(this.customStyle ? 1867 BlurStyle.Thick : BlurStyle.NONE, undefined, { disableSystemAdaptation: true }); 1868 Column.borderRadius(this.customStyle ? { 'id': -1, 'type': 10002, params: ['sys.float.ohos_id_corner_radius_dialog'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } : 0); 1869 Column.margin(this.customStyle ? { 1870 start: LengthMetrics.resource({ 'id': -1, 'type': 10002, params: ['sys.float.ohos_id_dialog_margin_start'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }), 1871 end: LengthMetrics.resource({ 'id': -1, 'type': 10002, params: ['sys.float.ohos_id_dialog_margin_end'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }), 1872 bottom: LengthMetrics.resource({ 'id': -1, 'type': 10002, params: ['sys.float.ohos_id_dialog_margin_bottom'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }), 1873 } : { left: 0, right: 0, bottom: 0 }); 1874 Column.backgroundColor(this.customStyle ? { 'id': -1, 'type': 10001, params: ['sys.color.ohos_id_color_dialog_bg'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } : Color.Transparent); 1875 }, Column); 1876 { 1877 this.observeComponentCreation2((elmtId, isInitialRender) => { 1878 if (isInitialRender) { 1879 let componentCall = new CustomDialogLayout(this, { 1880 buttonHeight: this.buttonHeight, 1881 titleHeight: this.titleHeight, 1882 titleMinHeight: this.getTitleAreaMinHeight(), 1883 dialogBuilder: () => { 1884 this.observeComponentCreation2((elmtId, isInitialRender) => { 1885 ForEach.create(); 1886 const forEachItemGenFunction = _item => { 1887 const index = _item; 1888 this.observeComponentCreation2((elmtId, isInitialRender) => { 1889 If.create(); 1890 if (index === this.titleIndex) { 1891 this.ifElseBranchUpdateFunction(0, () => { 1892 this.titleBuilder.bind(this)(); 1893 }); 1894 } 1895 else if (index === this.contentIndex) { 1896 this.ifElseBranchUpdateFunction(1, () => { 1897 this.observeComponentCreation2((elmtId, isInitialRender) => { 1898 Column.create(); 1899 Column.padding(this.getContentPadding()); 1900 }, Column); 1901 this.contentBuilder.bind(this)(); 1902 Column.pop(); 1903 }); 1904 } 1905 else { 1906 this.ifElseBranchUpdateFunction(2, () => { 1907 this.ButtonBuilder.bind(this)(); 1908 }); 1909 } 1910 }, If); 1911 If.pop(); 1912 }; 1913 this.forEachUpdateFunction(elmtId, [this.titleIndex, this.contentIndex, this.buttonIndex], forEachItemGenFunction); 1914 }, ForEach); 1915 ForEach.pop(); 1916 }, 1917 $buttonHeight: value => { this.buttonHeight = value; }, 1918 $titleHeight: value => { this.titleHeight = value; } 1919 }, undefined, elmtId, () => { }, { page: 'library/src/main/ets/components/dialog.ets', line: 1057, col: 9 }); 1920 ViewV2.create(componentCall); 1921 let paramsLambda = () => { 1922 return { 1923 buttonHeight: this.buttonHeight, 1924 titleHeight: this.titleHeight, 1925 titleMinHeight: this.getTitleAreaMinHeight(), 1926 dialogBuilder: () => { 1927 this.observeComponentCreation2((elmtId, isInitialRender) => { 1928 ForEach.create(); 1929 const forEachItemGenFunction = _item => { 1930 const index = _item; 1931 this.observeComponentCreation2((elmtId, isInitialRender) => { 1932 If.create(); 1933 if (index === this.titleIndex) { 1934 this.ifElseBranchUpdateFunction(0, () => { 1935 this.titleBuilder.bind(this)(); 1936 }); 1937 } 1938 else if (index === this.contentIndex) { 1939 this.ifElseBranchUpdateFunction(1, () => { 1940 this.observeComponentCreation2((elmtId, isInitialRender) => { 1941 Column.create(); 1942 Column.padding(this.getContentPadding()); 1943 }, Column); 1944 this.contentBuilder.bind(this)(); 1945 Column.pop(); 1946 }); 1947 } 1948 else { 1949 this.ifElseBranchUpdateFunction(2, () => { 1950 this.ButtonBuilder.bind(this)(); 1951 }); 1952 } 1953 }, If); 1954 If.pop(); 1955 }; 1956 this.forEachUpdateFunction(elmtId, [this.titleIndex, this.contentIndex, this.buttonIndex], forEachItemGenFunction); 1957 }, ForEach); 1958 ForEach.pop(); 1959 } 1960 }; 1961 }; 1962 componentCall.paramsGenerator_ = paramsLambda; 1963 } 1964 else { 1965 this.updateStateVarsOfChildByElmtId(elmtId, { 1966 buttonHeight: this.buttonHeight, 1967 titleHeight: this.titleHeight, 1968 titleMinHeight: this.getTitleAreaMinHeight() 1969 }); 1970 } 1971 }, { name: 'CustomDialogLayout' }); 1972 } 1973 Column.pop(); 1974 Scroll.pop(); 1975 this.observeComponentCreation2((elmtId, isInitialRender) => { 1976 ScrollBar.create({ scroller: this.scroller }); 1977 ScrollBar.alignRules({ 1978 top: { anchor: 'CustomDialogContentComponent', align: VerticalAlign.Top }, 1979 bottom: { anchor: 'CustomDialogContentComponent', align: VerticalAlign.Bottom }, 1980 end: { anchor: 'CustomDialogContentComponent', align: HorizontalAlign.End } 1981 }); 1982 ScrollBar.margin({ 1983 top: { 1984 'id': -1, 1985 'type': 10002, 1986 params: ['sys.float.alert_container_shape'], 1987 'bundleName': '__harDefaultBundleName__', 1988 'moduleName': '__harDefaultModuleName__' 1989 }, 1990 bottom: { 1991 'id': -1, 1992 'type': 10002, 1993 params: ['sys.float.alert_container_shape'], 1994 'bundleName': '__harDefaultBundleName__', 1995 'moduleName': '__harDefaultModuleName__' 1996 } 1997 }); 1998 ScrollBar.enableNestedScroll(true); 1999 ScrollBar.hitTestBehavior(HitTestMode.Transparent); 2000 ScrollBar.onGestureRecognizerJudgeBegin((event, current, others) => { 2001 if (current) { 2002 if (current.getType() == GestureControl.GestureType.LONG_PRESS_GESTURE) { 2003 return GestureJudgeResult.REJECT; 2004 } 2005 } 2006 return GestureJudgeResult.CONTINUE; 2007 }); 2008 }, ScrollBar); 2009 ScrollBar.pop(); 2010 RelativeContainer.pop(); 2011 } 2012 onMeasureSize(selfLayoutInfo, children, constraint) { 2013 let sizeResult = { width: selfLayoutInfo.width, height: selfLayoutInfo.height }; 2014 let maxWidth = Number(constraint.maxWidth); 2015 let maxHeight = Number(constraint.maxHeight); 2016 this.fontSizeScale = this.updateFontScale(); 2017 this.updateFontSize(); 2018 this.isButtonVertical = this.isVerticalAlignButton(maxWidth - BUTTON_HORIZONTAL_MARGIN * 2); 2019 let height = 0; 2020 children.forEach((child) => { 2021 this.contentMaxHeight = '100%'; 2022 let measureResult = child.measure(constraint); 2023 if (maxHeight - this.buttonHeight - this.titleHeight < this.minContentHeight) { 2024 this.contentMaxHeight = MAX_CONTENT_HEIGHT; 2025 measureResult = child.measure(constraint); 2026 } 2027 height += measureResult.height; 2028 }); 2029 sizeResult.height = height; 2030 sizeResult.width = maxWidth; 2031 return sizeResult; 2032 } 2033 onWillApplyTheme(theme) { 2034 this.primaryTitleFontColorWithTheme = theme.colors.fontPrimary; 2035 this.secondaryTitleFontColorWithTheme = theme.colors.fontSecondary; 2036 } 2037 aboutToAppear() { 2038 try { 2039 let uiContext = this.getUIContext(); 2040 this.isFollowingSystemFontScale = uiContext?.isFollowingSystemFontScale(); 2041 this.appMaxFontScale = uiContext?.getMaxFontScale(); 2042 } 2043 catch (err) { 2044 let code = err?.code; 2045 let message = err?.message; 2046 hilog.error(0x3900, 'Ace', `Faild to dialog getUIContext, code: ${code}, message: ${message}`); 2047 } 2048 this.fontSizeScale = this.updateFontScale(); 2049 this.initTitleTextAlign(); 2050 this.setDefaultFocusState(this.buttons); 2051 } 2052 updateFontSize() { 2053 if (this.fontSizeScale > MAX_FONT_SCALE) { 2054 this.buttonMaxFontSize = BODY_L * MAX_FONT_SCALE + 'vp'; 2055 this.buttonMinFontSize = BUTTON_MIN_FONT_SIZE * MAX_FONT_SCALE + 'vp'; 2056 } 2057 else { 2058 this.buttonMaxFontSize = BODY_L + 'fp'; 2059 this.buttonMinFontSize = BUTTON_MIN_FONT_SIZE + 'fp'; 2060 } 2061 } 2062 updateFontScale() { 2063 try { 2064 let uiContext = this.getUIContext(); 2065 let systemFontScale = uiContext.getHostContext()?.config?.fontSizeScale ?? 1; 2066 if (!this.isFollowingSystemFontScale) { 2067 return 1; 2068 } 2069 return Math.min(systemFontScale, this.appMaxFontScale); 2070 } 2071 catch (exception) { 2072 let code = exception.code; 2073 let message = exception.message; 2074 hilog.error(0x3900, 'Ace', `Faild to init fontsizescale info,cause, code: ${code}, message: ${message}`); 2075 return 1; 2076 } 2077 } 2078 /** 2079 * set state of button focus 2080 */ 2081 setDefaultFocusState(buttonList) { 2082 if (!buttonList) { 2083 return; 2084 } 2085 let falseNum = 0; 2086 buttonList.forEach((button) => { 2087 // 遍历查询按钮中存在是否存在默认按钮 2088 if (button.defaultFocus) { 2089 this.isHasDefaultFocus = true; 2090 } 2091 if (button.defaultFocus === false) { 2092 falseNum++; 2093 } 2094 }); 2095 // 所有按钮defaultFocus都设置为false 2096 if (falseNum === buttonList.length) { 2097 this.isAllFocusFalse = true; 2098 } 2099 } 2100 /** 2101 * get dialog content padding 2102 * 2103 * @returns content padding 2104 */ 2105 getContentPadding() { 2106 if (this.contentAreaPadding) { 2107 return this.contentAreaPadding; 2108 } 2109 if ((this.primaryTitle || this.secondaryTitle) && this.buttons && this.buttons.length > 0) { 2110 return { 2111 top: 0, 2112 right: { 'id': -1, 'type': 10002, params: ['sys.float.alert_content_default_padding'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2113 bottom: 0, 2114 left: { 'id': -1, 'type': 10002, params: ['sys.float.alert_content_default_padding'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2115 }; 2116 } 2117 else if (this.primaryTitle || this.secondaryTitle) { 2118 return { 2119 top: 0, 2120 right: { 'id': -1, 'type': 10002, params: ['sys.float.alert_content_default_padding'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2121 bottom: { 'id': -1, 'type': 10002, params: ['sys.float.alert_content_default_padding'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2122 left: { 'id': -1, 'type': 10002, params: ['sys.float.alert_content_default_padding'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2123 }; 2124 } 2125 else if (this.buttons && this.buttons.length > 0) { 2126 return { 2127 top: { 'id': -1, 'type': 10002, params: ['sys.float.alert_content_default_padding'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2128 right: { 'id': -1, 'type': 10002, params: ['sys.float.alert_content_default_padding'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2129 bottom: 0, 2130 left: { 'id': -1, 'type': 10002, params: ['sys.float.alert_content_default_padding'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2131 }; 2132 } 2133 else { 2134 return { 2135 top: { 'id': -1, 'type': 10002, params: ['sys.float.alert_content_default_padding'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2136 right: { 'id': -1, 'type': 10002, params: ['sys.float.alert_content_default_padding'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2137 bottom: { 'id': -1, 'type': 10002, params: ['sys.float.alert_content_default_padding'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2138 left: { 'id': -1, 'type': 10002, params: ['sys.float.alert_content_default_padding'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2139 }; 2140 } 2141 } 2142 titleBuilder(parent = null) { 2143 this.observeComponentCreation2((elmtId, isInitialRender) => { 2144 Column.create(); 2145 Column.justifyContent(FlexAlign.Center); 2146 Column.width('100%'); 2147 Column.padding(this.getTitleAreaPadding()); 2148 }, Column); 2149 this.observeComponentCreation2((elmtId, isInitialRender) => { 2150 Row.create(); 2151 Row.width('100%'); 2152 }, Row); 2153 this.observeComponentCreation2((elmtId, isInitialRender) => { 2154 Text.create(this.primaryTitle); 2155 Text.fontWeight(FontWeight.Bold); 2156 Text.fontColor(this.primaryTitleFontColorWithTheme); 2157 Text.textAlign(this.titleTextAlign); 2158 Text.fontSize(this.primaryTitleFontSize); 2159 Text.maxFontScale(Math.min(this.appMaxFontScale, MAX_FONT_SCALE)); 2160 Text.maxLines(TITLE_MAX_LINES); 2161 Text.heightAdaptivePolicy(TextHeightAdaptivePolicy.MAX_LINES_FIRST); 2162 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 2163 Text.width('100%'); 2164 }, Text); 2165 Text.pop(); 2166 Row.pop(); 2167 this.observeComponentCreation2((elmtId, isInitialRender) => { 2168 If.create(); 2169 if (this.primaryTitle && this.secondaryTitle) { 2170 this.ifElseBranchUpdateFunction(0, () => { 2171 this.observeComponentCreation2((elmtId, isInitialRender) => { 2172 Row.create(); 2173 Row.height({ 'id': -1, 'type': 10002, params: ['sys.float.padding_level1'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 2174 }, Row); 2175 Row.pop(); 2176 }); 2177 } 2178 else { 2179 this.ifElseBranchUpdateFunction(1, () => { 2180 }); 2181 } 2182 }, If); 2183 If.pop(); 2184 this.observeComponentCreation2((elmtId, isInitialRender) => { 2185 Row.create(); 2186 Row.width('100%'); 2187 }, Row); 2188 this.observeComponentCreation2((elmtId, isInitialRender) => { 2189 Text.create(this.secondaryTitle); 2190 Text.fontWeight(FontWeight.Regular); 2191 Text.fontColor(this.secondaryTitleFontColorWithTheme); 2192 Text.textAlign(this.titleTextAlign); 2193 Text.fontSize(this.secondaryTitleFontSize); 2194 Text.maxFontScale(Math.min(this.appMaxFontScale, MAX_FONT_SCALE)); 2195 Text.maxLines(TITLE_MAX_LINES); 2196 Text.heightAdaptivePolicy(TextHeightAdaptivePolicy.MAX_LINES_FIRST); 2197 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 2198 Text.width('100%'); 2199 }, Text); 2200 Text.pop(); 2201 Row.pop(); 2202 Column.pop(); 2203 } 2204 /** 2205 * get title area padding 2206 * 2207 * @returns padding 2208 */ 2209 getTitleAreaPadding() { 2210 if (this.primaryTitle || this.secondaryTitle) { 2211 return { 2212 top: { 'id': -1, 'type': 10002, params: ['sys.float.alert_title_padding_top'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2213 right: { 'id': -1, 'type': 10002, params: ['sys.float.alert_title_padding_right'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2214 left: { 'id': -1, 'type': 10002, params: ['sys.float.alert_title_padding_left'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2215 bottom: { 'id': -1, 'type': 10002, params: ['sys.float.alert_title_padding_bottom'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2216 }; 2217 } 2218 return { 2219 top: 0, 2220 right: { 'id': -1, 'type': 10002, params: ['sys.float.alert_title_padding_right'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2221 left: { 'id': -1, 'type': 10002, params: ['sys.float.alert_title_padding_left'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2222 bottom: 0, 2223 }; 2224 } 2225 /** 2226 * get tile TextAlign 2227 * @returns TextAlign 2228 */ 2229 initTitleTextAlign() { 2230 let textAlign = ALERT_TITLE_ALIGNMENT; 2231 if (textAlign === TextAlign.Start) { 2232 this.titleTextAlign = TextAlign.Start; 2233 } 2234 else if (textAlign === TextAlign.Center) { 2235 this.titleTextAlign = TextAlign.Center; 2236 } 2237 else if (textAlign === TextAlign.End) { 2238 this.titleTextAlign = TextAlign.End; 2239 } 2240 else if (textAlign === TextAlign.JUSTIFY) { 2241 this.titleTextAlign = TextAlign.JUSTIFY; 2242 } 2243 else { 2244 this.titleTextAlign = TextAlign.Center; 2245 } 2246 } 2247 /** 2248 * get title area min height 2249 * 2250 * @returns min height 2251 */ 2252 getTitleAreaMinHeight() { 2253 if (this.secondaryTitle) { 2254 return { 'id': -1, 'type': 10002, params: ['sys.float.alert_title_secondary_height'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }; 2255 } 2256 else if (this.primaryTitle) { 2257 return { 'id': -1, 'type': 10002, params: ['sys.float.alert_title_primary_height'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }; 2258 } 2259 else { 2260 return 0; 2261 } 2262 } 2263 ButtonBuilder(parent = null) { 2264 this.observeComponentCreation2((elmtId, isInitialRender) => { 2265 Column.create(); 2266 Column.width('100%'); 2267 Column.padding(this.getOperationAreaPadding()); 2268 }, Column); 2269 this.observeComponentCreation2((elmtId, isInitialRender) => { 2270 If.create(); 2271 if (this.buttons && this.buttons.length > 0) { 2272 this.ifElseBranchUpdateFunction(0, () => { 2273 this.observeComponentCreation2((elmtId, isInitialRender) => { 2274 If.create(); 2275 if (this.isButtonVertical) { 2276 this.ifElseBranchUpdateFunction(0, () => { 2277 this.buildVerticalAlignButtons.bind(this)(); 2278 }); 2279 } 2280 else { 2281 this.ifElseBranchUpdateFunction(1, () => { 2282 this.buildHorizontalAlignButtons.bind(this)(); 2283 }); 2284 } 2285 }, If); 2286 If.pop(); 2287 }); 2288 } 2289 else { 2290 this.ifElseBranchUpdateFunction(1, () => { 2291 }); 2292 } 2293 }, If); 2294 If.pop(); 2295 Column.pop(); 2296 } 2297 /** 2298 * get operation area padding 2299 * 2300 * @returns padding 2301 */ 2302 getOperationAreaPadding() { 2303 if (this.isButtonVertical) { 2304 return { 2305 top: { 'id': -1, 'type': 10002, params: ['sys.float.alert_button_top_padding'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2306 right: { 'id': -1, 'type': 10002, params: ['sys.float.alert_right_padding_vertical'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2307 left: { 'id': -1, 'type': 10002, params: ['sys.float.alert_left_padding_vertical'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2308 bottom: { 'id': -1, 'type': 10002, params: ['sys.float.alert_button_bottom_padding_vertical'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2309 }; 2310 } 2311 return { 2312 top: { 'id': -1, 'type': 10002, params: ['sys.float.alert_button_top_padding'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2313 right: { 'id': -1, 'type': 10002, params: ['sys.float.alert_right_padding_horizontal'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2314 left: { 'id': -1, 'type': 10002, params: ['sys.float.alert_left_padding_horizontal'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2315 bottom: { 'id': -1, 'type': 10002, params: ['sys.float.alert_button_bottom_padding_horizontal'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 2316 }; 2317 } 2318 buildSingleButton(index, parent = null) { 2319 this.observeComponentCreation2((elmtId, isInitialRender) => { 2320 If.create(); 2321 if (this.isNewPropertiesHighPriority(index)) { 2322 this.ifElseBranchUpdateFunction(0, () => { 2323 this.observeComponentCreation2((elmtId, isInitialRender) => { 2324 Button.createWithLabel(this.buttons?.[index].content); 2325 __Button__setButtonProperties(this.buttons?.[index], this.isHasDefaultFocus, this.isAllFocusFalse, this.getDialogController()); 2326 Button.role(this.buttons?.[index].role ?? ButtonRole.NORMAL); 2327 Button.key(`advanced_dialog_button_${this.keyIndex++}`); 2328 Button.labelStyle({ maxLines: 1, maxFontSize: this.buttonMaxFontSize, minFontSize: this.buttonMinFontSize }); 2329 }, Button); 2330 Button.pop(); 2331 }); 2332 } 2333 else if (this.buttons?.[index].background !== undefined && this.buttons?.[index].fontColor !== undefined) { 2334 this.ifElseBranchUpdateFunction(1, () => { 2335 this.observeComponentCreation2((elmtId, isInitialRender) => { 2336 Button.createWithLabel(this.buttons?.[index].content); 2337 __Button__setButtonProperties(this.buttons?.[index], this.isHasDefaultFocus, this.isAllFocusFalse, this.getDialogController()); 2338 Button.backgroundColor(this.buttons?.[index].background?.color); 2339 Button.fontColor(this.buttons?.[index].fontColor?.color); 2340 Button.key(`advanced_dialog_button_${this.keyIndex++}`); 2341 Button.labelStyle({ maxLines: 1, maxFontSize: this.buttonMaxFontSize, minFontSize: this.buttonMinFontSize }); 2342 }, Button); 2343 Button.pop(); 2344 }); 2345 } 2346 else if (this.buttons?.[index].background !== undefined) { 2347 this.ifElseBranchUpdateFunction(2, () => { 2348 this.observeComponentCreation2((elmtId, isInitialRender) => { 2349 Button.createWithLabel(this.buttons?.[index].content); 2350 __Button__setButtonProperties(this.buttons?.[index], this.isHasDefaultFocus, this.isAllFocusFalse, this.getDialogController()); 2351 Button.backgroundColor(this.buttons?.[index].background?.color); 2352 Button.key(`advanced_dialog_button_${this.keyIndex++}`); 2353 Button.labelStyle({ maxLines: 1, maxFontSize: this.buttonMaxFontSize, minFontSize: this.buttonMinFontSize }); 2354 }, Button); 2355 Button.pop(); 2356 }); 2357 } 2358 else { 2359 this.ifElseBranchUpdateFunction(3, () => { 2360 this.observeComponentCreation2((elmtId, isInitialRender) => { 2361 Button.createWithLabel(this.buttons?.[index].content); 2362 __Button__setButtonProperties(this.buttons?.[index], this.isHasDefaultFocus, this.isAllFocusFalse, this.getDialogController()); 2363 Button.fontColor(this.buttons?.[index]?.fontColor?.color); 2364 Button.key(`advanced_dialog_button_${this.keyIndex++}`); 2365 Button.labelStyle({ maxLines: 1, maxFontSize: this.buttonMaxFontSize, minFontSize: this.buttonMinFontSize }); 2366 }, Button); 2367 Button.pop(); 2368 }); 2369 } 2370 }, If); 2371 If.pop(); 2372 } 2373 buildHorizontalAlignButtons(parent = null) { 2374 this.observeComponentCreation2((elmtId, isInitialRender) => { 2375 If.create(); 2376 if (this.buttons && this.buttons.length > 0) { 2377 this.ifElseBranchUpdateFunction(0, () => { 2378 this.observeComponentCreation2((elmtId, isInitialRender) => { 2379 Row.create(); 2380 }, Row); 2381 this.buildSingleButton.bind(this)(0); 2382 this.observeComponentCreation2((elmtId, isInitialRender) => { 2383 If.create(); 2384 if (this.buttons.length === HORIZON_BUTTON_MAX_COUNT) { 2385 this.ifElseBranchUpdateFunction(0, () => { 2386 this.observeComponentCreation2((elmtId, isInitialRender) => { 2387 Row.create(); 2388 Row.width(BUTTON_HORIZONTAL_SPACE * 2); 2389 Row.justifyContent(FlexAlign.Center); 2390 }, Row); 2391 this.observeComponentCreation2((elmtId, isInitialRender) => { 2392 Divider.create(); 2393 Divider.width({ 'id': -1, 'type': 10002, params: ['sys.float.alert_divider_width'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 2394 Divider.height({ 'id': -1, 'type': 10002, params: ['sys.float.alert_divider_height'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 2395 Divider.color(this.getDividerColor()); 2396 Divider.vertical(true); 2397 }, Divider); 2398 Row.pop(); 2399 this.buildSingleButton.bind(this)(HORIZON_BUTTON_MAX_COUNT - 1); 2400 }); 2401 } 2402 else { 2403 this.ifElseBranchUpdateFunction(1, () => { 2404 }); 2405 } 2406 }, If); 2407 If.pop(); 2408 Row.pop(); 2409 }); 2410 } 2411 else { 2412 this.ifElseBranchUpdateFunction(1, () => { 2413 }); 2414 } 2415 }, If); 2416 If.pop(); 2417 } 2418 buildVerticalAlignButtons(parent = null) { 2419 this.observeComponentCreation2((elmtId, isInitialRender) => { 2420 If.create(); 2421 if (this.buttons) { 2422 this.ifElseBranchUpdateFunction(0, () => { 2423 this.observeComponentCreation2((elmtId, isInitialRender) => { 2424 Column.create(); 2425 }, Column); 2426 this.observeComponentCreation2((elmtId, isInitialRender) => { 2427 ForEach.create(); 2428 const forEachItemGenFunction = (_item, index) => { 2429 const item = _item; 2430 this.buildButtonWithDivider.bind(this)(this.buttons?.length === HORIZON_BUTTON_MAX_COUNT ? 2431 HORIZON_BUTTON_MAX_COUNT - index - 1 : index); 2432 }; 2433 this.forEachUpdateFunction(elmtId, this.buttons.slice(0, VERTICAL_BUTTON_MAX_COUNT), forEachItemGenFunction, (item) => item.content.toString(), true, false); 2434 }, ForEach); 2435 ForEach.pop(); 2436 Column.pop(); 2437 }); 2438 } 2439 else { 2440 this.ifElseBranchUpdateFunction(1, () => { 2441 }); 2442 } 2443 }, If); 2444 If.pop(); 2445 } 2446 /** 2447 * get divider color 2448 * 2449 * @returns divider color 2450 */ 2451 getDividerColor() { 2452 if (!this.buttons || this.buttons.length === 0 || !DIALOG_DIVIDER_SHOW) { 2453 return Color.Transparent; 2454 } 2455 if (this.buttons[0].buttonStyle === ButtonStyleMode.TEXTUAL || this.buttons[0].buttonStyle === undefined) { 2456 if (this.buttons[HORIZON_BUTTON_MAX_COUNT - 1].buttonStyle === ButtonStyleMode.TEXTUAL || 2457 this.buttons[HORIZON_BUTTON_MAX_COUNT - 1].buttonStyle === undefined) { 2458 return { 'id': -1, 'type': 10001, params: ['sys.color.alert_divider_color'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }; 2459 } 2460 } 2461 return Color.Transparent; 2462 } 2463 /** 2464 * is button buttonStyle and role properties high priority 2465 * 2466 * @param buttonOptions button properties 2467 * @returns check result 2468 */ 2469 isNewPropertiesHighPriority(index) { 2470 if (this.buttons?.[index].role === ButtonRole.ERROR) { 2471 return true; 2472 } 2473 if (this.buttons?.[index].buttonStyle !== undefined && 2474 this.buttons?.[index].buttonStyle !== ALERT_BUTTON_STYLE) { 2475 return true; 2476 } 2477 if (this.buttons?.[index].background === undefined && this.buttons?.[index].fontColor === undefined) { 2478 return true; 2479 } 2480 return false; 2481 } 2482 buildButtonWithDivider(index, parent = null) { 2483 this.observeComponentCreation2((elmtId, isInitialRender) => { 2484 If.create(); 2485 if (this.buttons && this.buttons[index]) { 2486 this.ifElseBranchUpdateFunction(0, () => { 2487 this.observeComponentCreation2((elmtId, isInitialRender) => { 2488 Row.create(); 2489 }, Row); 2490 this.buildSingleButton.bind(this)(index); 2491 Row.pop(); 2492 this.observeComponentCreation2((elmtId, isInitialRender) => { 2493 If.create(); 2494 if ((this.buttons.length === HORIZON_BUTTON_MAX_COUNT ? HORIZON_BUTTON_MAX_COUNT - index - 1 : index) < 2495 Math.min(this.buttons.length, VERTICAL_BUTTON_MAX_COUNT) - 1) { 2496 this.ifElseBranchUpdateFunction(0, () => { 2497 this.observeComponentCreation2((elmtId, isInitialRender) => { 2498 Row.create(); 2499 Row.height({ 'id': -1, 'type': 10002, params: ['sys.float.alert_button_vertical_space'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 2500 }, Row); 2501 Row.pop(); 2502 }); 2503 } 2504 else { 2505 this.ifElseBranchUpdateFunction(1, () => { 2506 }); 2507 } 2508 }, If); 2509 If.pop(); 2510 }); 2511 } 2512 else { 2513 this.ifElseBranchUpdateFunction(1, () => { 2514 }); 2515 } 2516 }, If); 2517 If.pop(); 2518 } 2519 isVerticalAlignButton(width) { 2520 if (this.buttons) { 2521 if (this.buttons.length === 1) { 2522 return false; 2523 } 2524 if (this.buttons.length !== HORIZON_BUTTON_MAX_COUNT) { 2525 return true; 2526 } 2527 let isVertical = false; 2528 let maxButtonTextSize = vp2px(width / HORIZON_BUTTON_MAX_COUNT - BUTTON_HORIZONTAL_MARGIN - 2529 BUTTON_HORIZONTAL_SPACE - 2 * BUTTON_HORIZONTAL_PADDING); 2530 this.buttons.forEach((button) => { 2531 let contentSize = measure.measureTextSize({ 2532 textContent: button.content, 2533 fontSize: this.buttonMaxFontSize 2534 }); 2535 if (Number(contentSize.width) > maxButtonTextSize) { 2536 isVertical = true; 2537 } 2538 }); 2539 return isVertical; 2540 } 2541 return false; 2542 } 2543 updateStateVars(params) { 2544 if (params === undefined) { 2545 return; 2546 } 2547 if ('primaryTitle' in params) { 2548 this.updateParam('primaryTitle', params.primaryTitle); 2549 } 2550 if ('secondaryTitle' in params) { 2551 this.updateParam('secondaryTitle', params.secondaryTitle); 2552 } 2553 if ('buttons' in params) { 2554 this.updateParam('buttons', params.buttons); 2555 } 2556 if ('contentAreaPadding' in params) { 2557 this.updateParam('contentAreaPadding', params.contentAreaPadding); 2558 } 2559 if ('minContentHeight' in params) { 2560 this.updateParam('minContentHeight', params.minContentHeight); 2561 } 2562 if ('isHasDefaultFocus' in params) { 2563 this.updateParam('isHasDefaultFocus', params.isHasDefaultFocus); 2564 } 2565 if ('isAllFocusFalse' in params) { 2566 this.updateParam('isAllFocusFalse', params.isAllFocusFalse); 2567 } 2568 } 2569 rerender() { 2570 this.updateDirtyElements(); 2571 } 2572} 2573__decorate([ 2574 Param 2575], CustomDialogContentComponent.prototype, 'primaryTitle', void 0); 2576__decorate([ 2577 Param 2578], CustomDialogContentComponent.prototype, 'secondaryTitle', void 0); 2579__decorate([ 2580 Param 2581], CustomDialogContentComponent.prototype, 'buttons', void 0); 2582__decorate([ 2583 Param 2584], CustomDialogContentComponent.prototype, 'contentAreaPadding', void 0); 2585__decorate([ 2586 Param 2587], CustomDialogContentComponent.prototype, 'minContentHeight', void 0); 2588__decorate([ 2589 Event 2590], CustomDialogContentComponent.prototype, '$minContentHeight', void 0); 2591__decorate([ 2592 Local 2593], CustomDialogContentComponent.prototype, 'titleHeight', void 0); 2594__decorate([ 2595 Local 2596], CustomDialogContentComponent.prototype, 'buttonHeight', void 0); 2597__decorate([ 2598 Local 2599], CustomDialogContentComponent.prototype, 'contentMaxHeight', void 0); 2600__decorate([ 2601 Consumer() 2602], CustomDialogContentComponent.prototype, 'fontSizeScale', void 0); 2603__decorate([ 2604 Local 2605], CustomDialogContentComponent.prototype, 'customStyle', void 0); 2606__decorate([ 2607 Local 2608], CustomDialogContentComponent.prototype, 'buttonMaxFontSize', void 0); 2609__decorate([ 2610 Local 2611], CustomDialogContentComponent.prototype, 'buttonMinFontSize', void 0); 2612__decorate([ 2613 Local 2614], CustomDialogContentComponent.prototype, 'primaryTitleFontColorWithTheme', void 0); 2615__decorate([ 2616 Local 2617], CustomDialogContentComponent.prototype, 'secondaryTitleFontColorWithTheme', void 0); 2618__decorate([ 2619 Local 2620], CustomDialogContentComponent.prototype, 'titleTextAlign', void 0); 2621__decorate([ 2622 Local 2623], CustomDialogContentComponent.prototype, 'isButtonVertical', void 0); 2624__decorate([ 2625 Param, 2626 Once 2627], CustomDialogContentComponent.prototype, 'isHasDefaultFocus', void 0); 2628__decorate([ 2629 Param, 2630 Once 2631], CustomDialogContentComponent.prototype, 'isAllFocusFalse', void 0); 2632function __Button__setButtonProperties(buttonOptions, isHasDefaultFocus, isAllFocusFalse, controller) { 2633 Button.onKeyEvent((event) => { 2634 if (!event) { 2635 return; 2636 } 2637 if ((event.keyCode === KeyCode.KEYCODE_SPACE || event.keyCode === KeyCode.KEYCODE_ENTER) && 2638 event.type === KeyType.Down) { 2639 if (buttonOptions?.action) { 2640 buttonOptions.action(); 2641 } 2642 closeDialog(controller, 'onKeyEvent'); 2643 event.stopPropagation(); 2644 } 2645 }); 2646 Button.onClick(() => { 2647 if (buttonOptions?.action) { 2648 buttonOptions.action(); 2649 } 2650 closeDialog(controller, 'onClick'); 2651 }); 2652 Button.defaultFocus(isDefaultFocus(buttonOptions, isHasDefaultFocus, isAllFocusFalse)); 2653 Button.buttonStyle(buttonOptions?.buttonStyle ?? ALERT_BUTTON_STYLE); 2654 Button.layoutWeight(BUTTON_LAYOUT_WEIGHT); 2655 Button.type(ButtonType.ROUNDED_RECTANGLE); 2656 Button.enabled(buttonOptions?.enabled ?? true); 2657} 2658function closeDialog(controller, funcName) { 2659 if (controller) { 2660 hilog?.info(0x3900, 'Ace', `AdvancedDialog button ${funcName} controller true`); 2661 controller?.close(); 2662 } else { 2663 hilog?.info(0x3900, 'Ace', `AdvancedDialog button ${funcName} controller false`); 2664 } 2665} 2666/** 2667 * is button set default focus 2668 * 2669 * @param singleButton button options 2670 * @param isHasDefaultFocus is button list has default focus button 2671 * @param isAllFocusFalse is all button in button list default focus false 2672 * @returns boolean 2673 */ 2674function isDefaultFocus(singleButton, isHasDefaultFocus, isAllFocusFalse) { 2675 try { 2676 // 当前按钮为默认按钮 2677 if (singleButton?.defaultFocus) { 2678 return true; 2679 } 2680 let isDefaultFocus = false; 2681 if (isHasDefaultFocus || isAllFocusFalse) { 2682 isDefaultFocus = false; // 存在默认按钮或者所有按钮的defaultFocus都为false 2683 } 2684 else { 2685 isDefaultFocus = true; // 默认第一个按钮获焦 2686 } 2687 return isDefaultFocus; 2688 } 2689 catch (error) { 2690 let code = error.code; 2691 let message = error.message; 2692 hilog.error(0x3900, 'Ace', `get defaultFocus exist error, code: ${code}, message: ${message}`); 2693 return true; 2694 } 2695} 2696/** 2697 * get resource size 2698 * 2699 * @param resourceId resource id 2700 * @param defaultValue default value 2701 * @returns resource size 2702 */ 2703function getNumberByResourceId(resourceId, defaultValue, allowZero) { 2704 try { 2705 let sourceValue = resourceManager.getSystemResourceManager().getNumber(resourceId); 2706 if (sourceValue > 0 || allowZero) { 2707 return sourceValue; 2708 } 2709 else { 2710 return defaultValue; 2711 } 2712 } 2713 catch (error) { 2714 let code = error.code; 2715 let message = error.message; 2716 hilog.error(0x3900, 'Ace', `CustomContentDialog getNumberByResourceId error, code: ${code}, message: ${message}`); 2717 return defaultValue; 2718 } 2719} 2720/** 2721 * get enum number 2722 * 2723 * @param resourceId resource id 2724 * @param defaultValue default value 2725 * @returns number 2726 */ 2727function getEnumNumberByResourceId(resourceId, defaultValue) { 2728 try { 2729 let sourceValue = getContext().resourceManager.getNumber(resourceId); 2730 if (sourceValue > 0) { 2731 return sourceValue; 2732 } 2733 else { 2734 return defaultValue; 2735 } 2736 } 2737 catch (error) { 2738 let code = error.code; 2739 let message = error.message; 2740 hilog.error(0x3900, 'Ace', `getEnumNumberByResourceId error, code: ${code}, message: ${message}`); 2741 return defaultValue; 2742 } 2743} 2744/** 2745 * 获取SelectDialog无障碍文本 2746 * 2747 * @param resource 资源 2748 * @param selected select state 2749 * @returns string 2750 */ 2751function getAccessibilityText(resource, selected) { 2752 try { 2753 let selectText = getContext().resourceManager.getStringSync(125833934); 2754 let resourceString = ''; 2755 if (typeof resource === 'string') { 2756 resourceString = resource; 2757 } 2758 else { 2759 resourceString = getContext().resourceManager.getStringSync(resource); 2760 } 2761 return selected ? `${selectText},${resourceString}` : resourceString; 2762 } 2763 catch (error) { 2764 let code = error.code; 2765 let message = error.message; 2766 hilog.error(0x3900, 'Ace', `getAccessibilityText error, code: ${code}, message: ${message}`); 2767 return ''; 2768 } 2769} 2770/** 2771 * resolve content area keyEvent 2772 * 2773 * @param event keyEvent 2774 * @param controller the controller of content area 2775 * @returns undefined 2776 */ 2777function resolveKeyEvent(event, controller) { 2778 if (event.type === IGNORE_KEY_EVENT_TYPE) { 2779 return; 2780 } 2781 if (event.keyCode === KEYCODE_UP) { 2782 controller.scrollPage({ next: false }); 2783 event.stopPropagation(); 2784 } 2785 else if (event.keyCode === KEYCODE_DOWN) { 2786 if (controller.isAtEnd()) { 2787 return; 2788 } 2789 else { 2790 controller.scrollPage({ next: true }); 2791 event.stopPropagation(); 2792 } 2793 } 2794} 2795/** 2796 * 获取checkTips无障碍文本 2797 * 2798 * @param resource 资源 2799 * @param selected select state 2800 * @returns string 2801 */ 2802function getCheckTipsAccessibilityText(resource, selected) { 2803 try { 2804 // 'sys.string.slider_accessibility_selected' 2805 let selectText = getContext().resourceManager.getStringSync(125833934); 2806 // 'sys.string.slider_accessibility_unselected' 2807 let unselectText = getContext().resourceManager.getStringSync(125833935); 2808 // 'sys.string.advanced_dialog_accessibility_checkbox' 2809 let checkBoxText = getContext().resourceManager.getStringSync(125834354); 2810 let resourceString = ''; 2811 if (typeof resource === 'string') { 2812 resourceString = resource; 2813 } 2814 else { 2815 resourceString = getContext().resourceManager.getStringSync(resource); 2816 } 2817 return selected ? `${selectText},${resourceString},${checkBoxText}` : 2818 `${unselectText},${resourceString},${checkBoxText}`; 2819 } 2820 catch (error) { 2821 let code = error.code; 2822 let message = error.message; 2823 hilog.error(0x3900, 'Ace', `getCheckTipsAccessibilityText error, code: ${code}, message: ${message}`); 2824 return ''; 2825 } 2826} 2827export class LoadingDialogV2 extends ViewV2 { 2828 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda, extraInfo) { 2829 super(parent, elmtId, extraInfo); 2830 this.initParam('content', (params && 'content' in params) ? params.content : ''); 2831 this.fontColorWithTheme = { 'id': -1, 'type': 10001, params: ['sys.color.font_primary'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }; 2832 this.loadingProgressIconColorWithTheme = { 'id': -1, 'type': 10001, params: ['sys.color.icon_secondary'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }; 2833 this.fontSizeScale = 1; 2834 this.minContentHeight = MIN_CONTENT_HEIGHT; 2835 this.finalizeConstruction(); 2836 } 2837 initialRender() { 2838 this.observeComponentCreation2((elmtId, isInitialRender) => { 2839 Column.create(); 2840 }, Column); 2841 this.observeComponentCreation2((elmtId, isInitialRender) => { 2842 __Common__.create(); 2843 __Common__.constraintSize({ maxHeight: '100%' }); 2844 }, __Common__); 2845 { 2846 this.observeComponentCreation2((elmtId, isInitialRender) => { 2847 if (isInitialRender) { 2848 let componentCall = new CustomDialogContentComponent(this, { 2849 contentBuilder: () => { 2850 this.contentBuilder(); 2851 }, 2852 minContentHeight: this.minContentHeight, 2853 $minContentHeight: value => { this.minContentHeight = value; } 2854 }, undefined, elmtId, () => { }, { page: 'library/src/main/ets/components/dialog.ets', line: 1707, col: 7 }); 2855 ViewV2.create(componentCall); 2856 let paramsLambda = () => { 2857 return { 2858 contentBuilder: () => { 2859 this.contentBuilder(); 2860 }, 2861 minContentHeight: this.minContentHeight 2862 }; 2863 }; 2864 componentCall.paramsGenerator_ = paramsLambda; 2865 } 2866 else { 2867 this.updateStateVarsOfChildByElmtId(elmtId, { 2868 minContentHeight: this.minContentHeight 2869 }); 2870 } 2871 }, { name: 'CustomDialogContentComponent' }); 2872 } 2873 __Common__.pop(); 2874 Column.pop(); 2875 } 2876 contentBuilder(parent = null) { 2877 this.observeComponentCreation2((elmtId, isInitialRender) => { 2878 Column.create(); 2879 }, Column); 2880 this.observeComponentCreation2((elmtId, isInitialRender) => { 2881 Row.create(); 2882 Row.constraintSize({ minHeight: LOADING_MIN_HEIGHT }); 2883 }, Row); 2884 this.observeComponentCreation2((elmtId, isInitialRender) => { 2885 Text.create(this.content); 2886 Text.fontSize(`${CONTENT_FONT_SIZE}fp`); 2887 Text.fontWeight(FontWeight.Regular); 2888 Text.fontColor(this.fontColorWithTheme); 2889 Text.layoutWeight(LOADING_TEXT_LAYOUT_WEIGHT); 2890 Text.maxLines(this.fontSizeScale > MAX_FONT_SCALE ? LOADING_MAX_LINES_BIG_FONT : LOADING_MAX_LINES); 2891 Text.focusable(true); 2892 Text.defaultFocus(true); 2893 Text.focusBox({ 2894 strokeWidth: LengthMetrics.px(0) 2895 }); 2896 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 2897 }, Text); 2898 Text.pop(); 2899 this.observeComponentCreation2((elmtId, isInitialRender) => { 2900 LoadingProgress.create(); 2901 LoadingProgress.color(this.loadingProgressIconColorWithTheme); 2902 LoadingProgress.width(LOADING_PROGRESS_WIDTH); 2903 LoadingProgress.height(LOADING_PROGRESS_HEIGHT); 2904 LoadingProgress.margin({ start: LengthMetrics.vp(LOADING_TEXT_MARGIN_LEFT) }); 2905 }, LoadingProgress); 2906 Row.pop(); 2907 Column.pop(); 2908 } 2909 onWillApplyTheme(theme) { 2910 this.fontColorWithTheme = theme.colors.fontPrimary; 2911 this.loadingProgressIconColorWithTheme = theme.colors.iconSecondary; 2912 } 2913 updateStateVars(params) { 2914 if (params === undefined) { 2915 return; 2916 } 2917 if ('content' in params) { 2918 this.updateParam('content', params.content); 2919 } 2920 } 2921 rerender() { 2922 this.updateDirtyElements(); 2923 } 2924} 2925__decorate([ 2926 Param 2927], LoadingDialogV2.prototype, 'content', void 0); 2928__decorate([ 2929 Local 2930], LoadingDialogV2.prototype, 'fontColorWithTheme', void 0); 2931__decorate([ 2932 Local 2933], LoadingDialogV2.prototype, 'loadingProgressIconColorWithTheme', void 0); 2934__decorate([ 2935 Provider() 2936], LoadingDialogV2.prototype, 'fontSizeScale', void 0); 2937__decorate([ 2938 Local 2939], LoadingDialogV2.prototype, 'minContentHeight', void 0); 2940export class PopoverDialogV2 extends ViewV2 { 2941 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda, extraInfo) { 2942 super(parent, elmtId, extraInfo); 2943 this.initParam('visible', (params && 'visible' in params) ? params.visible : false); 2944 this.$visible = '$visible' in params ? params.$visible : () => { }; 2945 this.initParam('popover', (params && 'popover' in params) ? params.popover : { 2946 builder: undefined 2947 }); 2948 this.targetBuilder = 'targetBuilder' in params ? params.targetBuilder : undefined; 2949 this.dialogWidth = this.popover?.width; 2950 this.finalizeConstruction(); 2951 } 2952 emptyBuilder(parent = null) { 2953 } 2954 aboutToAppear() { 2955 if (this.targetBuilder === undefined || this.targetBuilder === null) { 2956 this.targetBuilder = this.emptyBuilder; 2957 } 2958 } 2959 initialRender() { 2960 this.observeComponentCreation2((elmtId, isInitialRender) => { 2961 Column.create(); 2962 Column.onClick(() => { 2963 try { 2964 let screenSize = display.getDefaultDisplaySync(); 2965 let screenWidth = px2vp(screenSize.width); 2966 if (screenWidth - BUTTON_HORIZONTAL_MARGIN - BUTTON_HORIZONTAL_MARGIN > MAX_DIALOG_WIDTH) { 2967 this.popover.width = this.popover?.width ?? MAX_DIALOG_WIDTH; 2968 } 2969 else { 2970 this.popover.width = this.dialogWidth; 2971 } 2972 this.$visible?.(!this.visible); 2973 } 2974 catch (error) { 2975 let code = error.code; 2976 let message = error.message; 2977 hilog.error(0x3900, 'Ace', `dialog popup error, code: ${code}, message: ${message}`); 2978 } 2979 }); 2980 Column.bindPopup(this.visible, { 2981 builder: this.popover?.builder, 2982 placement: this.popover?.placement ?? Placement.Bottom, 2983 popupColor: this.popover?.popupColor, 2984 enableArrow: this.popover?.enableArrow ?? true, 2985 autoCancel: this.popover?.autoCancel, 2986 onStateChange: this.popover?.onStateChange ?? ((e) => { 2987 if (!e.isVisible) { 2988 this.$visible?.(false); 2989 } 2990 }), 2991 arrowOffset: this.popover?.arrowOffset, 2992 showInSubWindow: this.popover?.showInSubWindow, 2993 mask: this.popover?.mask, 2994 targetSpace: this.popover?.targetSpace, 2995 offset: this.popover?.offset, 2996 width: this.popover?.width, 2997 arrowPointPosition: this.popover?.arrowPointPosition, 2998 arrowWidth: this.popover?.arrowWidth, 2999 arrowHeight: this.popover?.arrowHeight, 3000 radius: this.popover?.radius ?? { 'id': -1, 'type': 10002, params: ['sys.float.corner_radius_level16'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }, 3001 shadow: this.popover?.shadow ?? ShadowStyle.OUTER_DEFAULT_MD, 3002 backgroundBlurStyle: this.popover?.backgroundBlurStyle ?? BlurStyle.COMPONENT_ULTRA_THICK, 3003 focusable: this.popover?.focusable, 3004 transition: this.popover?.transition, 3005 onWillDismiss: this.popover?.onWillDismiss 3006 }); 3007 }, Column); 3008 this.targetBuilder.bind(this)(); 3009 Column.pop(); 3010 } 3011 updateStateVars(params) { 3012 if (params === undefined) { 3013 return; 3014 } 3015 if ('visible' in params) { 3016 this.updateParam('visible', params.visible); 3017 } 3018 if ('popover' in params) { 3019 this.updateParam('popover', params.popover); 3020 } 3021 } 3022 rerender() { 3023 this.updateDirtyElements(); 3024 } 3025} 3026__decorate([ 3027 Param 3028], PopoverDialogV2.prototype, 'visible', void 0); 3029__decorate([ 3030 Event 3031], PopoverDialogV2.prototype, '$visible', void 0); 3032__decorate([ 3033 Param 3034], PopoverDialogV2.prototype, 'popover', void 0); 3035__decorate([ 3036 Local 3037], PopoverDialogV2.prototype, 'dialogWidth', void 0); 3038function toLengthString(value) { 3039 if (!value) { 3040 return undefined; 3041 } 3042 const length = value.value; 3043 let lengthString = ''; 3044 switch (value.unit) { 3045 case LengthUnit.PX: 3046 lengthString = `${length}px`; 3047 break; 3048 case LengthUnit.FP: 3049 lengthString = `${length}fp`; 3050 break; 3051 case LengthUnit.LPX: 3052 lengthString = `${length}lpx`; 3053 break; 3054 case LengthUnit.PERCENT: 3055 lengthString = `${length * 100}%`; 3056 break; 3057 case LengthUnit.VP: 3058 lengthString = `${length}vp`; 3059 break; 3060 default: 3061 lengthString = `${length}vp`; 3062 break; 3063 } 3064 return lengthString; 3065} 3066function lengthMetricsToPX(value) { 3067 if (!value) { 3068 return 0; 3069 } 3070 const length = value.value; 3071 switch (value.unit) { 3072 case LengthUnit.PX: 3073 return length; 3074 case LengthUnit.FP: 3075 return fp2px(length); 3076 case LengthUnit.LPX: 3077 return lpx2px(length); 3078 case LengthUnit.VP: 3079 return vp2px(length); 3080 default: 3081 return 0; 3082 } 3083} 3084export default { TipsDialogV2, ConfirmDialogV2, SelectDialogV2, AlertDialogV2, LoadingDialogV2, CustomContentDialogV2, PopoverDialogV2, AdvancedDialogV2Button };