• 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 ArkTextPickerComponent extends ArkComponent implements TextPickerAttribute {
18  constructor(nativePtr: KNode, classType?: ModifierType) {
19    super(nativePtr, classType);
20  }
21  defaultPickerItemHeight(value: string | number): this {
22    modifierWithKey(
23      this._modifiersWithKeys, TextpickerDefaultPickerItemHeightModifier.identity, TextpickerDefaultPickerItemHeightModifier, value);
24    return this;
25  }
26  canLoop(value: boolean): this {
27    modifierWithKey(
28      this._modifiersWithKeys, TextpickerCanLoopModifier.identity, TextpickerCanLoopModifier, value);
29    return this;
30  }
31  disappearTextStyle(value: PickerTextStyle): this {
32    modifierWithKey(
33      this._modifiersWithKeys, TextpickerDisappearTextStyleModifier.identity, TextpickerDisappearTextStyleModifier, value);
34    return this;
35  }
36  textStyle(value: PickerTextStyle): this {
37    modifierWithKey(
38      this._modifiersWithKeys, TextpickerTextStyleModifier.identity, TextpickerTextStyleModifier, value);
39    return this;
40  }
41  selectedTextStyle(value: PickerTextStyle): this {
42    modifierWithKey(
43      this._modifiersWithKeys, TextpickerSelectedTextStyleModifier.identity, TextpickerSelectedTextStyleModifier, value);
44    return this;
45  }
46  onAccept(callback: (value: string, index: number) => void): this {
47    throw new Error('Method not implemented.');
48  }
49  onCancel(callback: () => void): this {
50    throw new Error('Method not implemented.');
51  }
52  onChange(callback: Optional<OnTextPickerChangeCallback>): this {
53    modifierWithKey(
54      this._modifiersWithKeys, TextpickerOnChangeModifier.identity, TextpickerOnChangeModifier, callback);
55    return this;
56  }
57  selectedIndex(value: number | number[]): this {
58    modifierWithKey(
59      this._modifiersWithKeys, TextpickerSelectedIndexModifier.identity, TextpickerSelectedIndexModifier, value);
60    return this;
61  }
62  divider(value: DividerOptions | null): this {
63    modifierWithKey(
64      this._modifiersWithKeys, TextpickerDividerModifier.identity, TextpickerDividerModifier, value);
65    return this;
66  }
67  gradientHeight(value: Dimension): this {
68    modifierWithKey(
69      this._modifiersWithKeys, TextpickerGradientHeightModifier.identity, TextpickerGradientHeightModifier, value);
70    return this;
71  }
72  disableTextStyleAnimation(value: boolean): this {
73    modifierWithKey(
74      this._modifiersWithKeys, TextpickerDisableTextStyleAnimationModifier.identity, TextpickerDisableTextStyleAnimationModifier, value);
75    return this;
76  }
77  defaultTextStyle(value: PickerTextStyle): this {
78    modifierWithKey(
79      this._modifiersWithKeys, TextpickerDefaultTextStyleModifier.identity, TextpickerDefaultTextStyleModifier, value);
80    return this;
81  }
82
83  enableHapticFeedback(value: boolean): this {
84    modifierWithKey(this._modifiersWithKeys, TextpickerEnableHapticFeedbackModifier.identity, TextpickerEnableHapticFeedbackModifier, value);
85    return this;
86  }
87
88  digitalCrownSensitivity(sensitivity: Optional<CrownSensitivity>): this {
89    modifierWithKey(
90      this._modifiersWithKeys, TextpickerDigitalCrownSensitivityModifier.identity, TextpickerDigitalCrownSensitivityModifier, value);
91    return this;
92  }
93  onScrollStop(callback: (value: string | string[], index: number | number[]) => void) : this{
94    modifierWithKey(
95      this._modifiersWithKeys,TextpickerOnScrollStopModifier.identity,TextpickerOnScrollStopModifier,callback);
96    return this;
97  }
98}
99
100class TextpickerCanLoopModifier extends ModifierWithKey<boolean> {
101  constructor(value: boolean) {
102    super(value);
103  }
104  static identity: Symbol = Symbol('textpickerCanLoop');
105  applyPeer(node: KNode, reset: boolean): void {
106    if (reset) {
107      getUINativeModule().textpicker.resetCanLoop(node);
108    } else {
109      getUINativeModule().textpicker.setCanLoop(node, this.value);
110    }
111  }
112}
113
114class TextpickerDigitalCrownSensitivityModifier extends ModifierWithKey<Optional<CrownSensitivity>> {
115  constructor(value: Optional<CrownSensitivity>) {
116    super(value);
117  }
118  static identity: Symbol = Symbol('textpickerDigitalCrownSensitivity');
119  applyPeer(node: KNode, reset: boolean): void {
120    if (reset) {
121      getUINativeModule().textpicker.resetDigitalCrownSensitivity(node);
122    } else {
123      getUINativeModule().textpicker.setDigitalCrownSensitivity(node, this.value);
124    }
125  }
126}
127
128class TextpickerSelectedIndexModifier extends ModifierWithKey<number | number[]> {
129  constructor(value: number | number[]) {
130    super(value);
131  }
132  static identity: Symbol = Symbol('textpickerSelectedIndex');
133  applyPeer(node: KNode, reset: boolean): void {
134    if (reset) {
135      getUINativeModule().textpicker.resetSelectedIndex(node);
136    } else {
137      getUINativeModule().textpicker.setSelectedIndex(node, this.value);
138    }
139  }
140
141  checkObjectDiff(): boolean {
142    if (Array.isArray(this.stageValue) && Array.isArray(this.value)) {
143      return !deepCompareArrays(this.stageValue, this.value);
144    } else if (Array.isArray(this.stageValue) || Array.isArray(this.value)) {
145      return true;
146    } else {
147      return this.stageValue !== this.value;
148    }
149  }
150
151}
152
153class TextpickerDividerModifier extends ModifierWithKey<DividerOptions | null> {
154  constructor(value: DividerOptions | null) {
155    super(value);
156  }
157  static identity: Symbol = Symbol('textpickerDivider');
158  applyPeer(node: KNode, reset: boolean): void {
159    if (reset) {
160      getUINativeModule().textpicker.resetDivider(node, this.value);
161    } else {
162      getUINativeModule().textpicker.setDivider(node, this.value?.strokeWidth, this.value?.color, this.value?.startMargin, this.value?.endMargin);
163    }
164  }
165
166  checkObjectDiff(): boolean {
167    return !(this.stageValue?.strokeWidth === this.value?.strokeWidth &&
168      this.stageValue?.color === this.value?.color &&
169      this.stageValue?.startMargin === this.value?.startMargin &&
170      this.stageValue?.endMargin === this.value?.endMargin);
171  }
172}
173
174class TextpickerGradientHeightModifier extends ModifierWithKey<Dimension> {
175  constructor(value: Dimension) {
176    super(value);
177  }
178  static identity: Symbol = Symbol('textpickerGradientHeight');
179  applyPeer(node: KNode, reset: boolean): void {
180    if (reset) {
181      getUINativeModule().textpicker.resetGradientHeight(node);
182    } else {
183      getUINativeModule().textpicker.setGradientHeight(node, this.value);
184    }
185  }
186  checkObjectDiff(): boolean {
187    return !isBaseOrResourceEqual(this.stageValue, this.value);
188  }
189}
190
191class TextpickerDisableTextStyleAnimationModifier extends ModifierWithKey<boolean> {
192  constructor(value: boolean) {
193    super(value);
194  }
195  static identity: Symbol = Symbol('textpickerDisableTextStyleAnimation');
196  applyPeer(node: KNode, reset: boolean): void {
197    if (reset) {
198      getUINativeModule().textpicker.resetDisableTextStyleAnimation(node);
199    } else {
200      getUINativeModule().textpicker.setDisableTextStyleAnimation(node, this.value);
201    }
202  }
203}
204
205class TextpickerDefaultTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
206  constructor(value: PickerTextStyle) {
207    super(value);
208  }
209  static identity: Symbol = Symbol('textpickerDefaultTextStyle');
210  applyPeer(node: KNode, reset: boolean): void {
211    if (reset) {
212      getUINativeModule().textpicker.resetDefaultTextStyle(node);
213    } else {
214      getUINativeModule().textpicker.setDefaultTextStyle(node, this.value?.color ?? undefined,
215        this.value?.font?.size ?? undefined,
216        this.value?.font?.weight ?? undefined,
217        this.value?.font?.family ?? undefined,
218        this.value?.font?.style ?? undefined,
219        this.value?.minFontSize ?? undefined,
220        this.value?.maxFontSize ?? undefined,
221        this.value?.overflow ?? undefined);
222    }
223  }
224
225  checkObjectDiff(): boolean {
226    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
227      this.stageValue?.font?.style === this.value?.font?.style &&
228      this.stageValue?.overflow === this.value?.overflow)) {
229      return true;
230    } else {
231      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
232        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
233        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family) ||
234        !isBaseOrResourceEqual(this.stageValue?.minFontSize, this.value?.minFontSize) ||
235        !isBaseOrResourceEqual(this.stageValue?.maxFontSize, this.value?.maxFontSize);
236    }
237  }
238}
239
240class TextpickerTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
241  constructor(value: PickerTextStyle) {
242    super(value);
243  }
244  static identity: Symbol = Symbol('textpickerTextStyle');
245  applyPeer(node: KNode, reset: boolean): void {
246    if (reset) {
247      getUINativeModule().textpicker.resetTextStyle(node);
248    } else {
249      getUINativeModule().textpicker.setTextStyle(node, this.value?.color ?? undefined,
250        this.value?.font?.size ?? undefined,
251        this.value?.font?.weight ?? undefined,
252        this.value?.font?.family ?? undefined,
253        this.value?.font?.style ?? undefined);
254    }
255  }
256
257  checkObjectDiff(): boolean {
258    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
259      this.stageValue?.font?.style === this.value?.font?.style)) {
260      return true;
261    } else {
262      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
263        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
264        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
265    }
266  }
267}
268
269class TextpickerSelectedTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
270  constructor(value: PickerTextStyle) {
271    super(value);
272  }
273  static identity: Symbol = Symbol('textpickerSelectedTextStyle');
274  applyPeer(node: KNode, reset: boolean): void {
275    if (reset) {
276      getUINativeModule().textpicker.resetSelectedTextStyle(node);
277    } else {
278      getUINativeModule().textpicker.setSelectedTextStyle(node, this.value?.color ?? undefined,
279        this.value?.font?.size ?? undefined,
280        this.value?.font?.weight ?? undefined,
281        this.value?.font?.family ?? undefined,
282        this.value?.font?.style ?? undefined);
283    }
284  }
285
286  checkObjectDiff(): boolean {
287    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
288      this.stageValue?.font?.style === this.value?.font?.style)) {
289      return true;
290    } else {
291      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
292        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
293        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
294    }
295  }
296}
297
298class TextpickerDisappearTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
299  constructor(value: PickerTextStyle) {
300    super(value);
301  }
302  static identity: Symbol = Symbol('textpickerDisappearTextStyle');
303  applyPeer(node: KNode, reset: boolean): void {
304    if (reset) {
305      getUINativeModule().textpicker.resetDisappearTextStyle(node);
306    } else {
307      getUINativeModule().textpicker.setDisappearTextStyle(node, this.value?.color ?? undefined,
308        this.value?.font?.size ?? undefined,
309        this.value?.font?.weight ?? undefined,
310        this.value?.font?.family ?? undefined,
311        this.value?.font?.style ?? undefined);
312    }
313  }
314
315  checkObjectDiff(): boolean {
316    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
317      this.stageValue?.font?.style === this.value?.font?.style)) {
318      return true;
319    } else {
320      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
321        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
322        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
323    }
324  }
325}
326
327class TextpickerDefaultPickerItemHeightModifier extends ModifierWithKey<number | string> {
328  constructor(value: number | string) {
329    super(value);
330  }
331  static identity: Symbol = Symbol('textpickerDefaultPickerItemHeight');
332  applyPeer(node: KNode, reset: boolean): void {
333    if (reset) {
334      getUINativeModule().textpicker.resetDefaultPickerItemHeight(node);
335    } else {
336      getUINativeModule().textpicker.setDefaultPickerItemHeight(node, this.value);
337    }
338  }
339}
340
341class TextpickerEnableHapticFeedbackModifier extends ModifierWithKey<boolean> {
342  constructor(value: boolean) {
343    super(value);
344  }
345  static identity: Symbol = Symbol('textpickerEnableHapticFeedback');
346  applyPeer(node: KNode, reset: boolean): void {
347    if (reset) {
348      getUINativeModule().textpicker.resetTextpickerEnableHapticFeedback(node);
349    } else {
350      getUINativeModule().textpicker.setTextpickerEnableHapticFeedback(node, this.value!);
351    }
352  }
353}
354class TextpickerOnChangeModifier extends ModifierWithKey<Optional<OnTextPickerChangeCallback>>{
355  constructor(value: Optional<OnTextPickerChangeCallback>) {
356    super(value);
357  }
358  static identity: Symbol = Symbol('textpickerOnChange');
359  applyPeer(node: KNode, reset: boolean): void {
360    if (reset) {
361      getUINativeModule().textpicker.resetOnChange(node);
362    } else {
363      getUINativeModule().textpicker.setOnChange(node, this.value);
364    }
365  }
366}
367class TextpickerOnScrollStopModifier extends ModifierWithKey<(value: string | string[], index: number | number[]) => void>{
368  constructor(value:(value: string | string[], index: number | number[]) => void){
369     super(value);
370  }
371  static identity: Symbol = Symbol('textpickerOnScrollStop');
372  applyPeer(node: KNode, reset: boolean): void {
373    if (reset) {
374      getUINativeModule().textpicker.resetOnScrollStop(node);
375    } else {
376      getUINativeModule().textpicker.setOnScrollStop(node, this.value);
377    }
378  }
379}
380// @ts-ignore
381globalThis.TextPicker.attributeModifier = function (modifier: ArkComponent): void {
382  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
383    return new ArkTextPickerComponent(nativePtr);
384  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
385    return new modifierJS.TextPickerModifier(nativePtr, classType);
386  });
387};
388