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 ArkProgressComponent extends ArkComponent implements ProgressAttribute { 18 constructor(nativePtr: KNode) { 19 super(nativePtr); 20 } 21 value(value: number): ProgressAttribute<keyof ProgressStyleMap, LinearStyleOptions | 22 ProgressStyleOptions | RingStyleOptions | EclipseStyleOptions | ScaleRingStyleOptions | 23 CapsuleStyleOptions> { 24 modifierWithKey(this._modifiersWithKeys, ProgressValueModifier.identity, ProgressValueModifier, value); 25 return this; 26 } 27 color(value: ResourceColor | LinearGradient): ProgressAttribute<keyof ProgressStyleMap, LinearStyleOptions | 28 ProgressStyleOptions | RingStyleOptions | EclipseStyleOptions | ScaleRingStyleOptions | 29 CapsuleStyleOptions> { 30 modifierWithKey(this._modifiersWithKeys, ProgressColorModifier.identity, ProgressColorModifier, value); 31 return this; 32 } 33 style(value: LinearStyleOptions | ProgressStyleOptions | RingStyleOptions | EclipseStyleOptions | 34 ScaleRingStyleOptions | CapsuleStyleOptions): 35 ProgressAttribute<keyof ProgressStyleMap, LinearStyleOptions | ProgressStyleOptions | 36 RingStyleOptions | EclipseStyleOptions | ScaleRingStyleOptions | CapsuleStyleOptions> { 37 modifierWithKey(this._modifiersWithKeys, ProgressStyleModifier.identity, ProgressStyleModifier, value); 38 return this; 39 } 40 backgroundColor(value: ResourceColor): this { 41 modifierWithKey(this._modifiersWithKeys, ProgressBackgroundColorModifier.identity, ProgressBackgroundColorModifier, value); 42 return this; 43 } 44} 45 46class ProgressValueModifier extends ModifierWithKey<number> { 47 static identity: Symbol = Symbol('value'); 48 applyPeer(node: KNode, reset: boolean): void { 49 if (reset) { 50 getUINativeModule().progress.ResetProgressValue(node); 51 } else { 52 getUINativeModule().progress.SetProgressValue(node, this.value!); 53 } 54 } 55 checkObjectDiff(): boolean { 56 return true; 57 } 58} 59 60class ProgressColorModifier extends ModifierWithKey<ResourceColor | LinearGradient> { 61 static identity: Symbol = Symbol('color'); 62 applyPeer(node: KNode, reset: boolean): void { 63 if (reset) { 64 getUINativeModule().progress.resetProgressColor(node); 65 } else { 66 getUINativeModule().progress.setProgressColor(node, this.value!); 67 } 68 } 69 70 checkObjectDiff(): boolean { 71 return this.stageValue !== this.value; 72 } 73} 74 75class ProgressStyleModifier extends ModifierWithKey<ProgressStyleOptions | CapsuleStyleOptions | 76RingStyleOptions | LinearStyleOptions | ScaleRingStyleOptions | EclipseStyleOptions> { 77 static identity: Symbol = Symbol('style'); 78 applyPeer(node: KNode, reset: boolean): void { 79 if (reset) { 80 getUINativeModule().progress.ResetProgressStyle(node); 81 } else { 82 let strokeWidth = (<ProgressStyleOptions> this.value).strokeWidth; 83 let scaleCount = (<ProgressStyleOptions> this.value).scaleCount; 84 let scaleWidth = (<ProgressStyleOptions> this.value).scaleWidth; 85 let enableSmoothEffect = (<ProgressStyleOptions> this.value).enableSmoothEffect; 86 let borderColor = (<CapsuleStyleOptions> this.value).borderColor; 87 let borderWidth = (<CapsuleStyleOptions> this.value).borderWidth; 88 let content = (<CapsuleStyleOptions> this.value).content; 89 let fontSize; 90 let fontWeight; 91 let fontFamily; 92 let fontStyle; 93 if ((<CapsuleStyleOptions> this.value).font) { 94 fontSize = (<CapsuleStyleOptions> this.value).font.size; 95 fontWeight = (<CapsuleStyleOptions> this.value).font.weight; 96 fontFamily = (<CapsuleStyleOptions> this.value).font.family; 97 fontStyle = (<CapsuleStyleOptions> this.value).font.style; 98 } 99 let fontColor = (<CapsuleStyleOptions> this.value).fontColor; 100 let enableScanEffect = (<CapsuleStyleOptions> this.value).enableScanEffect; 101 let showDefaultPercentage = (<CapsuleStyleOptions> this.value).showDefaultPercentage; 102 let shadow = (<RingStyleOptions> this.value).shadow; 103 let status = (<RingStyleOptions> this.value).status; 104 let strokeRadius = (<LinearStyleOptions> this.value).strokeRadius; 105 getUINativeModule().progress.SetProgressStyle( 106 node, strokeWidth, scaleCount, scaleWidth, enableSmoothEffect, borderColor, 107 borderWidth, content, fontSize, fontWeight, fontFamily, fontStyle, fontColor, 108 enableScanEffect, showDefaultPercentage, shadow, status, strokeRadius 109 ); 110 } 111 } 112 checkObjectDiff(): boolean { 113 return true; 114 } 115} 116 117class ProgressBackgroundColorModifier extends ModifierWithKey<ResourceColor> { 118 static identity: Symbol = Symbol('progressBackgroundColor'); 119 applyPeer(node: KNode, reset: boolean): void { 120 if (reset) { 121 getUINativeModule().progress.resetProgressBackgroundColor(node); 122 } else { 123 getUINativeModule().progress.setProgressBackgroundColor(node, this.value); 124 } 125 } 126 127 checkObjectDiff(): boolean { 128 return !isBaseOrResourceEqual(this.stageValue, this.value); 129 } 130} 131 132// @ts-ignore 133globalThis.Progress.attributeModifier = function (modifier) { 134 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 135 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 136 let component = this.createOrGetNode(elmtId, () => { 137 return new ArkProgressComponent(nativeNode); 138 }); 139 applyUIAttributes(modifier, nativeNode, component); 140 component.applyModifierPatch(); 141}; 142