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' /> 18class ArkLineComponent extends ArkCommonShapeComponent implements LineAttribute { 19 constructor(nativePtr: KNode, classType?: ModifierType) { 20 super(nativePtr, classType); 21 } 22 startPoint(value: Array<Length>): this { 23 modifierWithKey(this._modifiersWithKeys, LineStartPointModifier.identity, LineStartPointModifier, value); 24 return this; 25 } 26 endPoint(value: Array<Length>): this { 27 modifierWithKey(this._modifiersWithKeys, LineEndPointModifier.identity, LineEndPointModifier, value); 28 return this; 29 } 30} 31 32class LineStartPointModifier extends ModifierWithKey<object> { 33 constructor(value: object) { 34 super(value); 35 } 36 static identity: Symbol = Symbol('startPoint'); 37 applyPeer(node: KNode, reset: boolean): void { 38 if (reset) { 39 getUINativeModule().line.resetStartPoint(node); 40 } else { 41 getUINativeModule().line.setStartPoint(node, this.value); 42 } 43 } 44 45 checkObjectDiff(): boolean { 46 return this.stageValue !== this.value; 47 } 48} 49 50class LineEndPointModifier extends ModifierWithKey<object> { 51 constructor(value: object) { 52 super(value); 53 } 54 static identity: Symbol = Symbol('endPoint'); 55 applyPeer(node: KNode, reset: boolean): void { 56 if (reset) { 57 getUINativeModule().line.resetEndPoint(node); 58 } else { 59 getUINativeModule().line.setEndPoint(node, this.value); 60 } 61 } 62 63 checkObjectDiff(): boolean { 64 return this.stageValue !== this.value; 65 } 66} 67 68// @ts-ignore 69globalThis.Line.attributeModifier = function (modifier: ArkComponent): void { 70 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 71 return new ArkLineComponent(nativePtr); 72 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 73 return new modifierJS.LineModifier(nativePtr, classType); 74 }); 75}; 76