• 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 ArkCounterComponent extends ArkComponent implements CounterAttribute {
18  constructor(nativePtr: KNode, classType?: ModifierType) {
19    super(nativePtr, classType);
20  }
21  onInc(event: () => void): this {
22    throw new Error('Method not implemented.');
23  }
24  onDec(event: () => void): this {
25    throw new Error('Method not implemented.');
26  }
27  enableDec(value: boolean): this {
28    modifierWithKey(this._modifiersWithKeys, EnableDecModifier.identity, EnableDecModifier, value);
29    return this;
30  }
31  enableInc(value: boolean): this {
32    modifierWithKey(this._modifiersWithKeys, EnableIncModifier.identity, EnableIncModifier, value);
33    return this;
34  }
35  backgroundColor(value: ResourceColor): this {
36    modifierWithKey(this._modifiersWithKeys, CounterBackgroundColorModifier.identity, CounterBackgroundColorModifier, value);
37    return this;
38  }
39  width(value: Length): this {
40    modifierWithKey(
41      this._modifiersWithKeys, CounterWidthModifier.identity, CounterWidthModifier, value);
42    return this;
43  }
44  height(value: Length): this {
45    modifierWithKey(
46      this._modifiersWithKeys, CounterHeightModifier.identity, CounterHeightModifier, value);
47    return this;
48  }
49  size(value: SizeOptions): this {
50    modifierWithKey(this._modifiersWithKeys, CounterSizeModifier.identity, CounterSizeModifier, value);
51    return this;
52  }
53}
54class CounterHeightModifier extends ModifierWithKey<Length> {
55  constructor(value: Length) {
56    super(value);
57  }
58  static identity: Symbol = Symbol('CounterHeight');
59  applyPeer(node: KNode, reset: boolean): void {
60    if (reset) {
61      getUINativeModule().counter.resetCounterHeight(node);
62    } else {
63      getUINativeModule().counter.setCounterHeight(node, this.value);
64    }
65  }
66
67  checkObjectDiff(): boolean {
68    return !isBaseOrResourceEqual(this.stageValue, this.value);
69  }
70}
71class CounterWidthModifier extends ModifierWithKey<Length> {
72  constructor(value: Length) {
73    super(value);
74  }
75  static identity: Symbol = Symbol('CounterWidth');
76  applyPeer(node: KNode, reset: boolean): void {
77    if (reset) {
78      getUINativeModule().counter.resetCounterWidth(node);
79    } else {
80      getUINativeModule().counter.setCounterWidth(node, this.value);
81    }
82  }
83
84  checkObjectDiff(): boolean {
85    return !isBaseOrResourceEqual(this.stageValue, this.value);
86  }
87}
88class CounterBackgroundColorModifier extends ModifierWithKey<ResourceColor> {
89  constructor(value: ResourceColor) {
90    super(value);
91  }
92  static identity: Symbol = Symbol('CounterBackgroundColor');
93  applyPeer(node: KNode, reset: boolean): void {
94    if (reset) {
95      getUINativeModule().counter.resetCounterBackgroundColor(node);
96    } else {
97      getUINativeModule().counter.setCounterBackgroundColor(node, this.value);
98    }
99  }
100
101  checkObjectDiff(): boolean {
102    return !isBaseOrResourceEqual(this.stageValue, this.value);
103  }
104}
105class CounterSizeModifier extends ModifierWithKey<SizeOptions> {
106  constructor(value: SizeOptions) {
107    super(value);
108  }
109  static identity: Symbol = Symbol('CounterSize');
110  applyPeer(node: KNode, reset: boolean): void {
111    if (reset) {
112      getUINativeModule().counter.resetCounterSize(node);
113    } else {
114      getUINativeModule().counter.setCounterSize(node, this.value.width, this.value.height);
115    }
116  }
117
118  checkObjectDiff(): boolean {
119    return !isBaseOrResourceEqual(this.stageValue.width, this.value.width) ||
120      !isBaseOrResourceEqual(this.stageValue.height, this.value.height);
121  }
122}
123class EnableIncModifier extends ModifierWithKey<boolean> {
124  constructor(value: boolean) {
125    super(value);
126  }
127  static identity = Symbol('enableInc');
128  applyPeer(node: KNode, reset: boolean): void {
129    if (reset) {
130      getUINativeModule().counter.resetEnableInc(node);
131    } else {
132      getUINativeModule().counter.setEnableInc(node, this.value);
133    }
134  }
135}
136class EnableDecModifier extends ModifierWithKey<boolean> {
137  constructor(value: boolean) {
138    super(value);
139  }
140  static identity = Symbol('enableDec');
141  applyPeer(node: KNode, reset: boolean): void {
142    if (reset) {
143      getUINativeModule().counter.resetEnableDec(node);
144    } else {
145      getUINativeModule().counter.setEnableDec(node, this.value);
146    }
147  }
148}
149
150// @ts-ignore
151globalThis.Counter.attributeModifier = function (modifier: ArkComponent): void {
152  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
153    return new ArkCounterComponent(nativePtr);
154  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
155    return new modifierJS.CounterModifier(nativePtr, classType);
156  });
157};
158