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