• 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 ArkDatePickerComponent extends ArkComponent implements DatePickerAttribute {
18  constructor(nativePtr: KNode, classType?: ModifierType) {
19    super(nativePtr, classType);
20  }
21  lunar(value: boolean): DatePickerAttribute {
22    modifier(this._modifiers, DatePickerLunarModifier, isBoolean(value) ? value : false);
23    return this;
24  }
25  disappearTextStyle(value: PickerTextStyle): DatePickerAttribute {
26    modifierWithKey(this._modifiersWithKeys, DatePickerDisappearTextStyleModifier.identity,
27      DatePickerDisappearTextStyleModifier, value);
28    return this;
29  }
30  textStyle(value: PickerTextStyle): DatePickerAttribute {
31    modifierWithKey(this._modifiersWithKeys, DatePickerTextStyleModifier.identity,
32      DatePickerTextStyleModifier, value);
33    return this;
34  }
35  selectedTextStyle(value: PickerTextStyle): DatePickerAttribute {
36    modifierWithKey(this._modifiersWithKeys, DatePickerSelectedTextStyleModifier.identity,
37      DatePickerSelectedTextStyleModifier, value);
38    return this;
39  }
40  onChange(callback: (value: DatePickerResult) => void): DatePickerAttribute {
41    throw new Error('Method not implemented.');
42  }
43  onDateChange(callback: (value: Date) => void): DatePickerAttribute {
44    throw new Error('Method not implemented.');
45  }
46  backgroundColor(value: ResourceColor): this {
47    modifierWithKey(this._modifiersWithKeys, DatePickerBackgroundColorModifier.identity, DatePickerBackgroundColorModifier, value);
48    return this;
49  }
50}
51
52class DatePickerLunarModifier extends Modifier<boolean> {
53  static identity: Symbol = Symbol('lunar');
54  applyPeer(node: KNode, reset: boolean) {
55    if (reset) {
56      getUINativeModule().datePicker.resetLunar(node);
57    } else {
58      getUINativeModule().datePicker.setLunar(node, this.value);
59    }
60  }
61}
62
63class DatePickerTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
64  static identity: Symbol = Symbol('textStyle');
65  applyPeer(node: KNode, reset: boolean) {
66    if (reset) {
67      getUINativeModule().datePicker.resetTextStyle(node);
68    } else {
69      getUINativeModule().datePicker.setTextStyle(node, this.value?.color ?? undefined,
70        this.value?.font?.size ?? undefined,
71        this.value?.font?.weight ?? undefined,
72        this.value?.font?.family ?? undefined,
73        this.value?.font?.style ?? undefined);
74    }
75  }
76
77  checkObjectDiff(): boolean {
78    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
79      this.stageValue?.font?.style === this.value?.font?.style)) {
80      return true;
81    } else {
82      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
83        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
84        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
85    }
86  }
87}
88
89class DatePickerSelectedTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
90  static identity: Symbol = Symbol('selectedTextStyle');
91  applyPeer(node: KNode, reset: boolean) {
92    if (reset) {
93      getUINativeModule().datePicker.resetSelectedTextStyle(node);
94    } else {
95      getUINativeModule().datePicker.setSelectedTextStyle(node, this.value?.color ?? undefined,
96        this.value?.font?.size ?? undefined,
97        this.value?.font?.weight ?? undefined,
98        this.value?.font?.family ?? undefined,
99        this.value?.font?.style ?? undefined);
100    }
101  }
102
103  checkObjectDiff(): boolean {
104    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
105      this.stageValue?.font?.style === this.value?.font?.style)) {
106      return true;
107    } else {
108      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
109        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
110        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
111    }
112  }
113}
114
115class DatePickerDisappearTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
116  static identity: Symbol = Symbol('disappearTextStyle');
117  applyPeer(node: KNode, reset: boolean) {
118    if (reset) {
119      getUINativeModule().datePicker.resetDisappearTextStyle(node);
120    } else {
121      getUINativeModule().datePicker.setDisappearTextStyle(node, this.value?.color ?? undefined,
122        this.value?.font?.size ?? undefined,
123        this.value?.font?.weight ?? undefined,
124        this.value?.font?.family ?? undefined,
125        this.value?.font?.style ?? undefined);
126    }
127  }
128
129  checkObjectDiff(): boolean {
130    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
131      this.stageValue?.font?.style === this.value?.font?.style)) {
132      return true;
133    } else {
134      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
135        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
136        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
137    }
138  }
139}
140
141class DatePickerBackgroundColorModifier extends ModifierWithKey<ResourceColor> {
142  constructor(value: ResourceColor) {
143    super(value);
144  }
145  static identity: Symbol = Symbol('datePickerBackgroundColor');
146  applyPeer(node: KNode, reset: boolean): void {
147    if (reset) {
148      getUINativeModule().datePicker.resetBackgroundColor(node);
149    } else {
150      getUINativeModule().datePicker.setBackgroundColor(node, this.value);
151    }
152  }
153
154  checkObjectDiff(): boolean {
155    return !isBaseOrResourceEqual(this.stageValue, this.value);
156  }
157}
158
159//@ts-ignore
160globalThis.DatePicker.attributeModifier = function (modifier: ArkComponent): void {
161  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
162    return new ArkDatePickerComponent(nativePtr);
163  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
164    return new modifierJS.DatePickerModifier(nativePtr, classType);
165  });
166};
167