• 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 ArkPolygonComponent extends ArkCommonShapeComponent implements PolygonAttribute {
18  points(value: Array<any>): this {
19    modifierWithKey(this._modifiersWithKeys, PolygonPointsModifier.identity, PolygonPointsModifier, value);
20    return this;
21  }
22}
23
24class PolygonPointsModifier extends ModifierWithKey<Array<any>> {
25  constructor(value: Array<any>) {
26    super(value);
27  }
28  static identity: Symbol = Symbol('polygonPoints');
29  applyPeer(node: KNode, reset: boolean): void {
30    let xPoint = [];
31    let yPoint = [];
32    if (Array.isArray(this.value)) {
33      for (let i = 0; i <= this.value.length; i++) {
34        let item = this.value[i];
35        if (!Array.isArray(item)) {
36          continue;
37        }
38
39        if (item.length < ARRAY_LENGTH || isUndefined(item[0]) || isUndefined(item[1])) {
40          reset = true;
41          break;
42        }
43
44        xPoint.push(item[0]);
45        yPoint.push(item[1]);
46      }
47    } else {
48      reset = true;
49    }
50
51    if (reset) {
52      getUINativeModule().polygon.resetPolygonPoints(node);
53    } else {
54      getUINativeModule().polygon.setPolygonPoints(node, xPoint, yPoint);
55    }
56  }
57
58  checkObjectDiff(): boolean {
59    return this.stageValue !== this.value;
60  }
61}
62
63// @ts-ignore
64globalThis.Polygon.attributeModifier = function (modifier) {
65  const elmtId = ViewStackProcessor.GetElmtIdToAccountFor();
66  let nativeNode = getUINativeModule().getFrameNodeById(elmtId);
67  let component = this.createOrGetNode(elmtId, () => {
68    return new ArkPolygonComponent(nativeNode);
69  });
70  applyUIAttributes(modifier, nativeNode, component);
71  component.applyModifierPatch();
72};
73