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) { 83 super(nativePtr); 84 } 85 vertical(value: boolean): DividerAttribute { 86 modifierWithKey(this._modifiersWithKeys, DividerVerticalModifier.identity, DividerVerticalModifier, value); 87 return this; 88 } 89 color(value: ResourceColor): DividerAttribute { 90 modifierWithKey(this._modifiersWithKeys, DividerColorModifier.identity, DividerColorModifier, value); 91 return this; 92 } 93 strokeWidth(value: number | string): DividerAttribute { 94 modifierWithKey(this._modifiersWithKeys, DividerStrokeWidthModifier.identity, DividerStrokeWidthModifier, value); 95 return this; 96 } 97 lineCap(value: LineCapStyle): DividerAttribute { 98 modifierWithKey(this._modifiersWithKeys, DividerLineCapModifier.identity, DividerLineCapModifier, value); 99 return this; 100 } 101} 102// @ts-ignore 103globalThis.Divider.attributeModifier = function (modifier) { 104 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 105 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 106 107 let component = this.createOrGetNode(elmtId, () => { 108 return new ArkDividerComponent(nativeNode); 109 }); 110 applyUIAttributes(modifier, nativeNode, component); 111 component.applyModifierPatch(); 112}; 113