1/* 2 * Copyright (c) 2024 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 ContainerSpanTextBackgroundStyleModifier extends ModifierWithKey<TextBackgroundStyle> { 18 constructor(value: TextBackgroundStyle) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('containerSpanTextBackgroundStyle'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().containerSpan.resetTextBackgroundStyle(node); 25 } else { 26 let textBackgroundStyle = new ArkTextBackGroundStyle(); 27 if (!textBackgroundStyle.convertTextBackGroundStyleOptions(this.value)) { 28 getUINativeModule().containerSpan.resetTextBackgroundStyle(node); 29 } else { 30 getUINativeModule().containerSpan.setTextBackgroundStyle(node, 31 textBackgroundStyle.color, textBackgroundStyle.radius.topLeft, 32 textBackgroundStyle.radius.topRight, 33 textBackgroundStyle.radius.bottomLeft, 34 textBackgroundStyle.radius.bottomRight); 35 } 36 } 37 } 38 checkObjectDiff(): boolean { 39 let textBackgroundStyle = new ArkTextBackGroundStyle(); 40 let stageTextBackGroundStyle = new ArkTextBackGroundStyle(); 41 if (!textBackgroundStyle.convertTextBackGroundStyleOptions(this.value) || 42 !stageTextBackGroundStyle.convertTextBackGroundStyleOptions(this.stageValue)) { 43 return false; 44 } else { 45 return textBackgroundStyle.checkObjectDiff(stageTextBackGroundStyle); 46 } 47 } 48} 49 50class ArkContainerSpanComponent extends ArkComponent implements ContainerSpanAttribute { 51 constructor(nativePtr: KNode, classType?: ModifierType) { 52 super(nativePtr, classType); 53 } 54 textBackgroundStyle(value: TextBackgroundStyle): ContainerSpanAttribute { 55 modifierWithKey(this._modifiersWithKeys, 56 ContainerSpanTextBackgroundStyleModifier.identity, ContainerSpanTextBackgroundStyleModifier, value); 57 return this; 58 } 59} 60 61// @ts-ignore 62globalThis.ContainerSpan.attributeModifier = function (modifier: ArkComponent): void { 63 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 64 return new ArkContainerSpanComponent(nativePtr); 65 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 66 return new modifierJS.ContainerSpanModifier(nativePtr, classType); 67 }); 68}; 69