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 ColumnAlignItemsModifier extends ModifierWithKey<number> { 18 static identity: Symbol = Symbol('columnAlignItems'); 19 applyPeer(node: KNode, reset: boolean): void { 20 if (reset) { 21 getUINativeModule().column.resetAlignItems(node); 22 } else { 23 getUINativeModule().column.setAlignItems(node, this.value!); 24 } 25 } 26 checkObjectDiff(): boolean { 27 return this.stageValue !== this.value; 28 } 29} 30 31class ColumnJustifyContentModifier extends ModifierWithKey<number> { 32 static identity: Symbol = Symbol('columnJustifyContent'); 33 applyPeer(node: KNode, reset: boolean): void { 34 if (reset) { 35 getUINativeModule().column.resetJustifyContent(node); 36 } else { 37 getUINativeModule().column.setJustifyContent(node, this.value!); 38 } 39 } 40 checkObjectDiff(): boolean { 41 return this.stageValue !== this.value; 42 } 43} 44 45class ColumnSpaceModifier extends ModifierWithKey<string | number> { 46 constructor(value: string | number) { 47 super(value); 48 } 49 static identity:Symbol = Symbol('columnSpace'); 50 applyPeer(node: KNode, reset: boolean): void { 51 if (reset) { 52 getUINativeModule().column.resetSpace(node); 53 } 54 else { 55 getUINativeModule().column.setSpace(node, this.value); 56 } 57 } 58 checkObjectDiff() : boolean { 59 return this.stageValue !== this.value; 60 } 61} 62class ColumnPointLightModifier extends ModifierWithKey<PointLightStyle> { 63 constructor(value: PointLightStyle) { 64 super(value); 65 } 66 static identity: Symbol = Symbol('columnPointLight'); 67 applyPeer(node: KNode, reset: boolean): void { 68 if (reset) { 69 getUINativeModule().common.resetPointLightStyle(node); 70 } else { 71 let positionX: Dimension | undefined; 72 let positionY: Dimension | undefined; 73 let positionZ: Dimension | undefined; 74 let intensity: number | undefined; 75 let color: ResourceColor | undefined; 76 let illuminated: number | undefined; 77 let bloom: number | undefined; 78 if (!isUndefined(this.value.lightSource) && this.value.lightSource != null) { 79 positionX = this.value.lightSource.positionX; 80 positionY = this.value.lightSource.positionY; 81 positionZ = this.value.lightSource.positionZ; 82 intensity = this.value.lightSource.intensity; 83 color = this.value.lightSource.color; 84 } 85 illuminated = this.value.illuminated; 86 bloom = this.value.bloom; 87 getUINativeModule().common.setPointLightStyle(node, positionX, positionY, positionZ, intensity, color, 88 illuminated, bloom); 89 } 90 } 91 checkObjectDiff(): boolean { 92 return !isBaseOrResourceEqual(this.stageValue.lightSource?.positionX, this.value.lightSource?.positionX) || 93 !isBaseOrResourceEqual(this.stageValue.lightSource?.positionY, this.value.lightSource?.positionY) || 94 !isBaseOrResourceEqual(this.stageValue.lightSource?.positionZ, this.value.lightSource?.positionZ) || 95 !isBaseOrResourceEqual(this.stageValue.lightSource?.intensity, this.value.lightSource?.intensity) || 96 !isBaseOrResourceEqual(this.stageValue.lightSource?.color, this.value.lightSource?.color) || 97 !isBaseOrResourceEqual(this.stageValue.illuminated, this.value.illuminated) || 98 !isBaseOrResourceEqual(this.stageValue.bloom, this.value.bloom); 99 } 100} 101 102class ColumnReverseModifier extends ModifierWithKey<boolean> { 103 constructor(value: boolean) { 104 super(value); 105 } 106 static identity: Symbol = Symbol('columnReverse'); 107 applyPeer(node: KNode, reset: boolean): void { 108 if (reset) { 109 getUINativeModule().column.resetReverse(node); 110 } else { 111 getUINativeModule().column.setReverse(node, this.value); 112 } 113 } 114 checkObjectDiff(): boolean { 115 return this.stageValue !== this.value; 116 } 117} 118 119interface ColumnParam { 120 space: string | number; 121} 122class ArkColumnComponent extends ArkComponent implements CommonMethod<ColumnAttribute> { 123 constructor(nativePtr: KNode, classType?: ModifierType) { 124 super(nativePtr, classType); 125 } 126 initialize(value: Object[]): ColumnAttribute { 127 if (value[0] !== undefined) { 128 modifierWithKey(this._modifiersWithKeys, ColumnSpaceModifier.identity, ColumnSpaceModifier, (value[0] as ColumnParam).space); 129 } 130 return this 131 } 132 alignItems(value: HorizontalAlign): ColumnAttribute { 133 modifierWithKey(this._modifiersWithKeys, ColumnAlignItemsModifier.identity, ColumnAlignItemsModifier, value); 134 return this; 135 } 136 justifyContent(value: FlexAlign): ColumnAttribute { 137 modifierWithKey(this._modifiersWithKeys, ColumnJustifyContentModifier.identity, ColumnJustifyContentModifier, value); 138 return this; 139 } 140 pointLight(value: PointLightStyle): ColumnAttribute { 141 modifierWithKey(this._modifiersWithKeys, ColumnPointLightModifier.identity, ColumnPointLightModifier, value); 142 return this; 143 } 144 reverse(value: boolean | undefined): ColumnAttribute { 145 modifierWithKey(this._modifiersWithKeys, ColumnReverseModifier.identity, ColumnReverseModifier, value); 146 return this; 147 } 148} 149// @ts-ignore 150globalThis.Column.attributeModifier = function (modifier: ArkComponent): void { 151 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 152 return new ArkColumnComponent(nativePtr); 153 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 154 return new modifierJS.ColumnModifier(nativePtr, classType); 155 }); 156}; 157