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