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 ArkAlphabetIndexerComponent extends ArkComponent implements AlphabetIndexerAttribute { 18 constructor(nativePtr: KNode) { 19 super(nativePtr); 20 } 21 onSelected(callback: (index: number) => void): this { 22 throw new Error('Method not implemented.'); 23 } 24 color(value: ResourceColor): this { 25 modifierWithKey(this._modifiersWithKeys, ColorModifier.identity, ColorModifier, value); 26 return this; 27 } 28 selectedColor(value: ResourceColor): this { 29 modifierWithKey(this._modifiersWithKeys, SelectedColorModifier.identity, SelectedColorModifier, value); 30 return this; 31 } 32 popupColor(value: ResourceColor): this { 33 modifierWithKey(this._modifiersWithKeys, PopupColorModifier.identity, PopupColorModifier, value); 34 return this; 35 } 36 selectedBackgroundColor(value: ResourceColor): this { 37 modifierWithKey(this._modifiersWithKeys, SelectedBackgroundColorModifier.identity, SelectedBackgroundColorModifier, value); 38 return this; 39 } 40 popupBackground(value: ResourceColor): this { 41 modifierWithKey(this._modifiersWithKeys, PopupBackgroundModifier.identity, PopupBackgroundModifier, value); 42 return this; 43 } 44 popupSelectedColor(value: ResourceColor): this { 45 modifierWithKey(this._modifiersWithKeys, PopupSelectedColorModifier.identity, PopupSelectedColorModifier, value); 46 return this; 47 } 48 popupUnselectedColor(value: ResourceColor): this { 49 modifierWithKey(this._modifiersWithKeys, PopupUnselectedColorModifier.identity, PopupUnselectedColorModifier, value); 50 return this; 51 } 52 popupItemBackgroundColor(value: ResourceColor): this { 53 modifierWithKey(this._modifiersWithKeys, PopupItemBackgroundColorModifier.identity, PopupItemBackgroundColorModifier, value); 54 return this; 55 } 56 usingPopup(value: boolean): this { 57 modifierWithKey(this._modifiersWithKeys, UsingPopupModifier.identity, UsingPopupModifier, value); 58 return this; 59 } 60 selectedFont(value: Font): this { 61 modifierWithKey(this._modifiersWithKeys, SelectedFontModifier.identity, SelectedFontModifier, value); 62 return this; 63 } 64 popupFont(value: Font): this { 65 modifierWithKey(this._modifiersWithKeys, PopupFontModifier.identity, PopupFontModifier, value); 66 return this; 67 } 68 popupItemFont(value: Font): this { 69 modifierWithKey(this._modifiersWithKeys, PopupItemFontModifier.identity, PopupItemFontModifier, value); 70 return this; 71 } 72 itemSize(value: string | number): this { 73 modifierWithKey(this._modifiersWithKeys, ItemSizeModifier.identity, ItemSizeModifier, value); 74 return this; 75 } 76 font(value: Font): this { 77 modifierWithKey(this._modifiersWithKeys, AlphabetIndexerFontModifier.identity, AlphabetIndexerFontModifier, value); 78 return this; 79 } 80 alignStyle(value: IndexerAlign, offset?: any): this { 81 let alignStyle = new ArkAlignStyle; 82 alignStyle.indexerAlign = value; 83 alignStyle.offset = offset; 84 modifierWithKey(this._modifiersWithKeys, AlignStyleModifier.identity, AlignStyleModifier, alignStyle); 85 return this; 86 } 87 onSelect(callback: (index: number) => void): this { 88 throw new Error('Method not implemented.'); 89 } 90 onRequestPopupData(callback: (index: number) => string[]): this { 91 throw new Error('Method not implemented.'); 92 } 93 onPopupSelect(callback: (index: number) => void): this { 94 throw new Error('Method not implemented.'); 95 } 96 selected(index: number): this { 97 modifierWithKey(this._modifiersWithKeys, AlphabetIndexerSelectedModifier.identity, AlphabetIndexerSelectedModifier, index); 98 return this; 99 } 100 popupPosition(value: Position): this { 101 modifierWithKey(this._modifiersWithKeys, PopupPositionModifier.identity, PopupPositionModifier, value); 102 return this; 103 } 104} 105// @ts-ignore 106globalThis.AlphabetIndexer.attributeModifier = function (modifier) { 107 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 108 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 109 let component = this.createOrGetNode(elmtId, () => { 110 return new ArkAlphabetIndexerComponent(nativeNode); 111 }); 112 applyUIAttributes(modifier, nativeNode, component); 113 component.applyModifierPatch(); 114}; 115 116class PopupItemFontModifier extends ModifierWithKey<Font> { 117 constructor(value: Font) { 118 super(value); 119 } 120 static identity: Symbol = Symbol('popupItemFont'); 121 applyPeer(node: KNode, reset: boolean) { 122 if (reset) { 123 getUINativeModule().alphabetIndexer.resetPopupItemFont(node); 124 } else { 125 getUINativeModule().alphabetIndexer.setPopupItemFont(node, this.value.size, this.value.weight, this.value.family, this.value.style); 126 } 127 } 128 129 checkObjectDiff(): boolean { 130 let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size); 131 let weightEQ = this.stageValue.weight === this.value.weight; 132 let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family); 133 let styleEQ = this.stageValue.style === this.value.style; 134 return !sizeEQ || !weightEQ || !familyEQ || !styleEQ; 135 } 136} 137 138class SelectedFontModifier extends ModifierWithKey<Font> { 139 constructor(value: Font) { 140 super(value); 141 } 142 static identity: Symbol = Symbol('alphaBetIndexerSelectedFont'); 143 applyPeer(node: KNode, reset: boolean) { 144 if (reset) { 145 getUINativeModule().alphabetIndexer.resetSelectedFont(node); 146 } else { 147 getUINativeModule().alphabetIndexer.setSelectedFont(node, this.value.size, this.value.weight, this.value.family, this.value.style); 148 } 149 } 150 151 checkObjectDiff(): boolean { 152 let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size); 153 let weightEQ = this.stageValue.weight === this.value.weight; 154 let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family); 155 let styleEQ = this.stageValue.style === this.value.style; 156 return !sizeEQ || !weightEQ || !familyEQ || !styleEQ; 157 } 158} 159 160class PopupFontModifier extends ModifierWithKey<Font> { 161 constructor(value: Font) { 162 super(value); 163 } 164 static identity: Symbol = Symbol('popupFont'); 165 applyPeer(node: KNode, reset: boolean) { 166 if (reset) { 167 getUINativeModule().alphabetIndexer.resetPopupFont(node); 168 } else { 169 getUINativeModule().alphabetIndexer.setPopupFont(node, this.value.size, this.value.weight, this.value.family, this.value.style); 170 } 171 } 172 173 checkObjectDiff(): boolean { 174 let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size); 175 let weightEQ = this.stageValue.weight === this.value.weight; 176 let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family); 177 let styleEQ = this.stageValue.style === this.value.style; 178 return !sizeEQ || !weightEQ || !familyEQ || !styleEQ; 179 } 180} 181 182class AlphabetIndexerFontModifier extends ModifierWithKey<Font> { 183 constructor(value: Font) { 184 super(value); 185 } 186 static identity: Symbol = Symbol('alphaBetIndexerFont'); 187 applyPeer(node: KNode, reset: boolean) { 188 if (reset) { 189 getUINativeModule().alphabetIndexer.resetFont(node); 190 } else { 191 getUINativeModule().alphabetIndexer.setFont(node, this.value.size, this.value.weight, this.value.family, this.value.style); 192 } 193 } 194 195 checkObjectDiff(): boolean { 196 let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size); 197 let weightEQ = this.stageValue.weight === this.value.weight; 198 let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family); 199 let styleEQ = this.stageValue.style === this.value.style; 200 return !sizeEQ || !weightEQ || !familyEQ || !styleEQ; 201 } 202} 203 204class PopupItemBackgroundColorModifier extends ModifierWithKey<ResourceColor> { 205 constructor(value: ResourceColor) { 206 super(value); 207 } 208 static identity: Symbol = Symbol('popupItemBackgroundColor'); 209 applyPeer(node: KNode, reset: boolean): void { 210 if (reset) { 211 getUINativeModule().alphabetIndexer.resetPopupItemBackgroundColor(node); 212 } else { 213 getUINativeModule().alphabetIndexer.setPopupItemBackgroundColor(node, this.value); 214 } 215 } 216 217 checkObjectDiff(): boolean { 218 return !isBaseOrResourceEqual(this.stageValue, this.value); 219 } 220} 221 222class ColorModifier extends ModifierWithKey<ResourceColor> { 223 constructor(value: ResourceColor) { 224 super(value); 225 } 226 static identity: Symbol = Symbol('alphabetColor'); 227 applyPeer(node: KNode, reset: boolean): void { 228 if (reset) { 229 getUINativeModule().alphabetIndexer.resetColor(node); 230 } else { 231 getUINativeModule().alphabetIndexer.setColor(node, this.value); 232 } 233 } 234 235 checkObjectDiff(): boolean { 236 return !isBaseOrResourceEqual(this.stageValue, this.value); 237 } 238} 239 240class PopupColorModifier extends ModifierWithKey<ResourceColor> { 241 constructor(value: ResourceColor) { 242 super(value); 243 } 244 static identity: Symbol = Symbol('popupColor'); 245 applyPeer(node: KNode, reset: boolean): void { 246 if (reset) { 247 getUINativeModule().alphabetIndexer.resetPopupColor(node); 248 } else { 249 getUINativeModule().alphabetIndexer.setPopupColor(node, this.value); 250 } 251 } 252 253 checkObjectDiff(): boolean { 254 return !isBaseOrResourceEqual(this.stageValue, this.value); 255 } 256} 257 258class SelectedColorModifier extends ModifierWithKey<ResourceColor> { 259 constructor(value: ResourceColor) { 260 super(value); 261 } 262 static identity: Symbol = Symbol('selectedColor'); 263 applyPeer(node: KNode, reset: boolean): void { 264 if (reset) { 265 getUINativeModule().alphabetIndexer.resetSelectedColor(node); 266 } else { 267 getUINativeModule().alphabetIndexer.setSelectedColor(node, this.value); 268 } 269 } 270 271 checkObjectDiff(): boolean { 272 return !isBaseOrResourceEqual(this.stageValue, this.value); 273 } 274} 275 276class PopupBackgroundModifier extends ModifierWithKey<ResourceColor> { 277 constructor(value: ResourceColor) { 278 super(value); 279 } 280 static identity: Symbol = Symbol('popupBackground'); 281 applyPeer(node: KNode, reset: boolean): void { 282 if (reset) { 283 getUINativeModule().alphabetIndexer.resetPopupBackground(node); 284 } else { 285 getUINativeModule().alphabetIndexer.setPopupBackground(node, this.value); 286 } 287 } 288 289 checkObjectDiff(): boolean { 290 return !isBaseOrResourceEqual(this.stageValue, this.value); 291 } 292} 293 294class SelectedBackgroundColorModifier extends ModifierWithKey<ResourceColor> { 295 constructor(value: ResourceColor) { 296 super(value); 297 } 298 static identity: Symbol = Symbol('selectedBackgroundColor'); 299 applyPeer(node: KNode, reset: boolean): void { 300 if (reset) { 301 getUINativeModule().alphabetIndexer.resetSelectedBackgroundColor(node); 302 } else { 303 getUINativeModule().alphabetIndexer.setSelectedBackgroundColor(node, this.value); 304 } 305 } 306 307 checkObjectDiff(): boolean { 308 return !isBaseOrResourceEqual(this.stageValue, this.value); 309 } 310} 311 312class PopupUnselectedColorModifier extends ModifierWithKey<ResourceColor> { 313 constructor(value: ResourceColor) { 314 super(value); 315 } 316 static identity: Symbol = Symbol('popupUnselectedColor'); 317 applyPeer(node: KNode, reset: boolean): void { 318 if (reset) { 319 getUINativeModule().alphabetIndexer.resetPopupUnselectedColor(node); 320 } else { 321 getUINativeModule().alphabetIndexer.setPopupUnselectedColor(node, this.value); 322 } 323 } 324 325 checkObjectDiff(): boolean { 326 return !isBaseOrResourceEqual(this.stageValue, this.value); 327 } 328} 329 330class PopupSelectedColorModifier extends ModifierWithKey<ResourceColor> { 331 constructor(value: ResourceColor) { 332 super(value); 333 } 334 static identity: Symbol = Symbol('popupSelectedColor'); 335 applyPeer(node: KNode, reset: boolean): void { 336 if (reset) { 337 getUINativeModule().alphabetIndexer.resetPopupSelectedColor(node); 338 } else { 339 getUINativeModule().alphabetIndexer.setPopupSelectedColor(node, this.value); 340 } 341 } 342 343 checkObjectDiff(): boolean { 344 return !isBaseOrResourceEqual(this.stageValue, this.value); 345 } 346} 347 348class AlignStyleModifier extends ModifierWithKey<ArkAlignStyle> { 349 constructor(value: ArkAlignStyle) { 350 super(value); 351 } 352 static identity = Symbol('alignStyle'); 353 applyPeer(node: KNode, reset: boolean): void { 354 if (reset) { 355 getUINativeModule().alphabetIndexer.resetAlignStyle(node); 356 } else { 357 getUINativeModule().alphabetIndexer.setAlignStyle(node, this.value.indexerAlign, this.value.offset); 358 } 359 } 360 361 checkObjectDiff(): boolean { 362 let indexerAlignEQ = isBaseOrResourceEqual(this.stageValue.indexerAlign, this.value.indexerAlign); 363 let offsetEQ = isBaseOrResourceEqual(this.stageValue.offset, this.value.offset); 364 return !indexerAlignEQ || !offsetEQ; 365 } 366} 367 368class UsingPopupModifier extends ModifierWithKey<boolean> { 369 constructor(value: boolean) { 370 super(value); 371 } 372 static identity = Symbol('usingPopup'); 373 applyPeer(node: KNode, reset: boolean): void { 374 if (reset) { 375 getUINativeModule().alphabetIndexer.resetUsingPopup(node); 376 } else { 377 getUINativeModule().alphabetIndexer.setUsingPopup(node, this.value); 378 } 379 } 380} 381 382class AlphabetIndexerSelectedModifier extends ModifierWithKey<number> { 383 constructor(value: number) { 384 super(value); 385 } 386 static identity = Symbol('alphabetIndexerSelected'); 387 applyPeer(node: KNode, reset: boolean): void { 388 if (reset) { 389 getUINativeModule().alphabetIndexer.resetSelected(node); 390 } else { 391 getUINativeModule().alphabetIndexer.setSelected(node, this.value); 392 } 393 } 394} 395 396class ItemSizeModifier extends ModifierWithKey<number | string> { 397 constructor(value: number | string) { 398 super(value); 399 } 400 static identity: Symbol = Symbol('itemSize'); 401 applyPeer(node: KNode, reset: boolean): void { 402 if (reset) { 403 getUINativeModule().alphabetIndexer.resetItemSize(node); 404 } else { 405 getUINativeModule().alphabetIndexer.setItemSize(node, this.value); 406 } 407 } 408} 409 410class PopupPositionModifier extends ModifierWithKey<Position> { 411 constructor(value: Position) { 412 super(value); 413 } 414 static identity: Symbol = Symbol('popupPosition'); 415 applyPeer(node: KNode, reset: boolean): void { 416 if (reset) { 417 getUINativeModule().alphabetIndexer.resetPopupPosition(node); 418 } else { 419 getUINativeModule().alphabetIndexer.setPopupPosition(node, this.value.x, this.value.y); 420 } 421 } 422 423 checkObjectDiff(): boolean { 424 let xEQ = isBaseOrResourceEqual(this.stageValue.x, this.value.x); 425 let yEQ = isBaseOrResourceEqual(this.stageValue.y, this.value.y); 426 return !xEQ || !yEQ; 427 } 428} 429