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 DividerVerticalModifier extends ModifierWithKey<boolean> { 18 constructor(value: boolean) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('dividerVertical'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().divider.resetVertical(node); 25 } else { 26 getUINativeModule().divider.setVertical(node, this.value!); 27 } 28 } 29 checkObjectDiff(): boolean { 30 return this.stageValue !== this.value; 31 } 32} 33class DividerLineCapModifier extends ModifierWithKey<LineCapStyle> { 34 constructor(value: LineCapStyle) { 35 super(value); 36 } 37 static identity: Symbol = Symbol('dividerLineCap'); 38 applyPeer(node: KNode, reset: boolean): void { 39 if (reset) { 40 getUINativeModule().divider.resetLineCap(node); 41 } else { 42 getUINativeModule().divider.setLineCap(node, this.value!); 43 } 44 } 45 checkObjectDiff(): boolean { 46 return this.stageValue !== this.value; 47 } 48} 49class DividerColorModifier extends ModifierWithKey<ResourceColor> { 50 constructor(value: ResourceColor) { 51 super(value); 52 } 53 static identity: Symbol = Symbol('dividerColor'); 54 applyPeer(node: KNode, reset: boolean): void { 55 if (reset) { 56 getUINativeModule().divider.resetColor(node); 57 } else { 58 getUINativeModule().divider.setColor(node, this.value!); 59 } 60 } 61 checkObjectDiff(): boolean { 62 return !isBaseOrResourceEqual(this.stageValue, this.value); 63 } 64} 65class DividerStrokeWidthModifier extends ModifierWithKey<number | string> { 66 constructor(value: number | string) { 67 super(value); 68 } 69 static identity: Symbol = Symbol('dividerStrokeWidth'); 70 applyPeer(node: KNode, reset: boolean): void { 71 if (reset) { 72 getUINativeModule().divider.resetStrokeWidth(node); 73 } else { 74 getUINativeModule().divider.setStrokeWidth(node, this.value!); 75 } 76 } 77 checkObjectDiff(): boolean { 78 return this.stageValue !== this.value; 79 } 80} 81class ArkDividerComponent extends ArkComponent implements DividerAttribute { 82 constructor(nativePtr: KNode, classType?: ModifierType) { 83 super(nativePtr, classType); 84 } 85 initialize(value: Object[]): DividerAttribute { 86 return this; 87 } 88 allowChildCount(): number { 89 return 0; 90 } 91 vertical(value: boolean): DividerAttribute { 92 modifierWithKey(this._modifiersWithKeys, DividerVerticalModifier.identity, DividerVerticalModifier, value); 93 return this; 94 } 95 color(value: ResourceColor): DividerAttribute { 96 modifierWithKey(this._modifiersWithKeys, DividerColorModifier.identity, DividerColorModifier, value); 97 return this; 98 } 99 strokeWidth(value: number | string): DividerAttribute { 100 modifierWithKey(this._modifiersWithKeys, DividerStrokeWidthModifier.identity, DividerStrokeWidthModifier, value); 101 return this; 102 } 103 lineCap(value: LineCapStyle): DividerAttribute { 104 modifierWithKey(this._modifiersWithKeys, DividerLineCapModifier.identity, DividerLineCapModifier, value); 105 return this; 106 } 107} 108// @ts-ignore 109globalThis.Divider.attributeModifier = function (modifier: ArkComponent): void { 110 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 111 return new ArkDividerComponent(nativePtr); 112 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 113 return new modifierJS.DividerModifier(nativePtr, classType); 114 }); 115}; 116