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 ArkDataPanelComponent extends ArkComponent implements DataPanelAttribute { 18 constructor(nativePtr: KNode) { 19 super(nativePtr); 20 } 21 closeEffect(value: boolean): this { 22 modifierWithKey(this._modifiersWithKeys, DataPanelCloseEffectModifier.identity, DataPanelCloseEffectModifier, value); 23 return this; 24 } 25 valueColors(value: Array<ResourceColor | LinearGradient>): this { 26 modifierWithKey(this._modifiersWithKeys, DataPanelValueColorsModifier.identity, DataPanelValueColorsModifier, value); 27 return this; 28 } 29 trackBackgroundColor(value: any): this { 30 modifierWithKey(this._modifiersWithKeys, DataPanelTrackBackgroundColorModifier.identity, DataPanelTrackBackgroundColorModifier, value); 31 return this; 32 } 33 strokeWidth(value: any): this { 34 modifierWithKey(this._modifiersWithKeys, DataPanelStrokeWidthModifier.identity, DataPanelStrokeWidthModifier, value); 35 return this; 36 } 37 trackShadow(value: DataPanelShadowOptions): this { 38 modifierWithKey(this._modifiersWithKeys, DataPanelTrackShadowModifier.identity, DataPanelTrackShadowModifier, value); 39 return this; 40 } 41} 42 43class DataPanelStrokeWidthModifier extends ModifierWithKey<Length> { 44 static identity: Symbol = Symbol('dataPanelStrokeWidth'); 45 applyPeer(node: KNode, reset: boolean): void { 46 if (reset) { 47 getUINativeModule().dataPanel.resetDataPanelStrokeWidth(node); 48 } else { 49 getUINativeModule().dataPanel.setDataPanelStrokeWidth(node, this.value); 50 } 51 } 52 53 checkObjectDiff(): boolean { 54 return !isBaseOrResourceEqual(this.stageValue, this.value); 55 } 56} 57 58class DataPanelCloseEffectModifier extends ModifierWithKey<boolean> { 59 static identity: Symbol = Symbol('dataPanelCloseEffect'); 60 applyPeer(node: KNode, reset: boolean): void { 61 if (reset) { 62 getUINativeModule().dataPanel.resetCloseEffect(node); 63 } else { 64 getUINativeModule().dataPanel.setCloseEffect(node, this.value); 65 } 66 } 67 68 checkObjectDiff(): boolean { 69 return !isBaseOrResourceEqual(this.stageValue, this.value); 70 } 71} 72 73class DataPanelTrackBackgroundColorModifier extends ModifierWithKey<ResourceColor> { 74 static identity: Symbol = Symbol('dataPanelTrackBackgroundColorModifier'); 75 applyPeer(node: KNode, reset: boolean): void { 76 if (reset) { 77 getUINativeModule().dataPanel.resetDataPanelTrackBackgroundColor(node); 78 } else { 79 getUINativeModule().dataPanel.setDataPanelTrackBackgroundColor(node, this.value); 80 } 81 } 82 83 checkObjectDiff(): boolean { 84 return !isBaseOrResourceEqual(this.stageValue, this.value); 85 } 86} 87class DataPanelTrackShadowModifier extends ModifierWithKey<DataPanelShadowOptions> { 88 static identity = Symbol('dataPanelTrackShadow'); 89 applyPeer(node: KNode, reset: boolean): void { 90 if (reset) { 91 if (this.value === null) { 92 getUINativeModule().dataPanel.setDataPanelTrackShadow(node, null); 93 } 94 getUINativeModule().dataPanel.resetDataPanelTrackShadow(node); 95 } else { 96 getUINativeModule().dataPanel.setDataPanelTrackShadow(node, this.value!); 97 } 98 } 99 checkObjectDiff(): boolean { 100 return true; 101 } 102} 103class DataPanelValueColorsModifier extends ModifierWithKey<Array<ResourceColor | LinearGradient>> { 104 static identity = Symbol('dataPanelValueColors'); 105 applyPeer(node: KNode, reset: boolean): void { 106 if (reset) { 107 getUINativeModule().dataPanel.resetDataPanelValueColors(node); 108 return; 109 } else { 110 getUINativeModule().dataPanel.setDataPanelValueColors(node, this.value!); 111 } 112 } 113 checkObjectDiff(): boolean { 114 return true; 115 } 116} 117// @ts-ignore 118globalThis.DataPanel.attributeModifier = function (modifier) { 119 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 120 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 121 let component = this.createOrGetNode(elmtId, () => { 122 return new ArkDataPanelComponent(nativeNode); 123 }); 124 applyUIAttributes(modifier, nativeNode, component); 125 component.applyModifierPatch(); 126}; 127