• 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 ArkSliderComponent extends ArkComponent implements SliderAttribute {
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  blockColor(value: ResourceColor): this {
25    modifierWithKey(this._modifiersWithKeys, BlockColorModifier.identity, BlockColorModifier, value);
26    return this;
27  }
28  trackColor(value: ResourceColor): this {
29    modifierWithKey(this._modifiersWithKeys, TrackColorModifier.identity, TrackColorModifier, value);
30    return this;
31  }
32  selectedColor(value: ResourceColor): this {
33    modifierWithKey(this._modifiersWithKeys, SelectColorModifier.identity, SelectColorModifier, value);
34    return this;
35  }
36  minLabel(value: string): this {
37    throw new Error('Method not implemented.');
38  }
39  maxLabel(value: string): this {
40    throw new Error('Method not implemented.');
41  }
42  showSteps(value: boolean): this {
43    modifier(this._modifiers, ShowStepsModifier, value);
44    return this;
45  }
46  showTips(value: boolean, content?: any): this {
47    let showTips = new ArkSliderTips(value, content);
48    modifierWithKey(this._modifiersWithKeys, ShowTipsModifier.identity, ShowTipsModifier, showTips);
49    return this;
50  }
51  trackThickness(value: Length): this {
52    modifierWithKey(this._modifiersWithKeys, TrackThicknessModifier.identity, TrackThicknessModifier, value);
53    return this;
54  }
55  onChange(callback: (value: number, mode: SliderChangeMode) => void): this {
56    throw new Error('Method not implemented.');
57  }
58  blockBorderColor(value: ResourceColor): this {
59    modifierWithKey(this._modifiersWithKeys, BlockBorderColorModifier.identity, BlockBorderColorModifier, value);
60    return this;
61  }
62  blockBorderWidth(value: Length): this {
63    modifierWithKey(this._modifiersWithKeys, BlockBorderWidthModifier.identity, BlockBorderWidthModifier, value);
64    return this;
65  }
66  stepColor(value: ResourceColor): this {
67    modifierWithKey(this._modifiersWithKeys, StepColorModifier.identity, StepColorModifier, value);
68    return this;
69  }
70  trackBorderRadius(value: Length): this {
71    modifierWithKey(this._modifiersWithKeys, TrackBorderRadiusModifier.identity, TrackBorderRadiusModifier, value);
72    return this;
73  }
74  blockSize(value: SizeOptions): this {
75    modifierWithKey(this._modifiersWithKeys, BlockSizeModifier.identity, BlockSizeModifier, value);
76    return this;
77  }
78  blockStyle(value: SliderBlockStyle): this {
79    modifierWithKey(this._modifiersWithKeys, BlockStyleModifier.identity, BlockStyleModifier, value);
80    return this;
81  }
82  stepSize(value: Length): this {
83    modifierWithKey(this._modifiersWithKeys, StepSizeModifier.identity, StepSizeModifier, value);
84    return this;
85  }
86}
87
88class BlockStyleModifier extends ModifierWithKey<SliderBlockStyle> {
89  constructor(value: SliderBlockStyle) {
90    super(value);
91  }
92  static identity: Symbol = Symbol('sliderBlockStyle');
93  applyPeer(node: KNode, reset: boolean): void {
94    if (reset) {
95      getUINativeModule().slider.resetBlockStyle(node);
96    } else {
97      getUINativeModule().slider.setBlockStyle(node, this.value);
98    }
99  }
100
101  checkObjectDiff(): boolean {
102    return !((this.stageValue as SliderBlockStyle).type === (this.value as SliderBlockStyle).type &&
103      (this.stageValue as SliderBlockStyle).image === (this.value as SliderBlockStyle).image &&
104      (this.stageValue as SliderBlockStyle).shape === (this.value as SliderBlockStyle).shape);
105
106  }
107}
108
109class ShowTipsModifier extends ModifierWithKey<ArkSliderTips> {
110  constructor(value: ArkSliderTips) {
111    super(value);
112  }
113  static identity: Symbol = Symbol('sliderShowTips');
114  applyPeer(node: KNode, reset: boolean) {
115    if (reset) {
116      getUINativeModule().slider.resetShowTips(node);
117    } else {
118      getUINativeModule().slider.setShowTips(node, this.value.showTip, this.value?.tipText);
119    }
120  }
121
122  checkObjectDiff(): boolean {
123    let showTipDiff = this.stageValue.showTip !== this.value.showTip;
124    let tipTextDiff = !isBaseOrResourceEqual(this.stageValue.tipText, this.value.tipText);
125    return showTipDiff || tipTextDiff;
126  }
127
128}
129
130class StepSizeModifier extends ModifierWithKey<Length> {
131  constructor(value: Length) {
132    super(value);
133  }
134  static identity: Symbol = Symbol('sliderStepSize');
135  applyPeer(node: KNode, reset: boolean): void {
136    if (reset) {
137      getUINativeModule().slider.resetStepSize(node);
138    } else {
139      getUINativeModule().slider.setStepSize(node, this.value);
140    }
141  }
142
143  checkObjectDiff(): boolean {
144    return !isBaseOrResourceEqual(this.stageValue, this.value);
145  }
146}
147
148class BlockSizeModifier extends ModifierWithKey<SizeOptions> {
149  constructor(value: SizeOptions) {
150    super(value);
151  }
152  static identity: Symbol = Symbol('sliderBlockSize');
153  applyPeer(node: KNode, reset: boolean) {
154    if (reset) {
155      getUINativeModule().slider.resetBlockSize(node);
156    } else {
157      getUINativeModule().slider.setBlockSize(node, this.value!.width, this.value!.height);
158    }
159  }
160
161  checkObjectDiff(): boolean {
162    if (isResource(this.stageValue.height) && isResource(this.value.height) && isResource(this.stageValue.width) && isResource(this.value.width)) {
163      return !(isResourceEqual(this.stageValue.height, this.value.height) && isResourceEqual(this.stageValue.width, this.value.width));
164    } else {
165      return true;
166    }
167  }
168}
169
170class TrackBorderRadiusModifier extends ModifierWithKey<Length> {
171  constructor(value: Length) {
172    super(value);
173  }
174  static identity: Symbol = Symbol('sliderTrackBorderRadius');
175  applyPeer(node: KNode, reset: boolean): void {
176    if (reset) {
177      getUINativeModule().slider.resetTrackBorderRadius(node);
178    } else {
179      getUINativeModule().slider.setTrackBorderRadius(node, this.value);
180    }
181  }
182
183  checkObjectDiff(): boolean {
184    return !isBaseOrResourceEqual(this.stageValue, this.value);
185  }
186}
187
188class StepColorModifier extends ModifierWithKey<ResourceColor> {
189  constructor(value: ResourceColor) {
190    super(value);
191  }
192  static identity: Symbol = Symbol('sliderStepColor');
193  applyPeer(node: KNode, reset: boolean): void {
194    if (reset) {
195      getUINativeModule().slider.resetStepColor(node);
196    } else {
197      getUINativeModule().slider.setStepColor(node, this.value);
198    }
199  }
200
201  checkObjectDiff(): boolean {
202    return !isBaseOrResourceEqual(this.stageValue, this.value);
203  }
204}
205
206class BlockBorderColorModifier extends ModifierWithKey<ResourceColor> {
207  constructor(value: ResourceColor) {
208    super(value);
209  }
210  static identity: Symbol = Symbol('sliderBlockBorderColor');
211  applyPeer(node: KNode, reset: boolean): void {
212    if (reset) {
213      getUINativeModule().slider.resetBlockBorderColor(node);
214    } else {
215      getUINativeModule().slider.setBlockBorderColor(node, this.value);
216    }
217  }
218
219  checkObjectDiff(): boolean {
220    return !isBaseOrResourceEqual(this.stageValue, this.value);
221  }
222}
223
224class BlockBorderWidthModifier extends ModifierWithKey<Length> {
225  constructor(value: Length) {
226    super(value);
227  }
228  static identity: Symbol = Symbol('sliderBlockBorderWidth');
229  applyPeer(node: KNode, reset: boolean): void {
230    if (reset) {
231      getUINativeModule().slider.resetBlockBorderWidth(node);
232    } else {
233      getUINativeModule().slider.setBlockBorderWidth(node, this.value);
234    }
235  }
236
237  checkObjectDiff(): boolean {
238    return !isBaseOrResourceEqual(this.stageValue, this.value);
239  }
240}
241
242class BlockColorModifier extends ModifierWithKey<ResourceColor> {
243  constructor(value: ResourceColor) {
244    super(value);
245  }
246  static identity: Symbol = Symbol('sliderBlockColor');
247  applyPeer(node: KNode, reset: boolean): void {
248    if (reset) {
249      getUINativeModule().slider.resetBlockColor(node);
250    } else {
251      getUINativeModule().slider.setBlockColor(node, this.value);
252    }
253  }
254
255  checkObjectDiff(): boolean {
256    return !isBaseOrResourceEqual(this.stageValue, this.value);
257  }
258}
259
260class TrackColorModifier extends ModifierWithKey<ResourceColor> {
261  constructor(value: ResourceColor) {
262    super(value);
263  }
264  static identity: Symbol = Symbol('sliderTrackColor');
265  applyPeer(node: KNode, reset: boolean): void {
266    if (reset) {
267      getUINativeModule().slider.resetTrackBackgroundColor(node);
268    } else {
269      getUINativeModule().slider.setTrackBackgroundColor(node, this.value);
270    }
271  }
272
273  checkObjectDiff(): boolean {
274    return !isBaseOrResourceEqual(this.stageValue, this.value);
275  }
276}
277
278class SelectColorModifier extends ModifierWithKey<ResourceColor> {
279  constructor(value: ResourceColor) {
280    super(value);
281  }
282  static identity: Symbol = Symbol('sliderSelectColor');
283  applyPeer(node: KNode, reset: boolean): void {
284    if (reset) {
285      getUINativeModule().slider.resetSelectColor(node);
286    } else {
287      getUINativeModule().slider.setSelectColor(node, this.value);
288    }
289  }
290
291  checkObjectDiff(): boolean {
292    return !isBaseOrResourceEqual(this.stageValue, this.value);
293  }
294}
295
296class ShowStepsModifier extends ModifierWithKey<boolean> {
297  constructor(value: boolean) {
298    super(value);
299  }
300  static identity: Symbol = Symbol('sliderShowSteps');
301  applyPeer(node: KNode, reset: boolean) {
302    if (reset) {
303      getUINativeModule().slider.resetShowSteps(node);
304    } else {
305      getUINativeModule().slider.setShowSteps(node, this.value);
306    }
307  }
308  checkObjectDiff(): boolean {
309    return this.stageValue !== this.value;
310  }
311}
312
313class TrackThicknessModifier extends ModifierWithKey<Length> {
314  constructor(value: Length) {
315    super(value);
316  }
317  static identity: Symbol = Symbol('sliderTrackThickness');
318  applyPeer(node: KNode, reset: boolean): void {
319    if (reset) {
320      getUINativeModule().slider.resetThickness(node);
321    } else {
322      getUINativeModule().slider.setThickness(node, this.value);
323    }
324  }
325
326  checkObjectDiff(): boolean {
327    return !isBaseOrResourceEqual(this.stageValue, this.value);
328  }
329}
330
331// @ts-ignore
332globalThis.Slider.attributeModifier = function (modifier) {
333  const elmtId = ViewStackProcessor.GetElmtIdToAccountFor();
334  let nativeNode = getUINativeModule().getFrameNodeById(elmtId);
335  let component = this.createOrGetNode(elmtId, () => {
336    return new ArkSliderComponent(nativeNode);
337  });
338  applyUIAttributes(modifier, nativeNode, component);
339  component.applyModifierPatch();
340};