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) { 19 super(nativePtr); 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 onChange(event: (index: number) => void): TabsAttribute { 69 throw new Error('Method not implemented.'); 70 } 71 onTabBarClick(event: (index: number) => void): TabsAttribute { 72 throw new Error('Method not implemented.'); 73 } 74 fadingEdge(value: boolean): TabsAttribute { 75 modifierWithKey(this._modifiersWithKeys, FadingEdgeModifier.identity, FadingEdgeModifier, value); 76 return this; 77 } 78 divider(value: DividerStyle | null): TabsAttribute { 79 modifierWithKey(this._modifiersWithKeys, DividerModifier.identity, DividerModifier, value); 80 return this; 81 } 82 barOverlap(value: boolean): TabsAttribute { 83 modifierWithKey(this._modifiersWithKeys, BarOverlapModifier.identity, BarOverlapModifier, value); 84 return this; 85 } 86 barBackgroundColor(value: ResourceColor): TabsAttribute { 87 modifierWithKey(this._modifiersWithKeys, BarBackgroundColorModifier.identity, BarBackgroundColorModifier, value); 88 return this; 89 } 90 barGridAlign(value: BarGridColumnOptions): TabsAttribute { 91 modifierWithKey(this._modifiersWithKeys, BarGridAlignModifier.identity, BarGridAlignModifier, value); 92 return this; 93 } 94 clip(value: boolean | CircleAttribute | EllipseAttribute | PathAttribute | RectAttribute): this { 95 modifierWithKey(this._modifiersWithKeys, TabClipModifier.identity, TabClipModifier, value); 96 return this; 97 } 98} 99 100class BarGridAlignModifier extends ModifierWithKey<BarGridColumnOptions> { 101 constructor(value: BarGridColumnOptions) { 102 super(value); 103 } 104 static identity: Symbol = Symbol('barGridAlign'); 105 106 applyPeer(node: KNode, reset: boolean): void { 107 if (reset) { 108 getUINativeModule().tabs.resetBarGridAlign(node); 109 } else { 110 getUINativeModule().tabs.setBarGridAlign(node, this.value.sm, 111 this.value.md, this.value.lg, this.value.gutter, this.value.margin); 112 } 113 } 114 115 checkObjectDiff(): boolean { 116 return !(this.stageValue.sm === this.value.sm && 117 this.stageValue.md === this.value.md && 118 this.stageValue.lg === this.value.lg && 119 this.stageValue.gutter === this.value.gutter && 120 this.stageValue.margin === this.value.margin); 121 } 122} 123 124class DividerModifier extends ModifierWithKey<DividerStyle> { 125 constructor(value: DividerStyle) { 126 super(value); 127 } 128 static identity: Symbol = Symbol('Divider'); 129 130 applyPeer(node: KNode, reset: boolean): void { 131 if (reset) { 132 getUINativeModule().tabs.resetDivider(node); 133 } else { 134 getUINativeModule().tabs.setDivider(node, this.value.strokeWidth, 135 this.value.color, this.value.startMargin, this.value.endMargin); 136 } 137 } 138 139 checkObjectDiff(): boolean { 140 return !(this.stageValue.strokeWidth === this.value.strokeWidth && 141 this.stageValue.color === this.value.color && 142 this.stageValue.startMargin === this.value.startMargin && 143 this.stageValue.endMargin === this.value.endMargin); 144 } 145} 146 147class BarWidthModifier extends ModifierWithKey<Length> { 148 constructor(value: Length) { 149 super(value); 150 } 151 static identity: Symbol = Symbol('barWidth'); 152 153 applyPeer(node: KNode, reset: boolean): void { 154 if (reset) { 155 getUINativeModule().tabs.resetTabBarWidth(node); 156 } else { 157 getUINativeModule().tabs.setTabBarWidth(node, this.value); 158 } 159 } 160 161 checkObjectDiff(): boolean { 162 return !isBaseOrResourceEqual(this.stageValue, this.value); 163 } 164} 165 166class BarAdaptiveHeightModifier extends Modifier<boolean> { 167 constructor(value: boolean) { 168 super(value); 169 } 170 static identity: Symbol = Symbol('barAdaptiveHeight'); 171 172 applyPeer(node: KNode, reset: boolean): void { 173 if (reset) { 174 getUINativeModule().tabs.resetBarAdaptiveHeight(node); 175 } else { 176 getUINativeModule().tabs.setBarAdaptiveHeight(node, this.value); 177 } 178 } 179} 180 181class BarHeightModifier extends ModifierWithKey<Length> { 182 constructor(value: Length) { 183 super(value); 184 } 185 static identity: Symbol = Symbol('barHeight'); 186 187 applyPeer(node: KNode, reset: boolean): void { 188 if (reset) { 189 getUINativeModule().tabs.resetTabBarHeight(node); 190 } else { 191 getUINativeModule().tabs.setTabBarHeight(node, this.value); 192 } 193 } 194 195 checkObjectDiff(): boolean { 196 return !isBaseOrResourceEqual(this.stageValue, this.value); 197 } 198} 199 200class BarOverlapModifier extends ModifierWithKey<boolean> { 201 constructor(value: boolean) { 202 super(value); 203 } 204 static identity: Symbol = Symbol('barOverlap'); 205 206 applyPeer(node: KNode, reset: boolean): void { 207 if (reset) { 208 getUINativeModule().tabs.resetBarOverlap(node); 209 } else { 210 getUINativeModule().tabs.setBarOverlap(node, this.value); 211 } 212 } 213} 214 215class TabsVerticalModifier extends ModifierWithKey<boolean> { 216 constructor(value: boolean) { 217 super(value); 218 } 219 static identity: Symbol = Symbol('vertical'); 220 221 applyPeer(node: KNode, reset: boolean): void { 222 if (reset) { 223 getUINativeModule().tabs.resetIsVertical(node); 224 } else { 225 getUINativeModule().tabs.setIsVertical(node, this.value); 226 } 227 } 228} 229 230class AnimationDurationModifier extends ModifierWithKey<number> { 231 constructor(value: number) { 232 super(value); 233 } 234 static identity: Symbol = Symbol('animationduration'); 235 236 applyPeer(node: KNode, reset: boolean): void { 237 if (reset) { 238 getUINativeModule().tabs.resetAnimationDuration(node); 239 } else { 240 getUINativeModule().tabs.setAnimationDuration(node, this.value); 241 } 242 } 243} 244 245class ScrollableModifier extends ModifierWithKey<boolean> { 246 constructor(value: boolean) { 247 super(value); 248 } 249 static identity: Symbol = Symbol('scrollable'); 250 251 applyPeer(node: KNode, reset: boolean): void { 252 if (reset) { 253 getUINativeModule().tabs.resetScrollable(node); 254 } else { 255 getUINativeModule().tabs.setScrollable(node, this.value); 256 } 257 } 258} 259 260class TabBarModeModifier extends ModifierWithKey<ArkBarMode> { 261 constructor(value: ArkBarMode) { 262 super(value); 263 } 264 static identity: Symbol = Symbol('tabsbarMode'); 265 266 applyPeer(node: KNode, reset: boolean): void { 267 if (reset) { 268 getUINativeModule().tabs.resetTabBarMode(node); 269 } else { 270 getUINativeModule().tabs.setTabBarMode(node, this.value.barMode 271 , this.value.options?.margin 272 , this.value.options?.nonScrollableLayoutStyle); 273 } 274 } 275 276 checkObjectDiff(): boolean { 277 if (isResource(this.stageValue) && isResource(this.value)) { 278 return !isResourceEqual(this.stageValue, this.value); 279 } else if (!isResource(this.stageValue) && !isResource(this.value)) { 280 return !(this.value.barMode === this.stageValue.barMode && 281 this.value.options?.margin === this.stageValue.options?.margin && 282 this.value.options?.nonScrollableLayoutStyle === this.stageValue.options?.nonScrollableLayoutStyle); 283 } else { 284 return true; 285 } 286 } 287} 288 289class BarPositionModifier extends ModifierWithKey<number> { 290 constructor(value: number) { 291 super(value); 292 } 293 static identity: Symbol = Symbol('barPosition'); 294 295 applyPeer(node: KNode, reset: boolean): void { 296 if (reset) { 297 getUINativeModule().tabs.resetTabBarPosition(node); 298 } else { 299 getUINativeModule().tabs.setTabBarPosition(node, this.value); 300 } 301 } 302} 303 304class TabsHideTitleBarModifier extends Modifier<string> { 305 constructor(value: string) { 306 super(value); 307 } 308 static identity: Symbol = Symbol('hideTitleBar'); 309 310 applyPeer(node: KNode, reset: boolean): void { 311 if (reset) { 312 getUINativeModule().tabs.resetHideTitleBar(node); 313 } else { 314 getUINativeModule().tabs.setHideTitleBar(node, this.value); 315 } 316 } 317} 318 319class BarBackgroundColorModifier extends ModifierWithKey<ResourceColor> { 320 constructor(value: ResourceColor) { 321 super(value); 322 } 323 static identity: Symbol = Symbol('barbackgroundcolor'); 324 325 applyPeer(node: KNode, reset: boolean): void { 326 if (reset) { 327 getUINativeModule().tabs.resetBarBackgroundColor(node); 328 } else { 329 getUINativeModule().tabs.setBarBackgroundColor(node, this.value); 330 } 331 } 332 333 checkObjectDiff(): boolean { 334 return !isBaseOrResourceEqual(this.stageValue, this.value); 335 } 336} 337 338class FadingEdgeModifier extends ModifierWithKey<boolean> { 339 constructor(value: boolean) { 340 super(value); 341 } 342 static identity: Symbol = Symbol('fadingedge'); 343 344 applyPeer(node: KNode, reset: boolean): void { 345 if (reset) { 346 getUINativeModule().tabs.resetFadingEdge(node); 347 } else { 348 getUINativeModule().tabs.setFadingEdge(node, this.value); 349 } 350 } 351} 352 353class TabClipModifier extends ModifierWithKey<boolean | object> { 354 constructor(value: boolean | object) { 355 super(value); 356 } 357 static identity: Symbol = Symbol('tabclip'); 358 applyPeer(node: KNode, reset: boolean): void { 359 if (reset) { 360 getUINativeModule().tabs.resetTabClip(node); 361 } else { 362 getUINativeModule().tabs.setTabClip(node, this.value); 363 } 364 } 365 366 checkObjectDiff(): boolean { 367 return true; 368 } 369} 370 371// @ts-ignore 372globalThis.Tabs.attributeModifier = function (modifier) { 373 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 374 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 375 let component = this.createOrGetNode(elmtId, () => { 376 return new ArkTabsComponent(nativeNode); 377 }); 378 applyUIAttributes(modifier, nativeNode, component); 379 component.applyModifierPatch(); 380}; 381