• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, classType?: ModifierType) {
19    super(nativePtr, classType);
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  popupItemBorderRadius(value: number): this {
105    modifierWithKey(this._modifiersWithKeys, PopupItemBorderRadiusModifier.identity, PopupItemBorderRadiusModifier, value);
106    return this;
107  }
108  itemBorderRadius(value: number): this {
109    modifierWithKey(this._modifiersWithKeys, ItemBorderRadiusModifier.identity, ItemBorderRadiusModifier, value);
110    return this;
111  }
112  popupBackgroundBlurStyle(value: BlurStyle): this {
113    modifierWithKey(this._modifiersWithKeys, PopupBackgroundBlurStyleModifier.identity, PopupBackgroundBlurStyleModifier, value);
114    return this;
115  }
116  popupTitleBackground(value: ResourceColor): this {
117    modifierWithKey(this._modifiersWithKeys, PopupTitleBackgroundModifier.identity, PopupTitleBackgroundModifier, value);
118    return this;
119  }
120  width(value: Length): this {
121    modifierWithKey(this._modifiersWithKeys, AdaptiveWidthModifier.identity, AdaptiveWidthModifier, value);
122    return this;
123  }
124  autoCollapse(value: boolean): this {
125    modifierWithKey(this._modifiersWithKeys, AutoCollapseModifier.identity, AutoCollapseModifier, value);
126    return this;
127  }
128  enableHapticFeedback(value: boolean): this {
129    modifierWithKey(this._modifiersWithKeys, EnableHapticFeedbackModifier.identity, EnableHapticFeedbackModifier, value);
130    return this;
131  }
132}
133// @ts-ignore
134globalThis.AlphabetIndexer.attributeModifier = function (modifier: ArkComponent): void {
135  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
136    return new ArkAlphabetIndexerComponent(nativePtr);
137  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
138    return new modifierJS.AlphabetIndexerModifier(nativePtr, classType);
139  });
140};
141
142class PopupItemFontModifier extends ModifierWithKey<Font> {
143  static identity: Symbol = Symbol('popupItemFont');
144  applyPeer(node: KNode, reset: boolean) {
145    if (reset) {
146      getUINativeModule().alphabetIndexer.resetPopupItemFont(node);
147    } else {
148      getUINativeModule().alphabetIndexer.setPopupItemFont(node, this.value.size, this.value.weight, this.value.family, this.value.style);
149    }
150  }
151
152  checkObjectDiff(): boolean {
153    let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size);
154    let weightEQ = this.stageValue.weight === this.value.weight;
155    let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family);
156    let styleEQ = this.stageValue.style === this.value.style;
157    return !sizeEQ || !weightEQ || !familyEQ || !styleEQ;
158  }
159}
160
161class SelectedFontModifier extends ModifierWithKey<Font> {
162  static identity: Symbol = Symbol('alphaBetIndexerSelectedFont');
163  applyPeer(node: KNode, reset: boolean) {
164    if (reset) {
165      getUINativeModule().alphabetIndexer.resetSelectedFont(node);
166    } else {
167      getUINativeModule().alphabetIndexer.setSelectedFont(node, this.value.size, this.value.weight, this.value.family, this.value.style);
168    }
169  }
170
171  checkObjectDiff(): boolean {
172    let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size);
173    let weightEQ = this.stageValue.weight === this.value.weight;
174    let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family);
175    let styleEQ = this.stageValue.style === this.value.style;
176    return !sizeEQ || !weightEQ || !familyEQ || !styleEQ;
177  }
178}
179
180class PopupFontModifier extends ModifierWithKey<Font> {
181  static identity: Symbol = Symbol('popupFont');
182  applyPeer(node: KNode, reset: boolean) {
183    if (reset) {
184      getUINativeModule().alphabetIndexer.resetPopupFont(node);
185    } else {
186      getUINativeModule().alphabetIndexer.setPopupFont(node, this.value.size, this.value.weight, this.value.family, this.value.style);
187    }
188  }
189
190  checkObjectDiff(): boolean {
191    let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size);
192    let weightEQ = this.stageValue.weight === this.value.weight;
193    let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family);
194    let styleEQ = this.stageValue.style === this.value.style;
195    return !sizeEQ || !weightEQ || !familyEQ || !styleEQ;
196  }
197}
198
199class AlphabetIndexerFontModifier extends ModifierWithKey<Font> {
200  static identity: Symbol = Symbol('alphaBetIndexerFont');
201  applyPeer(node: KNode, reset: boolean) {
202    if (reset) {
203      getUINativeModule().alphabetIndexer.resetFont(node);
204    } else {
205      getUINativeModule().alphabetIndexer.setFont(node, this.value.size, this.value.weight, this.value.family, this.value.style);
206    }
207  }
208
209  checkObjectDiff(): boolean {
210    let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size);
211    let weightEQ = this.stageValue.weight === this.value.weight;
212    let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family);
213    let styleEQ = this.stageValue.style === this.value.style;
214    return !sizeEQ || !weightEQ || !familyEQ || !styleEQ;
215  }
216}
217
218class PopupItemBackgroundColorModifier extends ModifierWithKey<ResourceColor> {
219  constructor(value: ResourceColor) {
220    super(value);
221  }
222  static identity: Symbol = Symbol('popupItemBackgroundColor');
223  applyPeer(node: KNode, reset: boolean): void {
224    if (reset) {
225      getUINativeModule().alphabetIndexer.resetPopupItemBackgroundColor(node);
226    } else {
227      getUINativeModule().alphabetIndexer.setPopupItemBackgroundColor(node, this.value);
228    }
229  }
230
231  checkObjectDiff(): boolean {
232    return !isBaseOrResourceEqual(this.stageValue, this.value);
233  }
234}
235
236class ColorModifier extends ModifierWithKey<ResourceColor> {
237  constructor(value: ResourceColor) {
238    super(value);
239  }
240  static identity: Symbol = Symbol('alphabetColor');
241  applyPeer(node: KNode, reset: boolean): void {
242    if (reset) {
243      getUINativeModule().alphabetIndexer.resetColor(node);
244    } else {
245      getUINativeModule().alphabetIndexer.setColor(node, this.value);
246    }
247  }
248
249  checkObjectDiff(): boolean {
250    return !isBaseOrResourceEqual(this.stageValue, this.value);
251  }
252}
253
254class PopupColorModifier extends ModifierWithKey<ResourceColor> {
255  constructor(value: ResourceColor) {
256    super(value);
257  }
258  static identity: Symbol = Symbol('popupColor');
259  applyPeer(node: KNode, reset: boolean): void {
260    if (reset) {
261      getUINativeModule().alphabetIndexer.resetPopupColor(node);
262    } else {
263      getUINativeModule().alphabetIndexer.setPopupColor(node, this.value);
264    }
265  }
266
267  checkObjectDiff(): boolean {
268    return !isBaseOrResourceEqual(this.stageValue, this.value);
269  }
270}
271
272class SelectedColorModifier extends ModifierWithKey<ResourceColor> {
273  constructor(value: ResourceColor) {
274    super(value);
275  }
276  static identity: Symbol = Symbol('selectedColor');
277  applyPeer(node: KNode, reset: boolean): void {
278    if (reset) {
279      getUINativeModule().alphabetIndexer.resetSelectedColor(node);
280    } else {
281      getUINativeModule().alphabetIndexer.setSelectedColor(node, this.value);
282    }
283  }
284
285  checkObjectDiff(): boolean {
286    return !isBaseOrResourceEqual(this.stageValue, this.value);
287  }
288}
289
290class PopupBackgroundModifier extends ModifierWithKey<ResourceColor> {
291  constructor(value: ResourceColor) {
292    super(value);
293  }
294  static identity: Symbol = Symbol('popupBackground');
295  applyPeer(node: KNode, reset: boolean): void {
296    if (reset) {
297      getUINativeModule().alphabetIndexer.resetPopupBackground(node);
298    } else {
299      getUINativeModule().alphabetIndexer.setPopupBackground(node, this.value);
300    }
301  }
302
303  checkObjectDiff(): boolean {
304    return !isBaseOrResourceEqual(this.stageValue, this.value);
305  }
306}
307
308class SelectedBackgroundColorModifier extends ModifierWithKey<ResourceColor> {
309  constructor(value: ResourceColor) {
310    super(value);
311  }
312  static identity: Symbol = Symbol('selectedBackgroundColor');
313  applyPeer(node: KNode, reset: boolean): void {
314    if (reset) {
315      getUINativeModule().alphabetIndexer.resetSelectedBackgroundColor(node);
316    } else {
317      getUINativeModule().alphabetIndexer.setSelectedBackgroundColor(node, this.value);
318    }
319  }
320
321  checkObjectDiff(): boolean {
322    return !isBaseOrResourceEqual(this.stageValue, this.value);
323  }
324}
325
326class PopupUnselectedColorModifier extends ModifierWithKey<ResourceColor> {
327  constructor(value: ResourceColor) {
328    super(value);
329  }
330  static identity: Symbol = Symbol('popupUnselectedColor');
331  applyPeer(node: KNode, reset: boolean): void {
332    if (reset) {
333      getUINativeModule().alphabetIndexer.resetPopupUnselectedColor(node);
334    } else {
335      getUINativeModule().alphabetIndexer.setPopupUnselectedColor(node, this.value);
336    }
337  }
338
339  checkObjectDiff(): boolean {
340    return !isBaseOrResourceEqual(this.stageValue, this.value);
341  }
342}
343
344class PopupSelectedColorModifier extends ModifierWithKey<ResourceColor> {
345  constructor(value: ResourceColor) {
346    super(value);
347  }
348  static identity: Symbol = Symbol('popupSelectedColor');
349  applyPeer(node: KNode, reset: boolean): void {
350    if (reset) {
351      getUINativeModule().alphabetIndexer.resetPopupSelectedColor(node);
352    } else {
353      getUINativeModule().alphabetIndexer.setPopupSelectedColor(node, this.value);
354    }
355  }
356
357  checkObjectDiff(): boolean {
358    return !isBaseOrResourceEqual(this.stageValue, this.value);
359  }
360}
361
362class AlignStyleModifier extends ModifierWithKey<ArkAlignStyle> {
363  static identity = Symbol('alignStyle');
364  applyPeer(node: KNode, reset: boolean): void {
365    if (reset) {
366      getUINativeModule().alphabetIndexer.resetAlignStyle(node);
367    } else {
368      getUINativeModule().alphabetIndexer.setAlignStyle(node, this.value.indexerAlign, this.value.offset);
369    }
370  }
371
372  checkObjectDiff(): boolean {
373    let indexerAlignEQ = isBaseOrResourceEqual(this.stageValue.indexerAlign, this.value.indexerAlign);
374    let offsetEQ = isBaseOrResourceEqual(this.stageValue.offset, this.value.offset);
375    return !indexerAlignEQ || !offsetEQ;
376  }
377}
378
379class UsingPopupModifier extends ModifierWithKey<boolean> {
380  static identity = Symbol('usingPopup');
381  applyPeer(node: KNode, reset: boolean): void {
382    if (reset) {
383      getUINativeModule().alphabetIndexer.resetUsingPopup(node);
384    } else {
385      getUINativeModule().alphabetIndexer.setUsingPopup(node, this.value);
386    }
387  }
388}
389
390class AlphabetIndexerSelectedModifier extends ModifierWithKey<number> {
391  static identity = Symbol('alphabetIndexerSelected');
392  applyPeer(node: KNode, reset: boolean): void {
393    if (reset) {
394      getUINativeModule().alphabetIndexer.resetSelected(node);
395    } else {
396      getUINativeModule().alphabetIndexer.setSelected(node, this.value);
397    }
398  }
399}
400
401class ItemSizeModifier extends ModifierWithKey<number | string> {
402  static identity: Symbol = Symbol('itemSize');
403  applyPeer(node: KNode, reset: boolean): void {
404    if (reset) {
405      getUINativeModule().alphabetIndexer.resetItemSize(node);
406    } else {
407      getUINativeModule().alphabetIndexer.setItemSize(node, this.value);
408    }
409  }
410}
411
412class PopupPositionModifier extends ModifierWithKey<Position> {
413  static identity: Symbol = Symbol('popupPosition');
414  applyPeer(node: KNode, reset: boolean): void {
415    if (reset) {
416      getUINativeModule().alphabetIndexer.resetPopupPosition(node);
417    } else {
418      getUINativeModule().alphabetIndexer.setPopupPosition(node, this.value.x, this.value.y);
419    }
420  }
421
422  checkObjectDiff(): boolean {
423    let xEQ = isBaseOrResourceEqual(this.stageValue.x, this.value.x);
424    let yEQ = isBaseOrResourceEqual(this.stageValue.y, this.value.y);
425    return !xEQ || !yEQ;
426  }
427}
428
429class PopupItemBorderRadiusModifier extends ModifierWithKey<number> {
430  constructor(value: number) {
431    super(value);
432  }
433  static identity: Symbol = Symbol('popupItemBorderRadius');
434  applyPeer(node: KNode, reset: boolean): void {
435    if (reset) {
436      getUINativeModule().alphabetIndexer.resetPopupItemBorderRadius(node);
437    } else {
438      getUINativeModule().alphabetIndexer.setPopupItemBorderRadius(node, this.value);
439    }
440  }
441}
442
443class ItemBorderRadiusModifier extends ModifierWithKey<number> {
444  constructor(value: number) {
445    super(value);
446  }
447  static identity: Symbol = Symbol('itemBorderRadius');
448  applyPeer(node: KNode, reset: boolean): void {
449    if (reset) {
450      getUINativeModule().alphabetIndexer.resetItemBorderRadius(node);
451    } else {
452      getUINativeModule().alphabetIndexer.setItemBorderRadius(node, this.value);
453    }
454  }
455}
456
457class PopupBackgroundBlurStyleModifier extends ModifierWithKey<BlurStyle> {
458  constructor(value: BlurStyle) {
459    super(value);
460  }
461  static identity: Symbol = Symbol('popupBackgroundBlurStyle');
462  applyPeer(node: KNode, reset: boolean): void {
463    if (reset) {
464      getUINativeModule().alphabetIndexer.resetPopupBackgroundBlurStyle(node);
465    } else {
466      getUINativeModule().alphabetIndexer.setPopupBackgroundBlurStyle(node, this.value);
467    }
468  }
469}
470
471class PopupTitleBackgroundModifier extends ModifierWithKey<ResourceColor> {
472  constructor(value: ResourceColor) {
473    super(value);
474  }
475  static identity: Symbol = Symbol('popupTitleBackground');
476  applyPeer(node: KNode, reset: boolean): void {
477    if (reset) {
478      getUINativeModule().alphabetIndexer.resetPopupTitleBackground(node);
479    } else {
480      getUINativeModule().alphabetIndexer.setPopupTitleBackground(node, this.value);
481    }
482  }
483}
484
485class AdaptiveWidthModifier extends ModifierWithKey<Length> {
486  constructor(value: Length) {
487    super(value);
488  }
489  static identity: Symbol = Symbol('adaptiveWidth');
490
491  applyPeer(node: KNode, reset: boolean): void {
492    if (reset) {
493      getUINativeModule().alphabetIndexer.resetAdaptiveWidth(node);
494    } else {
495      getUINativeModule().alphabetIndexer.setAdaptiveWidth(node, this.value);
496    }
497  }
498}
499
500class AutoCollapseModifier extends ModifierWithKey<boolean> {
501  constructor(value: boolean) {
502    super(value);
503  }
504  static identity = Symbol('autoCollapse');
505  applyPeer(node: KNode, reset: boolean): void {
506    if (reset) {
507      getUINativeModule().alphabetIndexer.resetAutoCollapse(node);
508    } else {
509      getUINativeModule().alphabetIndexer.setAutoCollapse(node, this.value);
510    }
511  }
512
513  checkObjectDiff(): boolean {
514    return !isBaseOrResourceEqual(this.stageValue, this.value);
515  }
516}
517
518class EnableHapticFeedbackModifier extends ModifierWithKey<boolean> {
519  constructor(value: boolean) {
520    super(value);
521  }
522  static identity = Symbol('enableHapticFeedback');
523  applyPeer(node: KNode, reset: boolean): void {
524    if (reset) {
525      getUINativeModule().alphabetIndexer.resetEnableHapticFeedback(node);
526    } else {
527      getUINativeModule().alphabetIndexer.setEnableHapticFeedback(node, this.value);
528    }
529  }
530
531  checkObjectDiff(): boolean {
532    return !isBaseOrResourceEqual(this.stageValue, this.value);
533  }
534}