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