• 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) {
19    super(nativePtr);
20  }
21  lunar(value: boolean): DatePickerAttribute {
22    modifierWithKey(this._modifiersWithKeys, DatePickerLunarModifier.identity, DatePickerLunarModifier, value);
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 ModifierWithKey<boolean> {
53  constructor(value: boolean) {
54    super(value);
55  }
56  static identity: Symbol = Symbol('lunar');
57  applyPeer(node: KNode, reset: boolean) {
58    if (reset) {
59      getUINativeModule().datePicker.resetLunar(node);
60    } else {
61      getUINativeModule().datePicker.setLunar(node, this.value);
62    }
63  }
64}
65
66class DatePickerTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
67  constructor(value: PickerTextStyle) {
68    super(value);
69  }
70  static identity: Symbol = Symbol('textStyle');
71  applyPeer(node: KNode, reset: boolean) {
72    if (reset) {
73      getUINativeModule().datePicker.resetTextStyle(node);
74    } else {
75      getUINativeModule().datePicker.setTextStyle(node, this.value?.color ?? undefined,
76        this.value?.font?.size ?? undefined,
77        this.value?.font?.weight ?? undefined,
78        this.value?.font?.family ?? undefined,
79        this.value?.font?.style ?? undefined);
80    }
81  }
82
83  checkObjectDiff(): boolean {
84    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
85      this.stageValue?.font?.style === this.value?.font?.style)) {
86      return true;
87    } else {
88      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
89        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
90        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
91    }
92  }
93}
94
95class DatePickerSelectedTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
96  constructor(value: PickerTextStyle) {
97    super(value);
98  }
99  static identity: Symbol = Symbol('selectedTextStyle');
100  applyPeer(node: KNode, reset: boolean) {
101    if (reset) {
102      getUINativeModule().datePicker.resetSelectedTextStyle(node);
103    } else {
104      getUINativeModule().datePicker.setSelectedTextStyle(node, this.value?.color ?? undefined,
105        this.value?.font?.size ?? undefined,
106        this.value?.font?.weight ?? undefined,
107        this.value?.font?.family ?? undefined,
108        this.value?.font?.style ?? undefined);
109    }
110  }
111
112  checkObjectDiff(): boolean {
113    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
114      this.stageValue?.font?.style === this.value?.font?.style)) {
115      return true;
116    } else {
117      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
118        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
119        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
120    }
121  }
122}
123
124class DatePickerDisappearTextStyleModifier extends ModifierWithKey<PickerTextStyle> {
125  constructor(value: PickerTextStyle) {
126    super(value);
127  }
128  static identity: Symbol = Symbol('disappearTextStyle');
129  applyPeer(node: KNode, reset: boolean) {
130    if (reset) {
131      getUINativeModule().datePicker.resetDisappearTextStyle(node);
132    } else {
133      getUINativeModule().datePicker.setDisappearTextStyle(node, this.value?.color ?? undefined,
134        this.value?.font?.size ?? undefined,
135        this.value?.font?.weight ?? undefined,
136        this.value?.font?.family ?? undefined,
137        this.value?.font?.style ?? undefined);
138    }
139  }
140
141  checkObjectDiff(): boolean {
142    if (!(this.stageValue?.font?.weight === this.value?.font?.weight &&
143      this.stageValue?.font?.style === this.value?.font?.style)) {
144      return true;
145    } else {
146      return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) ||
147        !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) ||
148        !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family);
149    }
150  }
151}
152
153class DatePickerBackgroundColorModifier extends ModifierWithKey<ResourceColor> {
154  constructor(value: ResourceColor) {
155    super(value);
156  }
157  static identity: Symbol = Symbol('datePickerBackgroundColor');
158  applyPeer(node: KNode, reset: boolean): void {
159    if (reset) {
160      getUINativeModule().datePicker.resetBackgroundColor(node);
161    } else {
162      getUINativeModule().datePicker.setBackgroundColor(node, this.value);
163    }
164  }
165
166  checkObjectDiff(): boolean {
167    return !isBaseOrResourceEqual(this.stageValue, this.value);
168  }
169}
170
171//@ts-ignore
172globalThis.DatePicker.attributeModifier = function (modifier) {
173  const elmtId = ViewStackProcessor.GetElmtIdToAccountFor();
174  let nativeNode = getUINativeModule().getFrameNodeById(elmtId);
175  let component = this.createOrGetNode(elmtId, () => {
176    return new ArkDatePickerComponent(nativeNode);
177  });
178  applyUIAttributes(modifier, nativeNode, component);
179  component.applyModifierPatch();
180};
181