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' /> 17 18function copyImageAnimatorModifierWithKey(obj: ModifierWithKey<string | number | boolean | object> | ImageAnimatorImagesModifier): 19 ModifierWithKey<string | number | boolean | object> { 20 21 let newObj: ModifierWithKey<string | number | boolean | object> | ImageAnimatorImagesModifier = { 22 ...obj, 23 applyStage: function (node: number): boolean { 24 throw new Error('Function not implemented.'); 25 }, 26 applyPeer: function (node: number, reset: boolean): void { 27 throw new Error('Function not implemented.'); 28 }, 29 checkObjectDiff: function (): boolean { 30 throw new Error('Function not implemented.'); 31 }, 32 }; 33 34 if ((obj as ImageAnimatorImagesModifier)!.convertImageFrames !== undefined) { 35 (newObj as ImageAnimatorImagesModifier).convertImageFrames = (obj as ImageAnimatorImagesModifier)?.convertImageFrames; 36 (newObj as ImageAnimatorImagesModifier).isEqual = (obj as ImageAnimatorImagesModifier)?.isEqual; 37 } 38 39 newObj.applyStage = obj?.applyStage; 40 newObj.applyPeer = obj?.applyPeer; 41 newObj.checkObjectDiff = obj?.checkObjectDiff; 42 return newObj; 43} 44 45function mergeImageAnimatorMaps(stageMap: Map<Symbol, AttributeModifierWithKey>, 46 newMap: Map<Symbol, AttributeModifierWithKey>): Map<Symbol, AttributeModifierWithKey> { 47 newMap.forEach((value, key) => { 48 stageMap.set(key, copyImageAnimatorModifierWithKey(value)); 49 }); 50 51 return stageMap; 52} 53class ImageAnimatorModifier extends ArkImageAnimatorComponent implements AttributeModifier<ImageAnimatorAttribute> { 54 55 constructor(nativePtr: KNode, classType: ModifierType) { 56 super(nativePtr, classType); 57 this._modifiersWithKeys = new ModifierMap(); 58 } 59 60 applyNormalAttribute(instance: ImageAnimatorAttribute): void { 61 ModifierUtils.applySetOnChange(this); 62 // @ts-ignore 63 let component: ArkComponent = instance as ArkComponent; 64 mergeImageAnimatorMaps(component._modifiersWithKeys, this._modifiersWithKeys); 65 } 66} 67