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 FlexInitializeModifier extends ModifierWithKey<FlexParam> { 18 constructor(value: FlexParam) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('flexInitialize'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().flex.resetFlexInitialize(node); 25 } else { 26 getUINativeModule().flex.setFlexInitialize(node, this.value.direction, this.value.wrap, 27 this.value.justifyContent, this.value.alignItems, this.value.alignContent, this.value?.space?.main, 28 this.value?.space?.cross); 29 } 30} 31interface FlexParam { 32 direction?: FlexDirection; 33 wrap?: FlexWrap; 34 justifyContent?: FlexAlign; 35 alignItems?: ItemAlign; 36 alignContent?: FlexAlign; 37 space?: FlexSpaceOptions; 38} 39class ArkFlexComponent extends ArkComponent implements FlexAttribute { 40 constructor(nativePtr: KNode, classType?: ModifierType) { 41 super(nativePtr, classType); 42 } 43 pointLight(value: PointLightStyle): this { 44 modifierWithKey(this._modifiersWithKeys, FlexPointLightModifier.identity, FlexPointLightModifier, value); 45 return this; 46 } 47 initialize(value: Object[]): FlexAttribute { 48 if (value[0] !== undefined) { 49 modifierWithKey(this._modifiersWithKeys, FlexInitializeModifier.identity, 50 FlexInitializeModifier, (value[0] as FlexParam)); 51 } 52 } 53} 54 55class FlexPointLightModifier extends ModifierWithKey<PointLightStyle> { 56 constructor(value: PointLightStyle) { 57 super(value); 58 } 59 static identity: Symbol = Symbol('flexPointLight'); 60 applyPeer(node: KNode, reset: boolean): void { 61 if (reset) { 62 getUINativeModule().common.resetPointLightStyle(node); 63 } else { 64 let positionX: Dimension | undefined; 65 let positionY: Dimension | undefined; 66 let positionZ: Dimension | undefined; 67 let intensity: number | undefined; 68 let color: ResourceColor | undefined; 69 let illuminated: number | undefined; 70 let bloom: number | undefined; 71 if (!isUndefined(this.value.lightSource) && this.value.lightSource != null) { 72 positionX = this.value.lightSource.positionX; 73 positionY = this.value.lightSource.positionY; 74 positionZ = this.value.lightSource.positionZ; 75 intensity = this.value.lightSource.intensity; 76 color = this.value.lightSource.color; 77 } 78 illuminated = this.value.illuminated; 79 bloom = this.value.bloom; 80 getUINativeModule().common.setPointLightStyle(node, positionX, positionY, positionZ, intensity, color, 81 illuminated, bloom); 82 } 83 } 84 checkObjectDiff(): boolean { 85 return !isBaseOrResourceEqual(this.stageValue.lightSource?.positionX, this.value.lightSource?.positionX) || 86 !isBaseOrResourceEqual(this.stageValue.lightSource?.positionY, this.value.lightSource?.positionY) || 87 !isBaseOrResourceEqual(this.stageValue.lightSource?.positionZ, this.value.lightSource?.positionZ) || 88 !isBaseOrResourceEqual(this.stageValue.lightSource?.intensity, this.value.lightSource?.intensity) || 89 !isBaseOrResourceEqual(this.stageValue.lightSource?.color, this.value.lightSource?.color) || 90 !isBaseOrResourceEqual(this.stageValue.illuminated, this.value.illuminated) || 91 !isBaseOrResourceEqual(this.stageValue.bloom, this.value.bloom); 92 } 93} 94 95// @ts-ignore 96globalThis.Flex.attributeModifier = function (modifier: ArkComponent): void { 97 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 98 return new ArkFlexComponent(nativePtr); 99 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 100 return new modifierJS.FlexModifier(nativePtr, classType); 101 }); 102}; 103