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' /> 17 18interface StackParam { 19 alignContent: Alignment 20} 21 22class ArkStackComponent extends ArkComponent implements StackAttribute { 23 constructor(nativePtr: KNode, classType?: ModifierType) { 24 super(nativePtr, classType); 25 } 26 initialize(value: Object[]): StackAttribute { 27 if (value[0] !== undefined) { 28 this.alignContent((value[0] as StackParam).alignContent); 29 } 30 return this 31 } 32 alignContent(value: Alignment): StackAttribute { 33 modifierWithKey(this._modifiersWithKeys, StackAlignContentModifier.identity, StackAlignContentModifier, value); 34 return this; 35 } 36 align(value: Alignment): this { 37 modifierWithKey(this._modifiersWithKeys, StackAlignContentModifier.identity, StackAlignContentModifier, value); 38 return this; 39 } 40 pointLight(value: PointLightStyle): StackAttribute { 41 modifierWithKey(this._modifiersWithKeys, StackPointLightModifier.identity, StackPointLightModifier, value); 42 return this; 43 } 44} 45 46class StackPointLightModifier extends ModifierWithKey<PointLightStyle> { 47 constructor(value: PointLightStyle) { 48 super(value); 49 } 50 static identity: Symbol = Symbol('stackPointLight'); 51 applyPeer(node: KNode, reset: boolean): void { 52 if (reset) { 53 getUINativeModule().common.resetPointLightStyle(node); 54 } else { 55 let positionX: Dimension | undefined; 56 let positionY: Dimension | undefined; 57 let positionZ: Dimension | undefined; 58 let intensity: number | undefined; 59 let color: ResourceColor | undefined; 60 let illuminated: number | undefined; 61 let bloom: number | undefined; 62 if (!isUndefined(this.value.lightSource) && this.value.lightSource != null) { 63 positionX = this.value.lightSource.positionX; 64 positionY = this.value.lightSource.positionY; 65 positionZ = this.value.lightSource.positionZ; 66 intensity = this.value.lightSource.intensity; 67 color = this.value.lightSource.color; 68 } 69 illuminated = this.value.illuminated; 70 bloom = this.value.bloom; 71 getUINativeModule().common.setPointLightStyle(node, positionX, positionY, positionZ, intensity, color, 72 illuminated, bloom); 73 } 74 } 75 checkObjectDiff(): boolean { 76 return !isBaseOrResourceEqual(this.stageValue.lightSource?.positionX, this.value.lightSource?.positionX) || 77 !isBaseOrResourceEqual(this.stageValue.lightSource?.positionY, this.value.lightSource?.positionY) || 78 !isBaseOrResourceEqual(this.stageValue.lightSource?.positionZ, this.value.lightSource?.positionZ) || 79 !isBaseOrResourceEqual(this.stageValue.lightSource?.intensity, this.value.lightSource?.intensity) || 80 !isBaseOrResourceEqual(this.stageValue.lightSource?.color, this.value.lightSource?.color) || 81 !isBaseOrResourceEqual(this.stageValue.illuminated, this.value.illuminated) || 82 !isBaseOrResourceEqual(this.stageValue.bloom, this.value.bloom); 83 } 84} 85 86class StackAlignContentModifier extends ModifierWithKey<number> { 87 constructor(nativePtr: number) { 88 super(nativePtr); 89 } 90 static identity: Symbol = Symbol('stackAlignContent'); 91 applyPeer(node: KNode, reset: boolean): void { 92 if (reset) { 93 getUINativeModule().stack.resetAlignContent(node); 94 } else { 95 getUINativeModule().stack.setAlignContent(node, this.value!); 96 } 97 } 98 checkObjectDiff(): boolean { 99 return this.stageValue !== this.value; 100 } 101} 102// @ts-ignore 103globalThis.Stack.attributeModifier = function (modifier: ArkComponent): void { 104 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 105 return new ArkStackComponent(nativePtr); 106 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 107 return new modifierJS.StackModifier(nativePtr, classType); 108 }); 109}; 110