1/* 2 * Copyright (c) 2023 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 16/// <reference path='./import.ts' /> 17class ArkSelectComponent extends ArkComponent implements SelectAttribute { 18 builder: WrappedBuilder<Object[]> | null = null; 19 menuItemNodes: Array<BuilderNode<[MenuItemConfiguration]>> | null = null; 20 modifier: ContentModifier<MenuItemConfiguration>; 21 constructor(nativePtr: KNode, classType?: ModifierType) { 22 super(nativePtr, classType); 23 } 24 allowChildCount(): number { 25 return 0; 26 } 27 initialize(value: Object[]): this { 28 if (!value.length) { 29 return this; 30 } 31 if (!isUndefined(value[0]) && !isNull(value[0]) && isObject(value[0])) { 32 modifierWithKey(this._modifiersWithKeys, SelectOptionsModifier.identity, SelectOptionsModifier, value[0]); 33 } else { 34 modifierWithKey(this._modifiersWithKeys, SelectOptionsModifier.identity, SelectOptionsModifier, undefined); 35 } 36 return this; 37 } 38 optionWidth(value: Dimension | OptionWidthMode): this { 39 modifierWithKey( 40 this._modifiersWithKeys, SelectOptionWidthModifier.identity, SelectOptionWidthModifier, value); 41 return this; 42 } 43 optionHeight(value: Dimension): this { 44 modifierWithKey( 45 this._modifiersWithKeys, SelectOptionHeightModifier.identity, SelectOptionHeightModifier, value); 46 return this; 47 } 48 width(value: Length): this { 49 modifierWithKey( 50 this._modifiersWithKeys, SelectWidthModifier.identity, SelectWidthModifier, value); 51 return this; 52 } 53 height(value: Length): this { 54 modifierWithKey( 55 this._modifiersWithKeys, SelectHeightModifier.identity, SelectHeightModifier, value); 56 return this; 57 } 58 size(value: SizeOptions): this { 59 modifierWithKey( 60 this._modifiersWithKeys, SelectSizeModifier.identity, SelectSizeModifier, value); 61 return this; 62 } 63 selected(value: number | Resource): this { 64 modifierWithKey( 65 this._modifiersWithKeys, SelectedModifier.identity, SelectedModifier, value); 66 return this; 67 } 68 value(value: ResourceStr): this { 69 modifierWithKey( 70 this._modifiersWithKeys, ValueModifier.identity, ValueModifier, value); 71 return this; 72 } 73 font(value: Font): this { 74 modifierWithKey( 75 this._modifiersWithKeys, FontModifier.identity, FontModifier, value); 76 return this; 77 } 78 fontColor(value: ResourceColor): this { 79 modifierWithKey( 80 this._modifiersWithKeys, SelectFontColorModifier.identity, SelectFontColorModifier, value); 81 return this; 82 } 83 selectedOptionBgColor(value: ResourceColor): this { 84 modifierWithKey( 85 this._modifiersWithKeys, SelectedOptionBgColorModifier.identity, SelectedOptionBgColorModifier, value); 86 return this; 87 } 88 selectedOptionFont(value: Font): this { 89 modifierWithKey( 90 this._modifiersWithKeys, SelectedOptionFontModifier.identity, SelectedOptionFontModifier, value); 91 return this; 92 } 93 selectedOptionFontColor(value: ResourceColor): this { 94 modifierWithKey( 95 this._modifiersWithKeys, SelectedOptionFontColorModifier.identity, SelectedOptionFontColorModifier, value); 96 return this; 97 } 98 optionBgColor(value: ResourceColor): this { 99 modifierWithKey( 100 this._modifiersWithKeys, OptionBgColorModifier.identity, OptionBgColorModifier, value); 101 return this; 102 } 103 optionFont(value: Font): this { 104 modifierWithKey( 105 this._modifiersWithKeys, OptionFontModifier.identity, OptionFontModifier, value); 106 return this; 107 } 108 optionFontColor(value: ResourceColor): this { 109 modifierWithKey( 110 this._modifiersWithKeys, OptionFontColorModifier.identity, OptionFontColorModifier, value); 111 return this; 112 } 113 onSelect(callback: (index: number, value: string) => void): this { 114 throw new Error('Method not implemented.'); 115 } 116 space(value: Length): this { 117 modifierWithKey( 118 this._modifiersWithKeys, SpaceModifier.identity, SpaceModifier, value); 119 return this; 120 } 121 arrowPosition(value: ArrowPosition): this { 122 modifierWithKey( 123 this._modifiersWithKeys, ArrowPositionModifier.identity, ArrowPositionModifier, value); 124 return this; 125 } 126 menuAlign(alignType: MenuAlignType, offset?: Offset): this { 127 let menuAlign = new ArkMenuAlignType(alignType, offset); 128 modifierWithKey( 129 this._modifiersWithKeys, MenuAlignModifier.identity, MenuAlignModifier, menuAlign); 130 return this; 131 } 132 avoidance(mode: AvoidanceMode): this { 133 modifierWithKey( 134 this._modifiersWithKeys, AvoidanceModifier.identity, AvoidanceModifier, mode); 135 return this; 136 } 137 menuBackgroundColor(value: ResourceColor): this { 138 modifierWithKey( 139 this._modifiersWithKeys, MenuBackgroundColorModifier.identity, MenuBackgroundColorModifier, value); 140 return this; 141 } 142 menuBackgroundBlurStyle(value: BlurStyle): this { 143 modifierWithKey( 144 this._modifiersWithKeys, MenuBackgroundBlurStyleModifier.identity, MenuBackgroundBlurStyleModifier, value); 145 return this; 146 } 147 controlSize(controlSize: ControlSize): this { 148 modifierWithKey( 149 this._modifiersWithKeys, ControlSizeModifier.identity, ControlSizeModifier, controlSize); 150 return this; 151 } 152 menuItemContentModifier(modifier: ContentModifier<MenuItemConfiguration>): this { 153 if (modifier === undefined || modifier === null) { 154 getUINativeModule().select.setContentModifierBuilder(this.nativePtr, false); 155 return; 156 } 157 this.builder = modifier.applyContent(); 158 this.modifier = modifier; 159 getUINativeModule().select.setContentModifierBuilder(this.nativePtr, this); 160 } 161 makeContentModifierNode(context: UIContext, menuItemConfiguration: MenuItemConfiguration): FrameNode | null { 162 menuItemConfiguration.contentModifier = this.modifier; 163 const index = menuItemConfiguration.index; 164 const xNode = globalThis.requireNapi('arkui.node'); 165 this.menuItemNodes = new xNode.BuilderNode(context); 166 this.menuItemNodes.build(this.builder, menuItemConfiguration); 167 return this.menuItemNodes.getFrameNode(); 168 } 169 divider(value: DividerOptions | null): this { 170 modifierWithKey( 171 this._modifiersWithKeys, SelectDividerModifier.identity, SelectDividerModifier, value); 172 return this; 173 } 174 dividerStyle(value: Optional<DividerStyleOptions>): this { 175 modifierWithKey( 176 this._modifiersWithKeys, SelectDividerStyleModifier.identity, SelectDividerStyleModifier, value); 177 return this; 178 } 179 direction(value: Direction): this { 180 modifierWithKey(this._modifiersWithKeys, SelectDirectionModifier.identity, SelectDirectionModifier, value); 181 return this; 182 } 183} 184 185class SelectOptionsModifier extends ModifierWithKey<SelectOption[]> { 186 constructor(value: SelectOption[]) { 187 super(value); 188 } 189 static identity: Symbol = Symbol('selectOptions'); 190 applyPeer(node: KNode, reset: boolean): void { 191 if (reset) { 192 getUINativeModule().select.setOptions(node, undefined, undefined, undefined, undefined); 193 } else { 194 let valueArray: string[] = []; 195 let iconArray: string[] = []; 196 let symbolIconArray: object[] = []; 197 let length: number = 0; 198 if (this.value) { 199 length = this.value.length; 200 for (let i = 0; i < length; i++) { 201 valueArray.push(this.value[i]?.value); 202 iconArray.push(this.value[i]?.icon); 203 symbolIconArray.push(this.value[i]?.symbolIcon); 204 } 205 } 206 207 getUINativeModule().select.setOptions(node, valueArray, iconArray, symbolIconArray, length); 208 } 209 } 210 211 checkObjectDiff(): boolean { 212 return !(Array.isArray(this.stageValue) && Array.isArray(this.value) && 213 this.stageValue.length === this.value.length && 214 this.stageValue.every((eachValue, index) => { 215 return isBaseOrResourceEqual(eachValue.value, this.value[index].value) && 216 isBaseOrResourceEqual(eachValue.icon, this.value[index].icon) && 217 isBaseOrResourceEqual(eachValue.symbolIcon, this.value[index].symbolIcon); 218 })); 219 } 220} 221 222class MenuBackgroundColorModifier extends ModifierWithKey<ResourceColor> { 223 constructor(value: ResourceColor) { 224 super(value); 225 } 226 static identity: Symbol = Symbol('selectMenuBackgroundColor'); 227 applyPeer(node: KNode, reset: boolean): void { 228 if (reset) { 229 getUINativeModule().select.resetMenuBackgroundColor(node); 230 } else { 231 getUINativeModule().select.setMenuBackgroundColor(node, this.value); 232 } 233 } 234 235 checkObjectDiff(): boolean { 236 return !isBaseOrResourceEqual(this.stageValue, this.value); 237 } 238} 239 240class MenuBackgroundBlurStyleModifier extends ModifierWithKey<BlurStyle> { 241 constructor(value: BlurStyle) { 242 super(value); 243 } 244 static identity: Symbol = Symbol('selectMenuBackgroundBlurStyle'); 245 applyPeer(node: KNode, reset: boolean): void { 246 if (reset) { 247 getUINativeModule().select.resetMenuBackgroundBlurStyle(node); 248 } else { 249 getUINativeModule().select.setMenuBackgroundBlurStyle(node, this.value); 250 } 251 } 252 253 checkObjectDiff(): boolean { 254 return !isBaseOrResourceEqual(this.stageValue, this.value); 255 } 256} 257 258class FontModifier extends ModifierWithKey<Font> { 259 constructor(value: Font) { 260 super(value); 261 } 262 static identity: Symbol = Symbol('selectFont'); 263 applyPeer(node: KNode, reset: boolean): void { 264 if (reset) { 265 getUINativeModule().select.resetFont(node); 266 } else { 267 getUINativeModule().select.setFont(node, this.value.size, this.value.weight, this.value.family, this.value.style); 268 } 269 } 270 271 checkObjectDiff(): boolean { 272 let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size); 273 let weightEQ = this.stageValue.weight === this.value.weight; 274 let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family); 275 let styleEQ = this.stageValue.style === this.value.style; 276 return !sizeEQ || !weightEQ || !familyEQ || !styleEQ; 277 } 278} 279 280class OptionFontModifier extends ModifierWithKey<Font> { 281 constructor(value: Font) { 282 super(value); 283 } 284 static identity: Symbol = Symbol('selectOptionFont'); 285 applyPeer(node: KNode, reset: boolean): void { 286 if (reset) { 287 getUINativeModule().select.resetOptionFont(node); 288 } else { 289 getUINativeModule().select.setOptionFont(node, this.value.size, this.value.weight, this.value.family, this.value.style); 290 } 291 } 292 293 checkObjectDiff(): boolean { 294 let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size); 295 let weightEQ = this.stageValue.weight === this.value.weight; 296 let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family); 297 let styleEQ = this.stageValue.style === this.value.style; 298 return !sizeEQ || !weightEQ || !familyEQ || !styleEQ; 299 } 300} 301 302class SelectedOptionFontModifier extends ModifierWithKey<Font> { 303 constructor(value: Font) { 304 super(value); 305 } 306 static identity: Symbol = Symbol('selectSelectedOptionFont'); 307 applyPeer(node: KNode, reset: boolean): void { 308 if (reset) { 309 getUINativeModule().select.resetSelectedOptionFont(node); 310 } else { 311 getUINativeModule().select.setSelectedOptionFont(node, this.value.size, this.value.weight, this.value.family, this.value.style); 312 } 313 } 314 315 checkObjectDiff(): boolean { 316 let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size); 317 let weightEQ = this.stageValue.weight === this.value.weight; 318 let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family); 319 let styleEQ = this.stageValue.style === this.value.style; 320 return !sizeEQ || !weightEQ || !familyEQ || !styleEQ; 321 } 322} 323 324class MenuAlignModifier extends ModifierWithKey<ArkMenuAlignType> { 325 constructor(value: ArkMenuAlignType) { 326 super(value); 327 } 328 static identity: Symbol = Symbol('selectMenuAlign'); 329 applyPeer(node: KNode, reset: boolean): void { 330 if (reset) { 331 getUINativeModule().select.resetMenuAlign(node); 332 } else { 333 getUINativeModule().select.setMenuAlign(node, this.value.alignType, this.value.dx, this.value.dy); 334 } 335 } 336 337 checkObjectDiff(): boolean { 338 let alignTypeEQ = this.stageValue.alignType === this.value.alignType; 339 let dxEQ = isBaseOrResourceEqual(this.stageValue, this.value); 340 let dyEQ = isBaseOrResourceEqual(this.stageValue, this.value); 341 342 return !alignTypeEQ || !dxEQ || !dyEQ; 343 } 344 345 private isEqual(stageValue: Length, value: Length): boolean { 346 if ((!isUndefined(stageValue) && isResource(stageValue)) && 347 (!isUndefined(value) && isResource(value))) { 348 return !isResourceEqual(stageValue, value); 349 } else { 350 return stageValue !== value; 351 } 352 } 353} 354 355class AvoidanceModifier extends ModifierWithKey<AvoidanceMode> { 356 constructor(value: AvoidanceMode) { 357 super(value); 358 } 359 static identity: Symbol = Symbol('selectAvoidance'); 360 applyPeer(node: KNode, reset: boolean): void { 361 if (reset) { 362 getUINativeModule().select.resetAvoidance(node); 363 } else { 364 getUINativeModule().select.setAvoidance(node, this.value); 365 } 366 } 367 checkObjectDiff(): boolean { 368 return this.stageValue !== this.value; 369 } 370} 371 372class ControlSizeModifier extends ModifierWithKey<ControlSize> { 373 constructor(value: ControlSize) { 374 super(value); 375 } 376 static identity: Symbol = Symbol('controlSize'); 377 applyPeer(node: KNode, reset: boolean): void { 378 if (reset) { 379 getUINativeModule().select.resetControlSize(node); 380 } else { 381 getUINativeModule().select.setControlSize(node, this.value); 382 } 383 } 384 385 checkObjectDiff(): boolean { 386 return this.stageValue !== this.value; 387 } 388} 389 390class ArrowPositionModifier extends ModifierWithKey<ArrowPosition> { 391 constructor(value: ArrowPosition) { 392 super(value); 393 } 394 static identity: Symbol = Symbol('selectArrowPosition'); 395 applyPeer(node: KNode, reset: boolean): void { 396 if (reset) { 397 getUINativeModule().select.resetArrowPosition(node); 398 } else { 399 getUINativeModule().select.setArrowPosition(node, this.value); 400 } 401 } 402 403 checkObjectDiff(): boolean { 404 return this.stageValue !== this.value; 405 } 406} 407class SpaceModifier extends ModifierWithKey<Length> { 408 constructor(value: Length) { 409 super(value); 410 } 411 static identity: Symbol = Symbol('selectSpace'); 412 413 applyPeer(node: KNode, reset: boolean): void { 414 if (reset) { 415 getUINativeModule().select.resetSpace(node); 416 } else { 417 getUINativeModule().select.setSpace(node, this.value); 418 } 419 } 420 421 checkObjectDiff(): boolean { 422 return !isBaseOrResourceEqual(this.stageValue, this.value); 423 } 424} 425class ValueModifier extends ModifierWithKey<ResourceStr> { 426 constructor(value: ResourceStr) { 427 super(value); 428 } 429 static identity: Symbol = Symbol('selectValue'); 430 431 applyPeer(node: KNode, reset: boolean): void { 432 if (reset) { 433 getUINativeModule().select.resetValue(node); 434 } else { 435 getUINativeModule().select.setValue(node, this.value); 436 } 437 } 438 439 checkObjectDiff(): boolean { 440 return !isBaseOrResourceEqual(this.stageValue, this.value); 441 } 442} 443class SelectedModifier extends ModifierWithKey<number | Resource> { 444 constructor(value: number | Resource) { 445 super(value); 446 } 447 static identity: Symbol = Symbol('selectSelected'); 448 449 applyPeer(node: KNode, reset: boolean): void { 450 if (reset) { 451 getUINativeModule().select.resetSelected(node); 452 } else { 453 getUINativeModule().select.setSelected(node, this.value); 454 } 455 } 456 457 checkObjectDiff(): boolean { 458 return !isBaseOrResourceEqual(this.stageValue, this.value); 459 } 460} 461class SelectFontColorModifier extends ModifierWithKey<ResourceColor> { 462 constructor(value: ResourceColor) { 463 super(value); 464 } 465 static identity: Symbol = Symbol('selectFontColor'); 466 467 applyPeer(node: KNode, reset: boolean): void { 468 if (reset) { 469 getUINativeModule().select.resetFontColor(node); 470 } else { 471 getUINativeModule().select.setFontColor(node, this.value); 472 } 473 } 474 checkObjectDiff(): boolean { 475 return !isBaseOrResourceEqual(this.stageValue, this.value); 476 } 477} 478class SelectedOptionBgColorModifier extends ModifierWithKey<ResourceColor> { 479 constructor(value: ResourceColor) { 480 super(value); 481 } 482 static identity: Symbol = Symbol('selectSelectedOptionBgColor'); 483 484 applyPeer(node: KNode, reset: boolean): void { 485 if (reset) { 486 getUINativeModule().select.resetSelectedOptionBgColor(node); 487 } else { 488 getUINativeModule().select.setSelectedOptionBgColor(node, this.value); 489 } 490 } 491 checkObjectDiff(): boolean { 492 return !isBaseOrResourceEqual(this.stageValue, this.value); 493 } 494} 495class OptionBgColorModifier extends ModifierWithKey<ResourceColor> { 496 constructor(value: ResourceColor) { 497 super(value); 498 } 499 static identity: Symbol = Symbol('selectOptionBgColor'); 500 501 applyPeer(node: KNode, reset: boolean): void { 502 if (reset) { 503 getUINativeModule().select.resetOptionBgColor(node); 504 } else { 505 getUINativeModule().select.setOptionBgColor(node, this.value); 506 } 507 } 508 checkObjectDiff(): boolean { 509 return !isBaseOrResourceEqual(this.stageValue, this.value); 510 } 511} 512class OptionFontColorModifier extends ModifierWithKey<ResourceColor> { 513 constructor(value: ResourceColor) { 514 super(value); 515 } 516 static identity: Symbol = Symbol('selectOptionFontColor'); 517 518 applyPeer(node: KNode, reset: boolean): void { 519 if (reset) { 520 getUINativeModule().select.resetOptionFontColor(node); 521 } else { 522 getUINativeModule().select.setOptionFontColor(node, this.value); 523 } 524 } 525 checkObjectDiff(): boolean { 526 return !isBaseOrResourceEqual(this.stageValue, this.value); 527 } 528} 529class SelectedOptionFontColorModifier extends ModifierWithKey<ResourceColor> { 530 constructor(value: ResourceColor) { 531 super(value); 532 } 533 static identity: Symbol = Symbol('selectSelectedOptionFontColor'); 534 535 applyPeer(node: KNode, reset: boolean): void { 536 if (reset) { 537 getUINativeModule().select.resetSelectedOptionFontColor(node); 538 } else { 539 getUINativeModule().select.setSelectedOptionFontColor(node, this.value); 540 } 541 } 542 checkObjectDiff(): boolean { 543 return !isBaseOrResourceEqual(this.stageValue, this.value); 544 } 545} 546 547class SelectOptionWidthModifier extends ModifierWithKey<Dimension | OptionWidthMode> { 548 constructor(value: Dimension | OptionWidthMode) { 549 super(value); 550 } 551 static identity: Symbol = Symbol('selectOptionWidth'); 552 553 applyPeer(node: KNode, reset: boolean): void { 554 if (reset) { 555 getUINativeModule().select.resetOptionWidth(node); 556 } else { 557 getUINativeModule().select.setOptionWidth(node, this.value); 558 } 559 } 560 561 checkObjectDiff(): boolean { 562 return !isBaseOrResourceEqual(this.stageValue, this.value); 563 } 564} 565 566class SelectOptionHeightModifier extends ModifierWithKey<Dimension> { 567 constructor(value: Dimension) { 568 super(value); 569 } 570 static identity: Symbol = Symbol('selectOptionHeight'); 571 572 applyPeer(node: KNode, reset: boolean): void { 573 if (reset) { 574 getUINativeModule().select.resetOptionHeight(node); 575 } else { 576 getUINativeModule().select.setOptionHeight(node, this.value); 577 } 578 } 579 580 checkObjectDiff(): boolean { 581 return !isBaseOrResourceEqual(this.stageValue, this.value); 582 } 583} 584 585class SelectWidthModifier extends ModifierWithKey<Length> { 586 constructor(value: Length) { 587 super(value); 588 } 589 static identity: Symbol = Symbol('selectWidth'); 590 591 applyPeer(node: KNode, reset: boolean): void { 592 if (reset) { 593 getUINativeModule().select.resetWidth(node); 594 } else { 595 getUINativeModule().select.setWidth(node, this.value); 596 } 597 } 598 599 checkObjectDiff(): boolean { 600 return !isBaseOrResourceEqual(this.stageValue, this.value); 601 } 602} 603 604class SelectDividerModifier extends ModifierWithKey<DividerOptions | null> { 605 constructor(value: DividerOptions | null) { 606 super(value); 607 } 608 static identity: Symbol = Symbol('selectDivider'); 609 applyPeer(node: KNode, reset: boolean): void { 610 if (reset) { 611 getUINativeModule().select.resetDivider(node, this.value); 612 } else { 613 getUINativeModule().select.setDivider(node, this.value?.strokeWidth, this.value?.color, this.value?.startMargin, this.value?.endMargin); 614 } 615 } 616 617 checkObjectDiff(): boolean { 618 return !(this.stageValue?.strokeWidth === this.value?.strokeWidth && 619 this.stageValue?.color === this.value?.color && 620 this.stageValue?.startMargin === this.value?.startMargin && 621 this.stageValue?.endMargin === this.value?.endMargin); 622 } 623} 624 625class SelectDividerStyleModifier extends ModifierWithKey<Optional<DividerStyleOptions>> { 626 constructor(value: Optional<DividerStyleOptions>) { 627 super(value); 628 } 629 static identity: Symbol = Symbol('selectDividerStyle'); 630 applyPeer(node: KNode, reset: boolean): void { 631 if (reset || !this.value) { 632 getUINativeModule().select.resetDividerStyle(node); 633 } else { 634 getUINativeModule().select.setDividerStyle(node, this.value.strokeWidth, this.value.color, this.value.startMargin, this.value.endMargin, this.value.mode); 635 } 636 } 637 638 checkObjectDiff(): boolean { 639 if (isResource(this.stageValue) && isResource(this.value)) { 640 return !isResourceEqual(this.stageValue, this.value); 641 } else if (!isResource(this.stageValue) && !isResource(this.value)) { 642 return !((this.stageValue as DividerStyleOptions).strokeWidth === (this.value as DividerStyleOptions).strokeWidth && 643 (this.stageValue as DividerStyleOptions).color === (this.value as DividerStyleOptions).color && 644 (this.stageValue as DividerStyleOptions).startMargin === (this.value as DividerStyleOptions).startMargin && 645 (this.stageValue as DividerStyleOptions).endMargin === (this.value as DividerStyleOptions).endMargin && 646 (this.stageValue as DividerStyleOptions).mode === (this.value as DividerStyleOptions).mode); 647 } else { 648 return true; 649 } 650 } 651} 652 653class SelectHeightModifier extends ModifierWithKey<Length> { 654 constructor(value: Length) { 655 super(value); 656 } 657 static identity: Symbol = Symbol('selectHeight'); 658 659 applyPeer(node: KNode, reset: boolean): void { 660 if (reset) { 661 getUINativeModule().select.resetHeight(node); 662 } else { 663 getUINativeModule().select.setHeight(node, this.value); 664 } 665 } 666 667 checkObjectDiff(): boolean { 668 return !isBaseOrResourceEqual(this.stageValue, this.value); 669 } 670} 671 672class SelectSizeModifier extends ModifierWithKey<SizeOptions> { 673 constructor(value: SizeOptions) { 674 super(value); 675 } 676 static identity: Symbol = Symbol('selectSize'); 677 678 applyPeer(node: KNode, reset: boolean): void { 679 if (reset) { 680 getUINativeModule().select.resetSize(node); 681 } else { 682 getUINativeModule().select.setSize(node, this.value.width, this.value.height); 683 } 684 } 685 686 checkObjectDiff(): boolean { 687 return !isBaseOrResourceEqual(this.stageValue.width, this.value.width) || 688 !isBaseOrResourceEqual(this.stageValue.height, this.value.height); 689 } 690} 691 692class SelectDirectionModifier extends ModifierWithKey<number> { 693 constructor(value: number) { 694 super(value); 695 } 696 static identity: Symbol = Symbol('selectDirection'); 697 applyPeer(node: KNode, reset: boolean): void { 698 if (reset) { 699 getUINativeModule().select.resetSelectDirection(node); 700 } else { 701 getUINativeModule().select.setSelectDirection(node, this.value!); 702 } 703 } 704 checkObjectDiff(): boolean { 705 return !isBaseOrResourceEqual(this.stageValue, this.value); 706 } 707} 708 709// @ts-ignore 710globalThis.Select.attributeModifier = function (modifier: ArkComponent): void { 711 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 712 return new ArkSelectComponent(nativePtr); 713 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 714 return new modifierJS.SelectModifier(nativePtr, classType); 715 }); 716}; 717 718// @ts-ignore 719globalThis.Select.menuItemContentModifier = function (modifier): void { 720 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 721 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 722 let component = this.createOrGetNode(elmtId, () => { 723 return new ArkSelectComponent(nativeNode); 724 }); 725 component.menuItemContentModifier(modifier); 726}; 727