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