• 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) {
19    super(nativePtr);
20  }
21  onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this {
22    throw new Error('Method not implemented.');
23  }
24  loop(value: boolean): this {
25    throw new Error('Method not implemented.');
26  }
27  useMilitaryTime(value: boolean): this {
28    modifierWithKey(this._modifiersWithKeys, TimepickerUseMilitaryTimeModifier.identity,
29      TimepickerUseMilitaryTimeModifier, value);
30    return this;
31  }
32  disappearTextStyle(value: PickerTextStyle): this {
33    modifierWithKey(this._modifiersWithKeys, TimepickerDisappearTextStyleModifier.identity,
34      TimepickerDisappearTextStyleModifier, value);
35    return this;
36  }
37  textStyle(value: PickerTextStyle): this {
38    modifierWithKey(this._modifiersWithKeys, TimepickerTextStyleModifier.identity,
39      TimepickerTextStyleModifier, value);
40    return this;
41  }
42  selectedTextStyle(value: PickerTextStyle): this {
43    modifierWithKey(this._modifiersWithKeys, TimepickerSelectedTextStyleModifier.identity,
44      TimepickerSelectedTextStyleModifier, value);
45    return this;
46  }
47  onChange(callback: (value: TimePickerResult) => void): this {
48    throw new Error('Method not implemented.');
49  }
50}
51
52class TimepickerTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
53  constructor(value: PickerTextStyle) {
54    super(value);
55  }
56  static identity: Symbol = Symbol('textStyle');
57
58  applyPeer(node: KNode, reset: boolean): void {
59    if (reset) {
60      getUINativeModule().timepicker.resetTextStyle(node);
61    } else {
62      getUINativeModule().timepicker.setTextStyle(node, this.value?.color ?? undefined,
63        this.value?.font?.size ?? undefined,
64        this.value?.font?.weight ?? undefined,
65        this.value?.font?.family ?? undefined,
66        this.value?.font?.style ?? undefined);
67    }
68  }
69
70  checkObjectDiff(): boolean {
71    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
72      this.stageValue?.font?.style === this.value?.font?.style)) {
73      return true;
74    } else {
75      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
76        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
77        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
78    }
79  }
80}
81
82class TimepickerSelectedTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
83  constructor(value: PickerTextStyle) {
84    super(value);
85  }
86  static identity: Symbol = Symbol('selectedTextStyle');
87
88  applyPeer(node: KNode, reset: boolean): void {
89    if (reset) {
90      getUINativeModule().timepicker.resetSelectedTextStyle(node);
91    } else {
92      getUINativeModule().timepicker.setSelectedTextStyle(node, this.value?.color ?? undefined,
93        this.value?.font?.size ?? undefined,
94        this.value?.font?.weight ?? undefined,
95        this.value?.font?.family ?? undefined,
96        this.value?.font?.style ?? undefined);
97    }
98  }
99
100  checkObjectDiff(): boolean {
101    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
102      this.stageValue?.font?.style === this.value?.font?.style)) {
103      return true;
104    } else {
105      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
106        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
107        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
108    }
109  }
110}
111
112class TimepickerDisappearTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
113  constructor(value: PickerTextStyle) {
114    super(value);
115  }
116  static identity: Symbol = Symbol('disappearTextStyle');
117
118  applyPeer(node: KNode, reset: boolean): void {
119    if (reset) {
120      getUINativeModule().timepicker.resetDisappearTextStyle(node);
121    } else {
122      getUINativeModule().timepicker.setDisappearTextStyle(node, this.value?.color ?? undefined,
123        this.value?.font?.size ?? undefined,
124        this.value?.font?.weight ?? undefined,
125        this.value?.font?.family ?? undefined,
126        this.value?.font?.style ?? undefined);
127    }
128  }
129
130  checkObjectDiff(): boolean {
131    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
132      this.stageValue?.font?.style === this.value?.font?.style)) {
133      return true;
134    } else {
135      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
136        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
137        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
138    }
139  }
140}
141
142class TimepickerUseMilitaryTimeModifier extends ModifierWithKey<boolean> {
143  constructor(value: boolean) {
144    super(value);
145  }
146  static identity: Symbol = Symbol('timepickerUseMilitaryTime');
147  applyPeer(node: KNode, reset: boolean): void {
148    if (reset) {
149      getUINativeModule().timepicker.resetTimepickerUseMilitaryTime(node);
150    } else {
151      getUINativeModule().timepicker.setTimepickerUseMilitaryTime(node, this.value);
152    }
153  }
154}
155
156// @ts-ignore
157globalThis.TimePicker.attributeModifier = function (modifier) {
158  const elmtId = ViewStackProcessor.GetElmtIdToAccountFor();
159  let nativeNode = getUINativeModule().getFrameNodeById(elmtId);
160  let component = this.createOrGetNode(elmtId, () => {
161    return new ArkTimePickerComponent(nativeNode);
162  });
163  applyUIAttributes(modifier, nativeNode, component);
164  component.applyModifierPatch();
165};
166