• 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 ArkTimePickerComponent extends ArkComponent implements TimePickerAttribute {
18  constructor(nativePtr: KNode, classType?: ModifierType) {
19    super(nativePtr, classType);
20  }
21  loop(value: boolean): this {
22    modifierWithKey(this._modifiersWithKeys, TimepickerLoopModifier.identity, TimepickerLoopModifier, value);
23    return this;
24  }
25  digitalCrownSensitivity(value: Optional<CrownSensitivity>): this {
26    modifierWithKey(this._modifiersWithKeys, TimepickerDigitalCrownSensitivityModifier.identity, TimepickerDigitalCrownSensitivityModifier, value);
27    return this;
28  }
29  useMilitaryTime(value: boolean): this {
30    modifierWithKey(this._modifiersWithKeys, TimepickerUseMilitaryTimeModifier.identity,
31      TimepickerUseMilitaryTimeModifier, value);
32    return this;
33  }
34  disappearTextStyle(value: PickerTextStyle): this {
35    modifierWithKey(this._modifiersWithKeys, TimepickerDisappearTextStyleModifier.identity,
36      TimepickerDisappearTextStyleModifier, value);
37    return this;
38  }
39  textStyle(value: PickerTextStyle): this {
40    modifierWithKey(this._modifiersWithKeys, TimepickerTextStyleModifier.identity,
41      TimepickerTextStyleModifier, value);
42    return this;
43  }
44  selectedTextStyle(value: PickerTextStyle): this {
45    modifierWithKey(this._modifiersWithKeys, TimepickerSelectedTextStyleModifier.identity,
46      TimepickerSelectedTextStyleModifier, value);
47    return this;
48  }
49  onChange(callback: (value: TimePickerResult) => void): this {
50    modifierWithKey(this._modifiersWithKeys,TimepickerOnChangeModifier.identity,
51      TimepickerOnChangeModifier,callback);
52    return this;
53  }
54  dateTimeOptions(value: DateTimeOptions): this {
55    modifierWithKey(this._modifiersWithKeys, TimepickerDateTimeOptionsModifier.identity,
56      TimepickerDateTimeOptionsModifier, value);
57    return this;
58  }
59  enableHapticFeedback(value: boolean): this {
60    modifierWithKey(this._modifiersWithKeys, TimepickerEnableHapticFeedbackModifier.identity, TimepickerEnableHapticFeedbackModifier, value);
61    return this;
62  }
63  enableCascade(value: boolean): this {
64    modifierWithKey(this._modifiersWithKeys, TimepickerEnableCascadeModifier.identity,
65      TimepickerEnableCascadeModifier, value);
66    return this;
67  }
68}
69
70class TimepickerTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
71  constructor(value: PickerTextStyle) {
72    super(value);
73  }
74  static identity: Symbol = Symbol('textStyle');
75
76  applyPeer(node: KNode, reset: boolean): void {
77    if (reset) {
78      getUINativeModule().timepicker.resetTextStyle(node);
79    } else {
80      getUINativeModule().timepicker.setTextStyle(node, this.value?.color ?? undefined,
81        this.value?.font?.size ?? undefined,
82        this.value?.font?.weight ?? undefined,
83        this.value?.font?.family ?? undefined,
84        this.value?.font?.style ?? undefined);
85    }
86  }
87
88  checkObjectDiff(): boolean {
89    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
90      this.stageValue?.font?.style === this.value?.font?.style)) {
91      return true;
92    } else {
93      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
94        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
95        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
96    }
97  }
98}
99
100class TimepickerSelectedTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
101  constructor(value: PickerTextStyle) {
102    super(value);
103  }
104  static identity: Symbol = Symbol('selectedTextStyle');
105
106  applyPeer(node: KNode, reset: boolean): void {
107    if (reset) {
108      getUINativeModule().timepicker.resetSelectedTextStyle(node);
109    } else {
110      getUINativeModule().timepicker.setSelectedTextStyle(node, this.value?.color ?? undefined,
111        this.value?.font?.size ?? undefined,
112        this.value?.font?.weight ?? undefined,
113        this.value?.font?.family ?? undefined,
114        this.value?.font?.style ?? undefined);
115    }
116  }
117
118  checkObjectDiff(): boolean {
119    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
120      this.stageValue?.font?.style === this.value?.font?.style)) {
121      return true;
122    } else {
123      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
124        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
125        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
126    }
127  }
128}
129
130class TimepickerDisappearTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
131  constructor(value: PickerTextStyle) {
132    super(value);
133  }
134  static identity: Symbol = Symbol('disappearTextStyle');
135
136  applyPeer(node: KNode, reset: boolean): void {
137    if (reset) {
138      getUINativeModule().timepicker.resetDisappearTextStyle(node);
139    } else {
140      getUINativeModule().timepicker.setDisappearTextStyle(node, this.value?.color ?? undefined,
141        this.value?.font?.size ?? undefined,
142        this.value?.font?.weight ?? undefined,
143        this.value?.font?.family ?? undefined,
144        this.value?.font?.style ?? undefined);
145    }
146  }
147
148  checkObjectDiff(): boolean {
149    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
150      this.stageValue?.font?.style === this.value?.font?.style)) {
151      return true;
152    } else {
153      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
154        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
155        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
156    }
157  }
158}
159
160class TimepickerUseMilitaryTimeModifier extends ModifierWithKey<boolean> {
161  constructor(value: boolean) {
162    super(value);
163  }
164  static identity: Symbol = Symbol('timepickerUseMilitaryTime');
165  applyPeer(node: KNode, reset: boolean): void {
166    if (reset) {
167      getUINativeModule().timepicker.resetTimepickerUseMilitaryTime(node);
168    } else {
169      getUINativeModule().timepicker.setTimepickerUseMilitaryTime(node, this.value);
170    }
171  }
172}
173
174class TimepickerLoopModifier extends ModifierWithKey<boolean> {
175  constructor(value: boolean) {
176    super(value);
177  }
178  static identity: Symbol = Symbol('timepickerLoop');
179  applyPeer(node: KNode, reset: boolean): void {
180    if (reset) {
181      getUINativeModule().timepicker.resetTimepickerLoop(node);
182    } else {
183      getUINativeModule().timepicker.setTimepickerLoop(node, this.value);
184    }
185  }
186}
187
188class TimepickerDigitalCrownSensitivityModifier extends ModifierWithKey<Optional<CrownSensitivity>> {
189  constructor(value: Optional<CrownSensitivity>) {
190    super(value);
191  }
192  static identity: Symbol = Symbol('timepickerDigitalCrownSensitivity');
193  applyPeer(node: KNode, reset: boolean): void {
194    if (reset) {
195      getUINativeModule().timepicker.resetTimepickerDigitalCrownSensitivity(node);
196    } else {
197      getUINativeModule().timepicker.setTimepickerDigitalCrownSensitivity(node, this.value);
198    }
199  }
200}
201
202class TimepickerDateTimeOptionsModifier extends ModifierWithKey<DateTimeOptions> {
203  constructor(value: DateTimeOptions) {
204    super(value);
205  }
206  static identity: Symbol = Symbol('timepickerDateTimeOptions');
207  applyPeer(node: KNode, reset: boolean): void {
208    if (reset) {
209      getUINativeModule().timepicker.resetTimepickerDateTimeOptions(node);
210    } else {
211      getUINativeModule().timepicker.setTimepickerDateTimeOptions(node, this.value.hour, this.value.minute, this.value.second);
212    }
213  }
214}
215
216class TimepickerEnableHapticFeedbackModifier extends ModifierWithKey<boolean> {
217  constructor(value: boolean) {
218    super(value);
219  }
220  static identity: Symbol = Symbol('timepickerEnableHapticFeedback');
221  applyPeer(node: KNode, reset: boolean): void {
222    if (reset) {
223      getUINativeModule().timepicker.resetTimepickerEnableHapticFeedback(node);
224    } else {
225      getUINativeModule().timepicker.setTimepickerEnableHapticFeedback(node, this.value);
226    }
227  }
228}
229
230class TimepickerEnableCascadeModifier extends ModifierWithKey<boolean> {
231  constructor(value: boolean) {
232    super(value);
233  }
234  static identity: Symbol = Symbol('timepickerEnableCascade');
235  applyPeer(node: KNode, reset: boolean): void {
236    if (reset) {
237      getUINativeModule().timepicker.resetTimepickerEnableCascade(node);
238    } else {
239      getUINativeModule().timepicker.setTimepickerEnableCascade(node, this.value);
240    }
241  }
242}
243
244class TimepickerOnChangeModifier extends ModifierWithKey<(value:TimePickerResult)=> void>
245{
246  constructor(value: (value: TimePickerResult) => void) {
247    super(value);
248  }
249  static identity: Symbol = Symbol('timePickerOnChange');
250  applyPeer(node: KNode, reset: boolean): void {
251    if (reset) {
252      getUINativeModule().timepicker.resetTimepickerOnChange(node);
253    } else {
254      getUINativeModule().timepicker.setTimepickerOnChange(node, this.value);
255    }
256  }
257}
258// @ts-ignore
259globalThis.TimePicker.attributeModifier = function (modifier: ArkComponent): void {
260  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
261    return new ArkTimePickerComponent(nativePtr);
262  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
263    return new modifierJS.TimePickerModifier(nativePtr, classType);
264  });
265};
266