• 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 ArkTabsComponent extends ArkComponent implements TabsAttribute {
18  constructor(nativePtr: KNode, classType?: ModifierType) {
19    super(nativePtr, classType);
20  }
21  onAnimationStart(handler: (index: number, targetIndex: number, event: TabsAnimationEvent) => void): TabsAttribute {
22    throw new Error('Method not implemented.');
23  }
24  onAnimationEnd(handler: (index: number, event: TabsAnimationEvent) => void): TabsAttribute {
25    throw new Error('Method not implemented.');
26  }
27  onGestureSwipe(handler: (index: number, event: TabsAnimationEvent) => void): TabsAttribute {
28    throw new Error('Method not implemented.');
29  }
30  vertical(value: boolean): TabsAttribute {
31    modifierWithKey(this._modifiersWithKeys, TabsVerticalModifier.identity, TabsVerticalModifier, value);
32    return this;
33  }
34  barPosition(value: BarPosition): TabsAttribute {
35    modifierWithKey(this._modifiersWithKeys, BarPositionModifier.identity, BarPositionModifier, value);
36    return this;
37  }
38  scrollable(value: boolean): TabsAttribute {
39    modifierWithKey(this._modifiersWithKeys, ScrollableModifier.identity, ScrollableModifier, value);
40    return this;
41  }
42  barMode(value: BarMode, options?: ScrollableBarModeOptions | undefined): TabsAttribute {
43    let arkBarMode = new ArkBarMode();
44    arkBarMode.barMode = value;
45    arkBarMode.options = options;
46    modifierWithKey(this._modifiersWithKeys, TabBarModeModifier.identity, TabBarModeModifier, arkBarMode);
47    return this;
48  }
49
50  barWidth(value: Length): TabsAttribute {
51    modifierWithKey(this._modifiersWithKeys, BarWidthModifier.identity, BarWidthModifier, value);
52
53    return this;
54  }
55  barHeight(value: Length): TabsAttribute {
56    if (isUndefined(value) || isNull(value)) {
57      modifierWithKey(this._modifiersWithKeys, BarHeightModifier.identity, BarHeightModifier, undefined);
58    } else {
59      modifierWithKey(this._modifiersWithKeys, BarHeightModifier.identity, BarHeightModifier, value);
60    }
61
62    return this;
63  }
64  animationDuration(value: number): TabsAttribute {
65    modifierWithKey(this._modifiersWithKeys, AnimationDurationModifier.identity, AnimationDurationModifier, value);
66    return this;
67  }
68  animationMode(value: AnimationMode): TabsAttribute {
69    modifierWithKey(this._modifiersWithKeys, AnimationModeModifier.identity, AnimationModeModifier, value);
70    return this;
71  }
72  onChange(event: (index: number) => void): TabsAttribute {
73    throw new Error('Method not implemented.');
74  }
75  onTabBarClick(event: (index: number) => void): TabsAttribute {
76    throw new Error('Method not implemented.');
77  }
78  fadingEdge(value: boolean): TabsAttribute {
79    modifierWithKey(this._modifiersWithKeys, FadingEdgeModifier.identity, FadingEdgeModifier, value);
80    return this;
81  }
82  divider(value: DividerStyle | null): TabsAttribute {
83    modifierWithKey(this._modifiersWithKeys, TabsDividerModifier.identity, TabsDividerModifier, value);
84    return this;
85  }
86  barOverlap(value: boolean): TabsAttribute {
87    modifierWithKey(this._modifiersWithKeys, BarOverlapModifier.identity, BarOverlapModifier, value);
88    return this;
89  }
90  barBackgroundColor(value: ResourceColor): TabsAttribute {
91    modifierWithKey(this._modifiersWithKeys, BarBackgroundColorModifier.identity, BarBackgroundColorModifier, value);
92    return this;
93  }
94  barBackgroundBlurStyle(value: BlurStyle): TabsAttribute {
95    modifierWithKey(this._modifiersWithKeys, BarBackgroundBlurStyleModifier.identity, BarBackgroundBlurStyleModifier, value);
96    return this;
97  }
98  barGridAlign(value: BarGridColumnOptions): TabsAttribute {
99    modifierWithKey(this._modifiersWithKeys, BarGridAlignModifier.identity, BarGridAlignModifier, value);
100    return this;
101  }
102  clip(value: boolean | CircleAttribute | EllipseAttribute | PathAttribute | RectAttribute): this {
103    modifierWithKey(this._modifiersWithKeys, TabClipModifier.identity, TabClipModifier, value);
104    return this;
105  }
106  width(value: Length): this {
107    modifierWithKey(this._modifiersWithKeys, TabWidthModifier.identity, TabWidthModifier, value);
108    return this;
109  }
110  height(value: Length): this {
111    modifierWithKey(this._modifiersWithKeys, TabHeightModifier.identity, TabHeightModifier, value);
112    return this;
113  }
114}
115
116class BarGridAlignModifier extends ModifierWithKey<BarGridColumnOptions> {
117  static identity: Symbol = Symbol('barGridAlign');
118
119  applyPeer(node: KNode, reset: boolean): void {
120    if (reset) {
121      getUINativeModule().tabs.resetBarGridAlign(node);
122    } else {
123      getUINativeModule().tabs.setBarGridAlign(node, this.value.sm,
124        this.value.md, this.value.lg, this.value.gutter, this.value.margin);
125    }
126  }
127
128  checkObjectDiff(): boolean {
129    return !(this.stageValue.sm === this.value.sm &&
130      this.stageValue.md === this.value.md &&
131      this.stageValue.lg === this.value.lg &&
132      this.stageValue.gutter === this.value.gutter &&
133      this.stageValue.margin === this.value.margin);
134  }
135}
136
137class TabsDividerModifier extends ModifierWithKey<DividerStyle> {
138  constructor(value: DividerStyle) {
139    super(value);
140  }
141  static identity: Symbol = Symbol('tabsDivider');
142
143  applyPeer(node: KNode, reset: boolean): void {
144    if (reset) {
145      getUINativeModule().tabs.resetDivider(node);
146    } else {
147      getUINativeModule().tabs.setDivider(node, this.value.strokeWidth,
148        this.value.color, this.value.startMargin, this.value.endMargin);
149    }
150  }
151
152  checkObjectDiff(): boolean {
153    return !(this.stageValue.strokeWidth === this.value.strokeWidth &&
154      this.stageValue.color === this.value.color &&
155      this.stageValue.startMargin === this.value.startMargin &&
156      this.stageValue.endMargin === this.value.endMargin);
157  }
158}
159
160class BarWidthModifier extends ModifierWithKey<Length> {
161  static identity: Symbol = Symbol('barWidth');
162
163  applyPeer(node: KNode, reset: boolean): void {
164    if (reset) {
165      getUINativeModule().tabs.resetTabBarWidth(node);
166    } else {
167      getUINativeModule().tabs.setTabBarWidth(node, this.value);
168    }
169  }
170
171  checkObjectDiff(): boolean {
172    return !isBaseOrResourceEqual(this.stageValue, this.value);
173  }
174}
175
176class BarAdaptiveHeightModifier extends ModifierWithKey<boolean> {
177  constructor(value: boolean) {
178    super(value);
179  }
180  static identity: Symbol = Symbol('barAdaptiveHeight');
181
182  applyPeer(node: KNode, reset: boolean): void {
183    if (reset) {
184      getUINativeModule().tabs.resetBarAdaptiveHeight(node);
185    } else {
186      getUINativeModule().tabs.setBarAdaptiveHeight(node, this.value);
187    }
188  }
189}
190
191class BarHeightModifier extends ModifierWithKey<Length> {
192  static identity: Symbol = Symbol('barHeight');
193
194  applyPeer(node: KNode, reset: boolean): void {
195    if (reset) {
196      getUINativeModule().tabs.resetTabBarHeight(node);
197    } else {
198      getUINativeModule().tabs.setTabBarHeight(node, this.value);
199    }
200  }
201
202  checkObjectDiff(): boolean {
203    return !isBaseOrResourceEqual(this.stageValue, this.value);
204  }
205}
206
207class BarOverlapModifier extends ModifierWithKey<boolean> {
208  static identity: Symbol = Symbol('barOverlap');
209
210  applyPeer(node: KNode, reset: boolean): void {
211    if (reset) {
212      getUINativeModule().tabs.resetBarOverlap(node);
213    } else {
214      getUINativeModule().tabs.setBarOverlap(node, this.value);
215    }
216  }
217}
218
219class TabsVerticalModifier extends ModifierWithKey<boolean> {
220  static identity: Symbol = Symbol('vertical');
221
222  applyPeer(node: KNode, reset: boolean): void {
223    if (reset) {
224      getUINativeModule().tabs.resetIsVertical(node);
225    } else {
226      getUINativeModule().tabs.setIsVertical(node, this.value);
227    }
228  }
229}
230
231class AnimationDurationModifier extends ModifierWithKey<number> {
232  static identity: Symbol = Symbol('animationduration');
233
234  applyPeer(node: KNode, reset: boolean): void {
235    if (reset) {
236      getUINativeModule().tabs.resetAnimationDuration(node);
237    } else {
238      getUINativeModule().tabs.setAnimationDuration(node, this.value);
239    }
240  }
241}
242
243class AnimationModeModifier extends ModifierWithKey<AnimationMode> {
244  constructor(value: AnimationMode) {
245    super(value);
246  }
247  static identity: Symbol = Symbol('animationMode');
248
249  applyPeer(node: KNode, reset: boolean): void {
250    if (reset) {
251      getUINativeModule().tabs.resetAnimateMode(node);
252    } else {
253      getUINativeModule().tabs.setAnimateMode(node, this.value);
254    }
255  }
256
257  checkObjectDiff(): boolean {
258    return !isBaseOrResourceEqual(this.stageValue, this.value);
259  }
260}
261
262class ScrollableModifier extends ModifierWithKey<boolean> {
263  static identity: Symbol = Symbol('scrollable');
264
265  applyPeer(node: KNode, reset: boolean): void {
266    if (reset) {
267      getUINativeModule().tabs.resetScrollable(node);
268    } else {
269      getUINativeModule().tabs.setScrollable(node, this.value);
270    }
271  }
272}
273
274class TabBarModeModifier extends ModifierWithKey<ArkBarMode> {
275  constructor(value: ArkBarMode) {
276    super(value);
277  }
278  static identity: Symbol = Symbol('tabsbarMode');
279
280  applyPeer(node: KNode, reset: boolean): void {
281    if (reset) {
282      getUINativeModule().tabs.resetTabBarMode(node);
283    } else {
284      getUINativeModule().tabs.setTabBarMode(node, this.value.barMode
285        , this.value.options?.margin
286        , this.value.options?.nonScrollableLayoutStyle);
287    }
288  }
289
290  checkObjectDiff(): boolean {
291    if (isResource(this.stageValue) && isResource(this.value)) {
292      return !isResourceEqual(this.stageValue, this.value);
293    } else if (!isResource(this.stageValue) && !isResource(this.value)) {
294      return !(this.value.barMode === this.stageValue.barMode &&
295        this.value.options?.margin === this.stageValue.options?.margin &&
296        this.value.options?.nonScrollableLayoutStyle === this.stageValue.options?.nonScrollableLayoutStyle);
297    } else {
298      return true;
299    }
300  }
301}
302
303class BarPositionModifier extends ModifierWithKey<number> {
304  static identity: Symbol = Symbol('barPosition');
305
306  applyPeer(node: KNode, reset: boolean): void {
307    if (reset) {
308      getUINativeModule().tabs.resetTabBarPosition(node);
309    } else {
310      getUINativeModule().tabs.setTabBarPosition(node, this.value);
311    }
312  }
313}
314
315class TabsHideTitleBarModifier extends ModifierWithKey<string> {
316  constructor(value: string) {
317    super(value);
318  }
319  static identity: Symbol = Symbol('hideTitleBar');
320
321  applyPeer(node: KNode, reset: boolean): void {
322    if (reset) {
323      getUINativeModule().tabs.resetHideTitleBar(node);
324    } else {
325      getUINativeModule().tabs.setHideTitleBar(node, this.value);
326    }
327  }
328}
329
330class BarBackgroundColorModifier extends ModifierWithKey<ResourceColor> {
331  static identity: Symbol = Symbol('barbackgroundcolor');
332
333  applyPeer(node: KNode, reset: boolean): void {
334    if (reset) {
335      getUINativeModule().tabs.resetBarBackgroundColor(node);
336    } else {
337      getUINativeModule().tabs.setBarBackgroundColor(node, this.value);
338    }
339  }
340
341  checkObjectDiff(): boolean {
342    return !isBaseOrResourceEqual(this.stageValue, this.value);
343  }
344}
345
346class BarBackgroundBlurStyleModifier extends ModifierWithKey<BlurStyle> {
347  constructor(value: BlurStyle) {
348    super(value);
349  }
350  static identity: Symbol = Symbol('barbackgroundblurstyle');
351
352  applyPeer(node: KNode, reset: boolean): void {
353    if (reset) {
354      getUINativeModule().tabs.resetBarBackgroundBlurStyle(node);
355    } else {
356      getUINativeModule().tabs.setBarBackgroundBlurStyle(node, this.value);
357    }
358  }
359
360  checkObjectDiff(): boolean {
361    return !isBaseOrResourceEqual(this.stageValue, this.value);
362  }
363}
364
365class FadingEdgeModifier extends ModifierWithKey<boolean> {
366  static identity: Symbol = Symbol('fadingedge');
367
368  applyPeer(node: KNode, reset: boolean): void {
369    if (reset) {
370      getUINativeModule().tabs.resetFadingEdge(node);
371    } else {
372      getUINativeModule().tabs.setFadingEdge(node, this.value);
373    }
374  }
375}
376
377class TabClipModifier extends ModifierWithKey<boolean | object> {
378  constructor(value: boolean | object) {
379    super(value);
380  }
381  static identity: Symbol = Symbol('tabclip');
382  applyPeer(node: KNode, reset: boolean): void {
383    if (reset) {
384      getUINativeModule().tabs.resetTabClip(node);
385    } else {
386      getUINativeModule().tabs.setTabClip(node, this.value);
387    }
388  }
389
390  checkObjectDiff(): boolean {
391    return true;
392  }
393}
394
395class TabEdgeEffectModifier extends ModifierWithKey<EdgeEffect> {
396  static identity: Symbol = Symbol('tabedgeEffect');
397  applyPeer(node: KNode, reset: boolean): void {
398    if (reset) {
399      getUINativeModule().tabs.resetTabEdgeEffect(node);
400    } else {
401      getUINativeModule().tabs.setTabEdgeEffect(node, this.value);
402    }
403  }
404  checkObjectDiff(): boolean {
405    return !isBaseOrResourceEqual(this.stageValue, this.value);
406  }
407}
408
409class TabWidthModifier extends ModifierWithKey<Length> {
410  constructor(value: Length) {
411    super(value);
412  }
413  static identity: Symbol = Symbol('tabWidth');
414
415  applyPeer(node: KNode, reset: boolean): void {
416    if (reset) {
417      getUINativeModule().tabs.resetTabWidth(node);
418    } else {
419      getUINativeModule().tabs.setTabWidth(node, this.value);
420    }
421  }
422}
423
424class TabHeightModifier extends ModifierWithKey<Length> {
425  constructor(value: Length) {
426    super(value);
427  }
428  static identity: Symbol = Symbol('tabHeight');
429
430  applyPeer(node: KNode, reset: boolean): void {
431    if (reset) {
432      getUINativeModule().tabs.resetTabHeight(node);
433    } else {
434      getUINativeModule().tabs.setTabHeight(node, this.value);
435    }
436  }
437}
438
439// @ts-ignore
440globalThis.Tabs.attributeModifier = function (modifier: ArkComponent): void {
441  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
442    return new ArkTabsComponent(nativePtr);
443  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
444    return new modifierJS.TabsModifier(nativePtr, classType);
445  });
446};
447