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 ImageSpanObjectFitModifier extends ModifierWithKey<number> { 18 constructor(value: number) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('imageSpanObjectFit'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().imageSpan.resetObjectFit(node); 25 } else { 26 getUINativeModule().imageSpan.setObjectFit(node, this.value!); 27 } 28 } 29 checkObjectDiff(): boolean { 30 return this.stageValue !== this.value; 31 } 32} 33class ImageSpanVerticalAlignModifier extends ModifierWithKey<number> { 34 constructor(value: number) { 35 super(value); 36 } 37 static identity: Symbol = Symbol('imageSpanVerticalAlign'); 38 applyPeer(node: KNode, reset: boolean): void { 39 if (reset) { 40 getUINativeModule().imageSpan.resetVerticalAlign(node); 41 } else { 42 getUINativeModule().imageSpan.setVerticalAlign(node, this.value!); 43 } 44 } 45 checkObjectDiff(): boolean { 46 return this.stageValue !== this.value; 47 } 48} 49class ArkImageSpanComponent extends ArkComponent implements ImageSpanAttribute { 50 constructor(nativePtr: KNode) { 51 super(nativePtr); 52 } 53 objectFit(value: ImageFit): ImageSpanAttribute { 54 modifierWithKey(this._modifiersWithKeys, ImageSpanObjectFitModifier.identity, ImageSpanObjectFitModifier, value); 55 return this; 56 } 57 verticalAlign(value: ImageSpanAlignment): ImageSpanAttribute { 58 modifierWithKey(this._modifiersWithKeys, ImageSpanVerticalAlignModifier.identity, ImageSpanVerticalAlignModifier, value); 59 return this; 60 } 61} 62// @ts-ignore 63globalThis.ImageSpan.attributeModifier = function (modifier) { 64 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 65 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 66 67 let component = this.createOrGetNode(elmtId, () => { 68 return new ArkImageSpanComponent(nativeNode); 69 }); 70 applyUIAttributes(modifier, nativeNode, component); 71 component.applyModifierPatch(); 72}; 73