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 pageFlipMode(value: PageFlipMode): this { 107 modifierWithKey(this._modifiersWithKeys, TabPageFlipModeModifier.identity, TabPageFlipModeModifier, value); 108 return this; 109 } 110 width(value: Length): this { 111 modifierWithKey(this._modifiersWithKeys, TabWidthModifier.identity, TabWidthModifier, value); 112 return this; 113 } 114 height(value: Length): this { 115 modifierWithKey(this._modifiersWithKeys, TabHeightModifier.identity, TabHeightModifier, value); 116 return this; 117 } 118} 119 120class BarGridAlignModifier extends ModifierWithKey<BarGridColumnOptions> { 121 static identity: Symbol = Symbol('barGridAlign'); 122 123 applyPeer(node: KNode, reset: boolean): void { 124 if (reset) { 125 getUINativeModule().tabs.resetBarGridAlign(node); 126 } else { 127 getUINativeModule().tabs.setBarGridAlign(node, this.value.sm, 128 this.value.md, this.value.lg, this.value.gutter, this.value.margin); 129 } 130 } 131 132 checkObjectDiff(): boolean { 133 return !(this.stageValue.sm === this.value.sm && 134 this.stageValue.md === this.value.md && 135 this.stageValue.lg === this.value.lg && 136 this.stageValue.gutter === this.value.gutter && 137 this.stageValue.margin === this.value.margin); 138 } 139} 140 141class TabsDividerModifier extends ModifierWithKey<DividerStyle> { 142 constructor(value: DividerStyle) { 143 super(value); 144 } 145 static identity: Symbol = Symbol('tabsDivider'); 146 147 applyPeer(node: KNode, reset: boolean): void { 148 if (reset) { 149 getUINativeModule().tabs.resetDivider(node); 150 } else { 151 getUINativeModule().tabs.setDivider(node, this.value.strokeWidth, 152 this.value.color, this.value.startMargin, this.value.endMargin); 153 } 154 } 155 156 checkObjectDiff(): boolean { 157 return !(this.stageValue.strokeWidth === this.value.strokeWidth && 158 this.stageValue.color === this.value.color && 159 this.stageValue.startMargin === this.value.startMargin && 160 this.stageValue.endMargin === this.value.endMargin); 161 } 162} 163 164class BarWidthModifier extends ModifierWithKey<Length> { 165 static identity: Symbol = Symbol('barWidth'); 166 167 applyPeer(node: KNode, reset: boolean): void { 168 if (reset) { 169 getUINativeModule().tabs.resetTabBarWidth(node); 170 } else { 171 getUINativeModule().tabs.setTabBarWidth(node, this.value); 172 } 173 } 174 175 checkObjectDiff(): boolean { 176 return !isBaseOrResourceEqual(this.stageValue, this.value); 177 } 178} 179 180class BarAdaptiveHeightModifier extends ModifierWithKey<boolean> { 181 constructor(value: boolean) { 182 super(value); 183 } 184 static identity: Symbol = Symbol('barAdaptiveHeight'); 185 186 applyPeer(node: KNode, reset: boolean): void { 187 if (reset) { 188 getUINativeModule().tabs.resetBarAdaptiveHeight(node); 189 } else { 190 getUINativeModule().tabs.setBarAdaptiveHeight(node, this.value); 191 } 192 } 193} 194 195class BarHeightModifier extends ModifierWithKey<Length> { 196 static identity: Symbol = Symbol('barHeight'); 197 198 applyPeer(node: KNode, reset: boolean): void { 199 if (reset) { 200 getUINativeModule().tabs.resetTabBarHeight(node); 201 } else { 202 getUINativeModule().tabs.setTabBarHeight(node, this.value); 203 } 204 } 205 206 checkObjectDiff(): boolean { 207 return !isBaseOrResourceEqual(this.stageValue, this.value); 208 } 209} 210 211class BarOverlapModifier extends ModifierWithKey<boolean> { 212 static identity: Symbol = Symbol('barOverlap'); 213 214 applyPeer(node: KNode, reset: boolean): void { 215 if (reset) { 216 getUINativeModule().tabs.resetBarOverlap(node); 217 } else { 218 getUINativeModule().tabs.setBarOverlap(node, this.value); 219 } 220 } 221} 222 223class TabsVerticalModifier extends ModifierWithKey<boolean> { 224 static identity: Symbol = Symbol('vertical'); 225 226 applyPeer(node: KNode, reset: boolean): void { 227 if (reset) { 228 getUINativeModule().tabs.resetIsVertical(node); 229 } else { 230 getUINativeModule().tabs.setIsVertical(node, this.value); 231 } 232 } 233} 234 235class AnimationDurationModifier extends ModifierWithKey<number> { 236 static identity: Symbol = Symbol('animationduration'); 237 238 applyPeer(node: KNode, reset: boolean): void { 239 if (reset) { 240 getUINativeModule().tabs.resetAnimationDuration(node); 241 } else { 242 getUINativeModule().tabs.setAnimationDuration(node, this.value); 243 } 244 } 245} 246 247class AnimationModeModifier extends ModifierWithKey<AnimationMode> { 248 constructor(value: AnimationMode) { 249 super(value); 250 } 251 static identity: Symbol = Symbol('animationMode'); 252 253 applyPeer(node: KNode, reset: boolean): void { 254 if (reset) { 255 getUINativeModule().tabs.resetAnimateMode(node); 256 } else { 257 getUINativeModule().tabs.setAnimateMode(node, this.value); 258 } 259 } 260 261 checkObjectDiff(): boolean { 262 return !isBaseOrResourceEqual(this.stageValue, this.value); 263 } 264} 265 266class ScrollableModifier extends ModifierWithKey<boolean> { 267 static identity: Symbol = Symbol('scrollable'); 268 269 applyPeer(node: KNode, reset: boolean): void { 270 if (reset) { 271 getUINativeModule().tabs.resetScrollable(node); 272 } else { 273 getUINativeModule().tabs.setScrollable(node, this.value); 274 } 275 } 276} 277 278class TabBarModeModifier extends ModifierWithKey<ArkBarMode> { 279 constructor(value: ArkBarMode) { 280 super(value); 281 } 282 static identity: Symbol = Symbol('tabsbarMode'); 283 284 applyPeer(node: KNode, reset: boolean): void { 285 if (reset) { 286 getUINativeModule().tabs.resetTabBarMode(node); 287 } else { 288 getUINativeModule().tabs.setTabBarMode(node, this.value.barMode 289 , this.value.options?.margin 290 , this.value.options?.nonScrollableLayoutStyle); 291 } 292 } 293 294 checkObjectDiff(): boolean { 295 if (isResource(this.stageValue) && isResource(this.value)) { 296 return !isResourceEqual(this.stageValue, this.value); 297 } else if (!isResource(this.stageValue) && !isResource(this.value)) { 298 return !(this.value.barMode === this.stageValue.barMode && 299 this.value.options?.margin === this.stageValue.options?.margin && 300 this.value.options?.nonScrollableLayoutStyle === this.stageValue.options?.nonScrollableLayoutStyle); 301 } else { 302 return true; 303 } 304 } 305} 306 307class BarPositionModifier extends ModifierWithKey<number> { 308 static identity: Symbol = Symbol('barPosition'); 309 310 applyPeer(node: KNode, reset: boolean): void { 311 if (reset) { 312 getUINativeModule().tabs.resetTabBarPosition(node); 313 } else { 314 getUINativeModule().tabs.setTabBarPosition(node, this.value); 315 } 316 } 317} 318 319class TabsHideTitleBarModifier extends ModifierWithKey<string> { 320 constructor(value: string) { 321 super(value); 322 } 323 static identity: Symbol = Symbol('hideTitleBar'); 324 325 applyPeer(node: KNode, reset: boolean): void { 326 if (reset) { 327 getUINativeModule().tabs.resetHideTitleBar(node); 328 } else { 329 getUINativeModule().tabs.setHideTitleBar(node, this.value); 330 } 331 } 332} 333 334class BarBackgroundColorModifier extends ModifierWithKey<ResourceColor> { 335 static identity: Symbol = Symbol('barbackgroundcolor'); 336 337 applyPeer(node: KNode, reset: boolean): void { 338 if (reset) { 339 getUINativeModule().tabs.resetBarBackgroundColor(node); 340 } else { 341 getUINativeModule().tabs.setBarBackgroundColor(node, this.value); 342 } 343 } 344 345 checkObjectDiff(): boolean { 346 return !isBaseOrResourceEqual(this.stageValue, this.value); 347 } 348} 349 350class BarBackgroundBlurStyleModifier extends ModifierWithKey<BlurStyle> { 351 constructor(value: BlurStyle) { 352 super(value); 353 } 354 static identity: Symbol = Symbol('barbackgroundblurstyle'); 355 356 applyPeer(node: KNode, reset: boolean): void { 357 if (reset) { 358 getUINativeModule().tabs.resetBarBackgroundBlurStyle(node); 359 } else { 360 getUINativeModule().tabs.setBarBackgroundBlurStyle(node, this.value); 361 } 362 } 363 364 checkObjectDiff(): boolean { 365 return !isBaseOrResourceEqual(this.stageValue, this.value); 366 } 367} 368 369class FadingEdgeModifier extends ModifierWithKey<boolean> { 370 static identity: Symbol = Symbol('fadingedge'); 371 372 applyPeer(node: KNode, reset: boolean): void { 373 if (reset) { 374 getUINativeModule().tabs.resetFadingEdge(node); 375 } else { 376 getUINativeModule().tabs.setFadingEdge(node, this.value); 377 } 378 } 379} 380 381class TabClipModifier extends ModifierWithKey<boolean | object> { 382 constructor(value: boolean | object) { 383 super(value); 384 } 385 static identity: Symbol = Symbol('tabclip'); 386 applyPeer(node: KNode, reset: boolean): void { 387 if (reset) { 388 getUINativeModule().tabs.resetTabClip(node); 389 } else { 390 getUINativeModule().tabs.setTabClip(node, this.value); 391 } 392 } 393 394 checkObjectDiff(): boolean { 395 return true; 396 } 397} 398 399class TabEdgeEffectModifier extends ModifierWithKey<EdgeEffect> { 400 static identity: Symbol = Symbol('tabedgeEffect'); 401 applyPeer(node: KNode, reset: boolean): void { 402 if (reset) { 403 getUINativeModule().tabs.resetTabEdgeEffect(node); 404 } else { 405 getUINativeModule().tabs.setTabEdgeEffect(node, this.value); 406 } 407 } 408 checkObjectDiff(): boolean { 409 return !isBaseOrResourceEqual(this.stageValue, this.value); 410 } 411} 412 413class TabPageFlipModeModifier extends ModifierWithKey<PageFlipMode> { 414 constructor(value: PageFlipMode) { 415 super(value); 416 } 417 static identity: Symbol = Symbol('tabPageFlipMode'); 418 applyPeer(node: KNode, reset: boolean): void { 419 if (reset) { 420 getUINativeModule().tabs.resetTabPageFlipMode(node); 421 } else { 422 getUINativeModule().tabs.setTabPageFlipMode(node, this.value); 423 } 424 } 425 checkObjectDiff(): boolean { 426 return !isBaseOrResourceEqual(this.stageValue, this.value); 427 } 428} 429 430class TabWidthModifier extends ModifierWithKey<Length> { 431 constructor(value: Length) { 432 super(value); 433 } 434 static identity: Symbol = Symbol('tabWidth'); 435 436 applyPeer(node: KNode, reset: boolean): void { 437 if (reset) { 438 getUINativeModule().tabs.resetTabWidth(node); 439 } else { 440 getUINativeModule().tabs.setTabWidth(node, this.value); 441 } 442 } 443} 444 445class TabHeightModifier extends ModifierWithKey<Length> { 446 constructor(value: Length) { 447 super(value); 448 } 449 static identity: Symbol = Symbol('tabHeight'); 450 451 applyPeer(node: KNode, reset: boolean): void { 452 if (reset) { 453 getUINativeModule().tabs.resetTabHeight(node); 454 } else { 455 getUINativeModule().tabs.setTabHeight(node, this.value); 456 } 457 } 458} 459 460// @ts-ignore 461globalThis.Tabs.attributeModifier = function (modifier: ArkComponent): void { 462 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 463 return new ArkTabsComponent(nativePtr); 464 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 465 return new modifierJS.TabsModifier(nativePtr, classType); 466 }); 467}; 468