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) { 19 super(nativePtr); 20 } 21 tabBar(value: any): this; 22 tabBar(value: SubTabBarStyle | BottomTabBarStyle): this; 23 tabBar(value: unknown): this { 24 throw new Error('Method not implemented.'); 25 } 26 size(value: SizeOptions): this { 27 modifierWithKey(this._modifiersWithKeys, TabContentSizeModifier.identity, TabContentSizeModifier, value); 28 return this; 29 } 30 width(value: Length): this { 31 modifierWithKey(this._modifiersWithKeys, TabContentWidthModifier.identity, TabContentWidthModifier, value); 32 return this; 33 } 34 height(value: Length): this { 35 modifierWithKey(this._modifiersWithKeys, TabContentHeightModifier.identity, TabContentHeightModifier, value); 36 return this; 37 } 38} 39 40class TabContentWidthModifier extends ModifierWithKey<Length> { 41 constructor(value: Length) { 42 super(value); 43 } 44 static identity: Symbol = Symbol('tabcontentwidth'); 45 applyPeer(node: KNode, reset: boolean): void { 46 if (reset) { 47 getUINativeModule().tabContent.resetTabContentWidth(node); 48 } else { 49 getUINativeModule().tabContent.setTabContentWidth(node, this.value); 50 } 51 } 52 53 checkObjectDiff(): boolean { 54 return !isBaseOrResourceEqual(this.stageValue, this.value); 55 } 56} 57 58class TabContentHeightModifier extends ModifierWithKey<Length> { 59 constructor(value: Length) { 60 super(value); 61 } 62 static identity: Symbol = Symbol('tabcontentheight'); 63 applyPeer(node: KNode, reset: boolean): void { 64 if (reset) { 65 getUINativeModule().tabContent.resetTabContentHeight(node); 66 } else { 67 getUINativeModule().tabContent.setTabContentHeight(node, this.value); 68 } 69 } 70 71 checkObjectDiff(): boolean { 72 return !isBaseOrResourceEqual(this.stageValue, this.value); 73 } 74} 75 76class TabContentSizeModifier extends ModifierWithKey<SizeOptions> { 77 constructor(value: SizeOptions) { 78 super(value); 79 } 80 static identity: Symbol = Symbol('tabcontentsize'); 81 applyPeer(node: KNode, reset: boolean): void { 82 if (reset) { 83 getUINativeModule().tabContent.resetTabContentSize(node); 84 } else { 85 getUINativeModule().tabContent.setTabContentSize(node, this.value.width, this.value.height); 86 } 87 } 88 89 checkObjectDiff(): boolean { 90 return !isBaseOrResourceEqual(this.stageValue.width, this.value.width) || 91 !isBaseOrResourceEqual(this.stageValue.height, this.value.height); 92 } 93} 94 95// @ts-ignore 96globalThis.TabContent.attributeModifier = function (modifier) { 97 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 98 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 99 let component = this.createOrGetNode(elmtId, () => { 100 return new ArkTabContentComponent(nativeNode); 101 }); 102 applyUIAttributes(modifier, nativeNode, component); 103 component.applyModifierPatch(); 104}; 105