• 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 RelativeContainerGuideLineModifier extends ModifierWithKey<ArkRelativeContainerGuideLine> {
18  constructor(value: ArkRelativeContainerGuideLine) {
19    super(value);
20  }
21  static identity: Symbol = Symbol('relativeContainerGuideLine');
22  applyPeer(node: KNode, reset: boolean): void {
23    if (reset) {
24      getUINativeModule().relativeContainer.resetGuideLine(node);
25    } else {
26      getUINativeModule().relativeContainer.setGuideLine(node,
27        this.value.ids, this.value.directions, this.value.positions);
28    }
29  }
30  checkObjectDiff(): boolean {
31    return !isBaseOrResourceEqual(this.stageValue.ids, this.value.ids) ||
32      !isBaseOrResourceEqual(this.stageValue.directions, this.value.directions) ||
33      !isBaseOrResourceEqual(this.stageValue.positions, this.value.positions);
34  }
35}
36
37class RelativeContainerBarrierModifier extends ModifierWithKey<ArkRelativeContainerBarrier> {
38  constructor(value: ArkRelativeContainerBarrier) {
39    super(value);
40  }
41  static identity: Symbol = Symbol('relativeContainerBarrier');
42  applyPeer(node: KNode, reset: boolean): void {
43    if (reset) {
44      getUINativeModule().relativeContainer.resetBarrier(node);
45    } else {
46      getUINativeModule().relativeContainer.setBarrier(node,
47        this.value.ids, this.value.directions, this.value.referencedIds);
48    }
49  }
50  checkObjectDiff(): boolean {
51    return !isBaseOrResourceEqual(this.stageValue.ids, this.value.ids) ||
52      !isBaseOrResourceEqual(this.stageValue.directions, this.value.directions) ||
53      !isBaseOrResourceEqual(this.stageValue.referencedIds, this.value.referencedIds);
54  }
55}
56
57class ArkRelativeContainerComponent extends ArkComponent implements RelativeContainerAttribute {
58  constructor(nativePtr: KNode, classType?: ModifierType) {
59    super(nativePtr, classType);
60  }
61  initialize(value: Object[]): RelativeContainerAttribute {
62    return this;
63  }
64  guideLine(value: Array<GuideLineStyle>): RelativeContainerAttribute {
65    let guideLineInfo = new ArkRelativeContainerGuideLine();
66    guideLineInfo.ids = value.map(item => { return item.id; });
67    guideLineInfo.directions = value.map(item => { return item.direction; });
68    guideLineInfo.positions = new Array<Dimension>();
69    for (let i = 0; i < value.length; i++) {
70      guideLineInfo.positions.push(value[i].position.start);
71      guideLineInfo.positions.push(value[i].position.end);
72    }
73    modifierWithKey(this._modifiersWithKeys, RelativeContainerGuideLineModifier.identity, RelativeContainerGuideLineModifier, guideLineInfo);
74    return this;
75  }
76  barrier(value: Array<BarrierStyle>): RelativeContainerAttribute {
77    let barrierInfo = new ArkRelativeContainerBarrier();
78    barrierInfo.ids = value.map(item => { return item.id; });
79    barrierInfo.directions = value.map(item => { return item.direction; });
80    barrierInfo.referencedIds = value.map(item => { return item.referencedId; });
81    modifierWithKey(this._modifiersWithKeys, RelativeContainerBarrierModifier.identity, RelativeContainerBarrierModifier, barrierInfo);
82    return this;
83  }
84}
85
86// @ts-ignore
87globalThis.RelativeContainer.attributeModifier = function (modifier: ArkComponent): void {
88  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
89    return new ArkRelativeContainerComponent(nativePtr);
90  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
91    return new modifierJS.RelativeContainerModifier(nativePtr, classType);
92  });
93};
94