• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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' />
17
18class IndicatorComponentInitialIndexModifier extends ModifierWithKey<number> {
19  constructor(value: number) {
20    super(value);
21  }
22  static identity: Symbol = Symbol('indicatorComponentInitialIndex');
23  applyPeer(node: KNode, reset: boolean): void {
24    if (reset) {
25      getUINativeModule().indicatorComponent.resetInitialIndex(node);
26    } else {
27      getUINativeModule().indicatorComponent.setInitialIndex(node, this.value);
28    }
29  }
30  checkObjectDiff(): boolean {
31    return !isBaseOrResourceEqual(this.stageValue, this.value);
32  }
33}
34
35class IndicatorComponentCountModifier extends ModifierWithKey<number> {
36  constructor(value: number) {
37    super(value);
38  }
39  static identity: Symbol = Symbol('indicatorComponentCount');
40  applyPeer(node: KNode, reset: boolean): void {
41    if (reset) {
42      getUINativeModule().indicatorComponent.resetCount(node);
43    } else {
44      getUINativeModule().indicatorComponent.setCount(node, this.value);
45    }
46  }
47  checkObjectDiff(): boolean {
48    return !isBaseOrResourceEqual(this.stageValue, this.value);
49  }
50}
51
52class IndicatorComponentStyleModifier extends ModifierWithKey<DotIndicator | DigitIndicator> {
53  constructor(value: DotIndicator | DigitIndicator) {
54    super(value);
55  }
56  static identity: Symbol = Symbol('indicatorComponentStyle');
57  applyPeer(node: KNode, reset: boolean): void {
58    if (reset) {
59      getUINativeModule().indicatorComponent.resetStyle(node);
60    } else {
61      let left;
62      let top;
63      let right;
64      let bottom;
65      let itemWidth;
66      let itemHeight;
67      let selectedItemWidth;
68      let selectedItemHeight;
69      let mask;
70      let color;
71      let selectedColor;
72      let maxDisplayCount;
73      let fontColor;
74      let selectedFontColor;
75      let digitFontSize;
76      let digitFontWeight;
77      let selectedDigitFontSize;
78      let selectedDigitFontWeight;
79      if (typeof this.value === 'object' && (this.value as ArkDigitIndicator).type === 'DigitIndicator') {
80        left = (this.value as ArkDigitIndicator).leftValue;
81        top = (this.value as ArkDigitIndicator).topValue;
82        right = (this.value as ArkDigitIndicator).rightValue;
83        bottom = (this.value as ArkDigitIndicator).bottomValue;
84        fontColor = (this.value as ArkDigitIndicator).fontColorValue;
85        selectedFontColor = (this.value as ArkDigitIndicator).selectedFontColorValue;
86        let arkDigitFont = new ArkDigitFont();
87        if (typeof (this.value as ArkDigitIndicator).digitFontValue === 'object') {
88          digitFontSize = ((this.value as ArkDigitIndicator).digitFontValue as Font).size;
89          digitFontWeight = arkDigitFont.parseFontWeight(
90            ((this.value as ArkDigitIndicator).digitFontValue as Font).weight
91          );
92        }
93        if (typeof (this.value as ArkDigitIndicator).selectedDigitFontValue === 'object') {
94          selectedDigitFontSize = ((this.value as ArkDigitIndicator).selectedDigitFontValue as Font).size;
95          selectedDigitFontWeight = arkDigitFont.parseFontWeight(
96            ((this.value as ArkDigitIndicator).selectedDigitFontValue as Font).weight
97          );
98        }
99        getUINativeModule().indicatorComponent.setStyle(
100          node,
101          'ArkDigitIndicator',
102          fontColor,
103          selectedFontColor,
104          digitFontSize,
105          digitFontWeight,
106          selectedDigitFontSize,
107          selectedDigitFontWeight,
108          left,
109          top,
110          right,
111          bottom
112        );
113      } else {
114        left = (this.value as ArkDotIndicator).leftValue;
115        top = (this.value as ArkDotIndicator).topValue;
116        right = (this.value as ArkDotIndicator).rightValue;
117        bottom = (this.value as ArkDotIndicator).bottomValue;
118        itemWidth = (this.value as ArkDotIndicator).itemWidthValue;
119        itemHeight = (this.value as ArkDotIndicator).itemHeightValue;
120        selectedItemWidth = (this.value as ArkDotIndicator).selectedItemWidthValue;
121        selectedItemHeight = (this.value as ArkDotIndicator).selectedItemHeightValue;
122        mask = (this.value as ArkDotIndicator).maskValue;
123        color = (this.value as ArkDotIndicator).colorValue;
124        selectedColor = (this.value as ArkDotIndicator).selectedColorValue;
125        maxDisplayCount = (this.value as ArkDotIndicator).maxDisplayCountValue;
126        getUINativeModule().indicatorComponent.setStyle(
127          node,
128          'ArkDotIndicator',
129          itemWidth,
130          itemHeight,
131          selectedItemWidth,
132          selectedItemHeight,
133          mask,
134          color,
135          selectedColor,
136          maxDisplayCount,
137          left,
138          top,
139          right,
140          bottom
141        );
142      }
143    }
144  }
145  checkObjectDiff(): boolean {
146    if (typeof this.stageValue !== typeof this.value) {
147      return true;
148    }
149    if (this.stageValue instanceof ArkDigitIndicator && this.value instanceof ArkDigitIndicator) {
150      return (
151        !isBaseOrResourceEqual(
152          (this.stageValue as ArkDigitIndicator).fontColorValue,
153          (this.value as ArkDigitIndicator).fontColorValue
154        ) ||
155        !isBaseOrResourceEqual(
156          (this.stageValue as ArkDigitIndicator).selectedFontColorValue,
157          (this.value as ArkDigitIndicator).selectedFontColorValue
158        ) ||
159        !isBaseOrResourceEqual(
160          ((this.stageValue as ArkDigitIndicator).digitFontValue as Font).size,
161          ((this.value as ArkDigitIndicator).digitFontValue as Font).size
162        ) ||
163        !isBaseOrResourceEqual(
164          ((this.stageValue as ArkDigitIndicator).digitFontValue as Font).weight,
165          ((this.value as ArkDigitIndicator).digitFontValue as Font).weight
166        ) ||
167        !isBaseOrResourceEqual(
168          ((this.stageValue as ArkDigitIndicator).selectedDigitFontValue as Font).size,
169          ((this.value as ArkDigitIndicator).selectedDigitFontValue as Font).size
170        ) ||
171        !isBaseOrResourceEqual(
172          ((this.stageValue as ArkDigitIndicator).selectedDigitFontValue as Font).weight,
173          ((this.value as ArkDigitIndicator).selectedDigitFontValue as Font).weight
174        )
175      );
176    } else if (this.stageValue instanceof ArkDotIndicator && this.value instanceof ArkDotIndicator) {
177      return (
178        !isBaseOrResourceEqual(
179          (this.stageValue as ArkDotIndicator).itemWidthValue,
180          (this.value as ArkDotIndicator).itemWidthValue
181        ) ||
182        !isBaseOrResourceEqual(
183          (this.stageValue as ArkDotIndicator).itemHeightValue,
184          (this.value as ArkDotIndicator).itemHeightValue
185        ) ||
186        !isBaseOrResourceEqual(
187          (this.stageValue as ArkDotIndicator).selectedItemWidthValue,
188          (this.value as ArkDotIndicator).selectedItemWidthValue
189        ) ||
190        !isBaseOrResourceEqual(
191          (this.stageValue as ArkDotIndicator).selectedItemHeightValue,
192          (this.value as ArkDotIndicator).selectedItemHeightValue
193        ) ||
194        !isBaseOrResourceEqual(
195          (this.stageValue as ArkDotIndicator).maskValue,
196          (this.value as ArkDotIndicator).maskValue
197        ) ||
198        !isBaseOrResourceEqual(
199          (this.stageValue as ArkDotIndicator).colorValue,
200          (this.value as ArkDotIndicator).colorValue
201        ) ||
202        !isBaseOrResourceEqual(
203          (this.stageValue as ArkDotIndicator).selectedColorValue,
204          (this.value as ArkDotIndicator).selectedColorValue
205        ) ||
206        !isBaseOrResourceEqual(
207          (this.stageValue as ArkDotIndicator).maxDisplayCountValue,
208          (this.value as ArkDotIndicator).maxDisplayCountValue
209        )
210      );
211    } else {
212      return true;
213    }
214  }
215}
216
217class IndicatorComponentLoopModifier extends ModifierWithKey<boolean> {
218  constructor(value: boolean) {
219    super(value);
220  }
221  static identity: Symbol = Symbol('indicatorComponentLoop');
222  applyPeer(node: KNode, reset: boolean): void {
223    if (reset) {
224      getUINativeModule().indicatorComponent.resetLoop(node);
225    } else {
226      getUINativeModule().indicatorComponent.setLoop(node, this.value);
227    }
228  }
229  checkObjectDiff(): boolean {
230    return !isBaseOrResourceEqual(this.stageValue, this.value);
231  }
232}
233
234class IndicatorComponentVerticalModifier extends ModifierWithKey<boolean> {
235  constructor(value: boolean) {
236    super(value);
237  }
238  static identity: Symbol = Symbol('indicatorComponentVertical');
239  applyPeer(node: KNode, reset: boolean): void {
240    if (reset) {
241      getUINativeModule().indicatorComponent.resetVertical(node);
242    } else {
243      getUINativeModule().indicatorComponent.setVertical(node, this.value);
244    }
245  }
246  checkObjectDiff(): boolean {
247    return !isBaseOrResourceEqual(this.stageValue, this.value);
248  }
249}
250
251class IndicatorComponentOnChangeModifier extends ModifierWithKey<Callback<number>> {
252  constructor(value: Callback<number>) {
253    super(value);
254  }
255  static identity: Symbol = Symbol('indicatorComponentOnChange');
256  applyPeer(node: KNode, reset: boolean): void {
257    if (reset) {
258      getUINativeModule().indicatorComponent.resetOnChange(node);
259    } else {
260      getUINativeModule().indicatorComponent.setOnChange(node, this.value);
261    }
262  }
263  checkObjectDiff(): boolean {
264    return !isBaseOrResourceEqual(this.stageValue, this.value);
265  }
266}
267
268class ArkIndicatorComponentComponent extends ArkComponent implements CommonMethod<IndicatorComponentAttribute> {
269  constructor(nativePtr: KNode, classType?: ModifierType) {
270    super(nativePtr, classType);
271  }
272
273  initialIndex(value: number): IndicatorComponentAttribute {
274    modifierWithKey(this._modifiersWithKeys, IndicatorComponentInitialIndexModifier.identity, IndicatorComponentInitialIndexModifier, value);
275    return this;
276  }
277
278  count(value: number): IndicatorComponentAttribute {
279    modifierWithKey(this._modifiersWithKeys, IndicatorComponentCountModifier.identity, IndicatorComponentCountModifier, value);
280    return this;
281  }
282
283  style(value: DotIndicator | DigitIndicator): IndicatorComponentAttribute {
284    modifierWithKey(this._modifiersWithKeys, IndicatorComponentStyleModifier.identity, IndicatorComponentStyleModifier, value);
285    return this;
286  }
287
288  loop(value: boolean): IndicatorComponentAttribute {
289    modifierWithKey(this._modifiersWithKeys, IndicatorComponentLoopModifier.identity, IndicatorComponentLoopModifier, value);
290    return this;
291  }
292
293  vertical(value: boolean): IndicatorComponentAttribute {
294    modifierWithKey(this._modifiersWithKeys, IndicatorComponentVerticalModifier.identity, IndicatorComponentVerticalModifier, value);
295    return this;
296  }
297
298  onChange(value: Callback<number>): IndicatorComponentAttribute {
299    modifierWithKey(this._modifiersWithKeys, IndicatorComponentOnChangeModifier.identity, IndicatorComponentOnChangeModifier, value);
300    return this;
301  }
302}
303
304// @ts-ignore
305globalThis.IndicatorComponent.attributeModifier = function (modifier: ArkComponent): void {
306  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
307    return new ArkIndicatorComponentComponent(nativePtr);
308  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
309    return new modifierJS.IndicatorComponentModifier(nativePtr, classType);
310  });
311};
312