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 BlankColorModifier extends ModifierWithKey<ResourceColor> { 18 constructor(value: ResourceColor) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('blankColor'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().blank.resetColor(node); 25 } else { 26 getUINativeModule().blank.setColor(node, this.value!); 27 } 28 } 29 checkObjectDiff(): boolean { 30 return !isBaseOrResourceEqual(this.stageValue, this.value); 31 } 32} 33 34class BlankHeightModifier extends ModifierWithKey<Length> { 35 constructor(value: ResourceColor) { 36 super(value); 37 } 38 static identity: Symbol = Symbol('blankHeight'); 39 applyPeer(node: KNode, reset: boolean): void { 40 if (reset) { 41 getUINativeModule().blank.resetBlankHeight(node); 42 } else { 43 getUINativeModule().blank.setBlankHeight(node, this.value!); 44 } 45 } 46 checkObjectDiff(): boolean { 47 return !isBaseOrResourceEqual(this.stageValue, this.value); 48 } 49} 50 51class ArkBlankComponent extends ArkComponent implements CommonMethod<BlankAttribute> { 52 constructor(nativePtr: KNode) { 53 super(nativePtr); 54 } 55 color(value: ResourceColor): BlankAttribute { 56 modifierWithKey(this._modifiersWithKeys, BlankColorModifier.identity, BlankColorModifier, value); 57 return this; 58 } 59 height(value: Length): this { 60 modifierWithKey(this._modifiersWithKeys, BlankHeightModifier.identity, BlankHeightModifier, value); 61 return this; 62 } 63} 64 65// @ts-ignore 66globalThis.Blank.attributeModifier = function (modifier) { 67 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 68 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 69 let component = this.createOrGetNode(elmtId, () => { 70 return new ArkBlankComponent(nativeNode); 71 }); 72 applyUIAttributes(modifier, nativeNode, component); 73 component.applyModifierPatch(); 74};