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