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 ArkTabContentComponent extends ArkComponent implements TabContentAttribute { 18 constructor(nativePtr: KNode, classType?: ModifierType) { 19 super(nativePtr, classType); 20 } 21 tabBar(value: SubTabBarStyle | BottomTabBarStyle | ComponentContent): this { 22 modifierWithKey(this._modifiersWithKeys, TabContentTabBarModifier.identity, TabContentTabBarModifier, value); 23 return this; 24 } 25 size(value: SizeOptions): this { 26 modifierWithKey(this._modifiersWithKeys, TabContentSizeModifier.identity, TabContentSizeModifier, value); 27 return this; 28 } 29 width(value: Length): this { 30 modifierWithKey(this._modifiersWithKeys, TabContentWidthModifier.identity, TabContentWidthModifier, value); 31 return this; 32 } 33 height(value: Length): this { 34 modifierWithKey(this._modifiersWithKeys, TabContentHeightModifier.identity, TabContentHeightModifier, value); 35 return this; 36 } 37} 38 39class TabContentTabBarModifier extends ModifierWithKey<SubTabBarStyle | BottomTabBarStyle> { 40 constructor(value: SubTabBarStyle | BottomTabBarStyle) { 41 super(value); 42 } 43 static identity: Symbol = Symbol('tabContentTabBar'); 44 applyPeer(node: KNode, reset: boolean): void { 45 if (reset) { 46 getUINativeModule().tabContent.resetTabBar(node); 47 } else { 48 getUINativeModule().tabContent.setTabBar(this.value); 49 } 50 } 51 52 checkObjectDiff(): boolean { 53 return !isBaseOrResourceEqual(this.stageValue, this.value); 54 } 55} 56 57class TabContentWidthModifier extends ModifierWithKey<Length> { 58 constructor(value: Length) { 59 super(value); 60 } 61 static identity: Symbol = Symbol('tabcontentwidth'); 62 applyPeer(node: KNode, reset: boolean): void { 63 if (reset) { 64 getUINativeModule().tabContent.resetTabContentWidth(node); 65 } else { 66 getUINativeModule().tabContent.setTabContentWidth(node, this.value); 67 } 68 } 69 70 checkObjectDiff(): boolean { 71 return !isBaseOrResourceEqual(this.stageValue, this.value); 72 } 73} 74 75class TabContentHeightModifier extends ModifierWithKey<Length> { 76 constructor(value: Length) { 77 super(value); 78 } 79 static identity: Symbol = Symbol('tabcontentheight'); 80 applyPeer(node: KNode, reset: boolean): void { 81 if (reset) { 82 getUINativeModule().tabContent.resetTabContentHeight(node); 83 } else { 84 getUINativeModule().tabContent.setTabContentHeight(node, this.value); 85 } 86 } 87 88 checkObjectDiff(): boolean { 89 return !isBaseOrResourceEqual(this.stageValue, this.value); 90 } 91} 92 93class TabContentSizeModifier extends ModifierWithKey<SizeOptions> { 94 constructor(value: SizeOptions) { 95 super(value); 96 } 97 static identity: Symbol = Symbol('tabcontentsize'); 98 applyPeer(node: KNode, reset: boolean): void { 99 if (reset) { 100 getUINativeModule().tabContent.resetTabContentSize(node); 101 } else { 102 getUINativeModule().tabContent.setTabContentSize(node, this.value.width, this.value.height); 103 } 104 } 105 106 checkObjectDiff(): boolean { 107 return !isBaseOrResourceEqual(this.stageValue.width, this.value.width) || 108 !isBaseOrResourceEqual(this.stageValue.height, this.value.height); 109 } 110} 111 112// @ts-ignore 113globalThis.TabContent.attributeModifier = function (modifier: ArkComponent): void { 114 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 115 return new ArkTabContentComponent(nativePtr); 116 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 117 return new modifierJS.TabContentModifier(nativePtr, classType); 118 }); 119}; 120