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