• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 #include "bridge/declarative_frontend/jsview/js_progress.h"
17 
18 #include "base/utils/utils.h"
19 #include "bridge/declarative_frontend/jsview/js_interactable_view.h"
20 #include "bridge/declarative_frontend/jsview/js_linear_gradient.h"
21 #include "bridge/declarative_frontend/jsview/models/progress_model_impl.h"
22 #include "core/components/common/properties/color.h"
23 #include "core/components/progress/progress_theme.h"
24 #include "core/components/text/text_theme.h"
25 #include "core/components_ng/pattern/progress/progress_model_ng.h"
26 
27 namespace OHOS::Ace {
28 
29 std::unique_ptr<ProgressModel> ProgressModel::instance_ = nullptr;
30 std::mutex ProgressModel::mutex_;
31 ProgressType g_progressType = ProgressType::LINEAR;
32 
GetInstance()33 ProgressModel* ProgressModel::GetInstance()
34 {
35     if (!instance_) {
36         std::lock_guard<std::mutex> lock(mutex_);
37         if (!instance_) {
38 #ifdef NG_BUILD
39             instance_.reset(new NG::ProgressModelNG());
40 #else
41             if (Container::IsCurrentUseNewPipeline()) {
42                 instance_.reset(new NG::ProgressModelNG());
43             } else {
44                 instance_.reset(new Framework::ProgressModelImpl());
45             }
46 #endif
47         }
48     }
49     return instance_.get();
50 }
51 
52 } // namespace OHOS::Ace
53 
54 namespace OHOS::Ace::Framework {
Create(const JSCallbackInfo & info)55 void JSProgress::Create(const JSCallbackInfo& info)
56 {
57     if (!info[0]->IsObject()) {
58         return;
59     }
60     auto paramObject = JSRef<JSObject>::Cast(info[0]);
61 
62     auto value = 0;
63     auto jsValue = paramObject->GetProperty("value");
64     if (jsValue->IsNumber()) {
65         value = jsValue->ToNumber<double>();
66     }
67 
68     auto total = 100;
69     auto jsTotal = paramObject->GetProperty("total");
70     if (jsTotal->IsNumber() && jsTotal->ToNumber<int>() > 0) {
71         total = jsTotal->ToNumber<int>();
72     }
73 
74     if (value > total) {
75         value = total;
76     } else if (value < 0) {
77         value = 0;
78     }
79 
80     auto jsStyle = paramObject->GetProperty("type");
81     if (jsStyle->IsNull() || jsStyle->IsUndefined()) {
82         jsStyle = paramObject->GetProperty("style");
83     }
84 
85     auto progressStyle = static_cast<ProgressStyle>(jsStyle->ToNumber<int32_t>());
86     if (progressStyle == ProgressStyle::Eclipse) {
87         g_progressType = ProgressType::MOON;
88     } else if (progressStyle == ProgressStyle::Ring) {
89         g_progressType = ProgressType::RING;
90     } else if (progressStyle == ProgressStyle::ScaleRing) {
91         g_progressType = ProgressType::SCALE;
92     } else if (progressStyle == ProgressStyle::Capsule) {
93         g_progressType = ProgressType::CAPSULE;
94     } else {
95         g_progressType = ProgressType::LINEAR;
96     }
97 
98     ProgressModel::GetInstance()->Create(0.0, value, 0.0, total, static_cast<NG::ProgressType>(g_progressType));
99 }
100 
JSBind(BindingTarget globalObj)101 void JSProgress::JSBind(BindingTarget globalObj)
102 {
103     JSClass<JSProgress>::Declare("Progress");
104     MethodOptions opt = MethodOptions::NONE;
105 
106     JSClass<JSProgress>::StaticMethod("create", &JSProgress::Create, opt);
107     JSClass<JSProgress>::StaticMethod("value", &JSProgress::SetValue, opt);
108     JSClass<JSProgress>::StaticMethod("color", &JSProgress::SetColor, opt);
109     JSClass<JSProgress>::StaticMethod("style", &JSProgress::SetCircularStyle, opt);
110     JSClass<JSProgress>::StaticMethod("backgroundColor", &JSProgress::JsBackgroundColor, opt);
111     JSClass<JSProgress>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
112     JSClass<JSProgress>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
113     JSClass<JSProgress>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
114     JSClass<JSProgress>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
115     JSClass<JSProgress>::StaticMethod("onAttach", &JSInteractableView::JsOnAttach);
116     JSClass<JSProgress>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
117     JSClass<JSProgress>::StaticMethod("onDetach", &JSInteractableView::JsOnDetach);
118     JSClass<JSProgress>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
119     JSClass<JSProgress>::StaticMethod("borderColor", &JSProgress::JsBorderColor, opt);
120     JSClass<JSProgress>::InheritAndBind<JSViewAbstract>(globalObj);
121 }
122 
SetValue(double value)123 void JSProgress::SetValue(double value)
124 {
125     if (std::isnan(value)) {
126         return;
127     }
128     if (value < 0) {
129         value = 0;
130     }
131     ProgressModel::GetInstance()->SetValue(value);
132 }
133 
SetColor(const JSCallbackInfo & info)134 void JSProgress::SetColor(const JSCallbackInfo& info)
135 {
136     Color colorVal;
137     NG::Gradient gradient;
138     RefPtr<ProgressTheme> theme = GetTheme<ProgressTheme>();
139     if (ConvertGradientColor(info[0], gradient)) {
140         ProgressModel::GetInstance()->SetGradientColor(gradient);
141     } else {
142         Color endColor;
143         Color beginColor;
144         if (info[0]->IsNull() || info[0]->IsUndefined() || !ParseJsColor(info[0], colorVal)) {
145             endColor = theme->GetRingProgressEndSideColor();
146             beginColor = theme->GetRingProgressBeginSideColor();
147             if (g_progressType == ProgressType::CAPSULE) {
148                 colorVal = theme->GetCapsuleParseFailedSelectColor();
149             } else {
150                 colorVal = theme->GetTrackParseFailedSelectedColor();
151             }
152         } else {
153             endColor = colorVal;
154             beginColor = colorVal;
155         }
156 
157         NG::GradientColor endSideColor;
158         NG::GradientColor beginSideColor;
159         endSideColor.SetLinearColor(LinearColor(endColor));
160         endSideColor.SetDimension(Dimension(0.0f));
161         beginSideColor.SetLinearColor(LinearColor(beginColor));
162         beginSideColor.SetDimension(Dimension(1.0f));
163         gradient.AddColor(endSideColor);
164         gradient.AddColor(beginSideColor);
165         ProgressModel::GetInstance()->SetGradientColor(gradient);
166         ProgressModel::GetInstance()->SetColor(colorVal);
167     }
168 }
169 
SetCircularStyle(const JSCallbackInfo & info)170 void JSProgress::SetCircularStyle(const JSCallbackInfo& info)
171 {
172     if (!info[0]->IsObject()) {
173         return;
174     }
175 
176     if (Container::LessThanAPIVersion(PlatformVersion::VERSION_TEN)) {
177         JsSetProgressStyleOptions(info);
178         return;
179     }
180 
181     JsSetCommonOptions(info);
182 
183     switch (g_progressType) {
184         case ProgressType::LINEAR:
185             JsSetLinearStyleOptions(info);
186             break;
187         case ProgressType::RING:
188             JsSetRingStyleOptions(info);
189             break;
190         case ProgressType::CAPSULE:
191             JsSetCapsuleStyle(info);
192             break;
193         default:
194             JsSetProgressStyleOptions(info);
195             break;
196     }
197 }
198 
JsSetProgressStyleOptions(const JSCallbackInfo & info)199 void JSProgress::JsSetProgressStyleOptions(const JSCallbackInfo& info)
200 {
201     static const char attrsProgressStrokeWidth[] = "strokeWidth";
202     static const char attrsProgressScaleWidth[] = "scaleWidth";
203     auto paramObject = JSRef<JSObject>::Cast(info[0]);
204     RefPtr<ProgressTheme> theme = GetTheme<ProgressTheme>();
205     CHECK_NULL_VOID(theme);
206 
207     CalcDimension strokeWidthDimension;
208     auto jsStrokeWidth = paramObject->GetProperty(attrsProgressStrokeWidth);
209     if (!CheckLength(jsStrokeWidth, strokeWidthDimension, V2::PROGRESS_ETS_TAG, attrsProgressStrokeWidth)) {
210         strokeWidthDimension = theme->GetTrackThickness();
211     }
212 
213     if (strokeWidthDimension.Value() <= 0.0 || strokeWidthDimension.Unit() == DimensionUnit::PERCENT) {
214         strokeWidthDimension = theme->GetTrackThickness();
215     }
216 
217     ProgressModel::GetInstance()->SetStrokeWidth(strokeWidthDimension);
218 
219     auto jsScaleCount = paramObject->GetProperty("scaleCount");
220     auto scaleCount = jsScaleCount->IsNumber() ? jsScaleCount->ToNumber<int32_t>() : theme->GetScaleNumber();
221     if (scaleCount > 1.0) {
222         ProgressModel::GetInstance()->SetScaleCount(scaleCount);
223     } else {
224         ProgressModel::GetInstance()->SetScaleCount(theme->GetScaleNumber());
225     }
226 
227     CalcDimension scaleWidthDimension;
228     auto jsScaleWidth = paramObject->GetProperty(attrsProgressScaleWidth);
229     if (!CheckLength(jsScaleWidth, scaleWidthDimension, V2::PROGRESS_ETS_TAG, attrsProgressScaleWidth)) {
230         scaleWidthDimension = theme->GetScaleWidth();
231     }
232 
233     if ((scaleWidthDimension.Value() <= 0.0) || (scaleWidthDimension.Value() > strokeWidthDimension.Value()) ||
234         scaleWidthDimension.Unit() == DimensionUnit::PERCENT) {
235         scaleWidthDimension = theme->GetScaleWidth();
236     }
237 
238     ProgressModel::GetInstance()->SetScaleWidth(scaleWidthDimension);
239 }
240 
ConvertStrToProgressStatus(const std::string & value)241 NG::ProgressStatus JSProgress::ConvertStrToProgressStatus(const std::string& value)
242 {
243     if (value.compare("LOADING") == 0) {
244         return NG::ProgressStatus::LOADING;
245     } else {
246         return NG::ProgressStatus::PROGRESSING;
247     }
248 }
249 
JsSetRingStyleOptions(const JSCallbackInfo & info)250 void JSProgress::JsSetRingStyleOptions(const JSCallbackInfo& info)
251 {
252     auto paramObject = JSRef<JSObject>::Cast(info[0]);
253     RefPtr<ProgressTheme> theme = GetTheme<ProgressTheme>();
254 
255     // Parse stroke width
256     CalcDimension strokeWidthDimension;
257     auto versionTenOrLarger = Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN);
258     auto strokeWidth = paramObject->GetProperty("strokeWidth");
259     if (strokeWidth->IsUndefined() || strokeWidth->IsNull() ||
260         (versionTenOrLarger ? !ParseJsDimensionVpNG(strokeWidth, strokeWidthDimension)
261                             : !ParseJsDimensionVp(strokeWidth, strokeWidthDimension))) {
262         strokeWidthDimension = theme->GetTrackThickness();
263     }
264 
265     if (LessOrEqual(strokeWidthDimension.Value(), 0.0f) || strokeWidthDimension.Unit() == DimensionUnit::PERCENT) {
266         strokeWidthDimension = theme->GetTrackThickness();
267     }
268 
269     ProgressModel::GetInstance()->SetStrokeWidth(strokeWidthDimension);
270 
271     // Parse shadow
272     bool paintShadow = false;
273     auto shadow = paramObject->GetProperty("shadow");
274     if (shadow->IsUndefined() || shadow->IsNull() || !ParseJsBool(shadow, paintShadow)) {
275         paintShadow = false;
276     }
277 
278     ProgressModel::GetInstance()->SetPaintShadow(paintShadow);
279 
280     // Parse progress status
281     std::string statusStr;
282     NG::ProgressStatus progressStatus;
283     auto status = paramObject->GetProperty("status");
284     if (status->IsUndefined() || status->IsNull() || !ParseJsString(status, statusStr)) {
285         progressStatus = NG::ProgressStatus::PROGRESSING;
286     } else {
287         progressStatus = ConvertStrToProgressStatus(statusStr);
288     }
289 
290     ProgressModel::GetInstance()->SetProgressStatus(static_cast<NG::ProgressStatus>(progressStatus));
291 
292     auto jsSweepingEffect = paramObject->GetProperty("enableScanEffect");
293     bool sweepingEffect = false;
294     if (!ParseJsBool(jsSweepingEffect, sweepingEffect)) {
295         sweepingEffect = false;
296     }
297     ProgressModel::GetInstance()->SetRingSweepingEffect(sweepingEffect);
298 }
299 
JsBackgroundColor(const JSCallbackInfo & info)300 void JSProgress::JsBackgroundColor(const JSCallbackInfo& info)
301 {
302     Color colorVal;
303     if (!CheckColor(info[0], colorVal, V2::PROGRESS_ETS_TAG, V2::ATTRS_COMMON_BACKGROUND_COLOR)) {
304         RefPtr<ProgressTheme> theme = GetTheme<ProgressTheme>();
305         CHECK_NULL_VOID(theme);
306         if (g_progressType == ProgressType::CAPSULE) {
307             colorVal = theme->GetCapsuleParseFailedBgColor();
308         } else if (g_progressType == ProgressType::RING) {
309             colorVal = theme->GetRingProgressParseFailedBgColor();
310         } else {
311             colorVal = theme->GetTrackParseFailedBgColor();
312         }
313     }
314 
315     ProgressModel::GetInstance()->SetBackgroundColor(colorVal);
316 }
317 
JsBorderColor(const JSCallbackInfo & info)318 void JSProgress::JsBorderColor(const JSCallbackInfo& info)
319 {
320     JSViewAbstract::JsBorderColor(info);
321 }
322 
JsSetCapsuleStyle(const JSCallbackInfo & info)323 void JSProgress::JsSetCapsuleStyle(const JSCallbackInfo& info)
324 {
325     if (!info[0]->IsObject()) {
326         return;
327     }
328     auto paramObject = JSRef<JSObject>::Cast(info[0]);
329     RefPtr<ProgressTheme> theme = GetTheme<ProgressTheme>();
330 
331     auto jsBorderWidth = paramObject->GetProperty("borderWidth");
332     CalcDimension borderWidth;
333     if (!ParseJsDimensionVpNG(jsBorderWidth, borderWidth)) {
334         borderWidth = theme->GetBorderWidth();
335     }
336     if (LessNotEqual(borderWidth.Value(), 0.0) || borderWidth.Unit() == DimensionUnit::PERCENT) {
337         borderWidth = theme->GetBorderWidth();
338     }
339     ProgressModel::GetInstance()->SetBorderWidth(borderWidth);
340 
341     auto jsBorderColor = paramObject->GetProperty("borderColor");
342     Color colorVal;
343     if (ParseJsColor(jsBorderColor, colorVal)) {
344         ProgressModel::GetInstance()->SetBorderColor(colorVal);
345     } else {
346         ProgressModel::GetInstance()->ResetBorderColor();
347     }
348 
349     auto jsSweepingEffect = paramObject->GetProperty("enableScanEffect");
350     bool sweepingEffect = false;
351     if (!ParseJsBool(jsSweepingEffect, sweepingEffect)) {
352         sweepingEffect = false;
353     }
354     ProgressModel::GetInstance()->SetSweepingEffect(sweepingEffect);
355 
356     auto jsShowDefaultPercentage = paramObject->GetProperty("showDefaultPercentage");
357     bool showDefaultPercentage = false;
358     if (!ParseJsBool(jsShowDefaultPercentage, showDefaultPercentage)) {
359         showDefaultPercentage = false;
360     }
361     ProgressModel::GetInstance()->SetShowText(showDefaultPercentage);
362 
363     auto jsContext = paramObject->GetProperty("content");
364     std::string text;
365     if (jsContext->IsUndefined() || jsContext->IsNull() || (!ParseJsString(jsContext, text))) {
366         ProgressModel::GetInstance()->SetText(std::nullopt);
367     } else {
368         ProgressModel::GetInstance()->SetText(text);
369     }
370 
371     JsSetFontStyle(info);
372     JsSetBorderRadius(paramObject);
373 }
374 
JsSetCommonOptions(const JSCallbackInfo & info)375 void JSProgress::JsSetCommonOptions(const JSCallbackInfo& info)
376 {
377     auto paramObject = JSRef<JSObject>::Cast(info[0]);
378 
379     // Parse smooth effect
380     auto jsSmoothEffect = paramObject->GetProperty("enableSmoothEffect");
381     bool enable = true;
382     if (!ParseJsBool(jsSmoothEffect, enable)) {
383         enable = true;
384     }
385     ProgressModel::GetInstance()->SetSmoothEffect(enable);
386 }
387 
JsSetFontStyle(const JSCallbackInfo & info)388 void JSProgress::JsSetFontStyle(const JSCallbackInfo& info)
389 {
390     auto paramObject = JSRef<JSObject>::Cast(info[0]);
391     auto jsFontColor = paramObject->GetProperty("fontColor");
392     Color fontColorVal;
393     if (!ParseJsColor(jsFontColor, fontColorVal)) {
394         ProgressModel::GetInstance()->ResetFontColor();
395     } else {
396         ProgressModel::GetInstance()->SetFontColor(fontColorVal);
397     }
398 
399     auto textStyle = paramObject->GetProperty("font");
400     if (!textStyle->IsObject()) {
401         JsSetFontDefault();
402     } else {
403         auto textObject = JSRef<JSObject>::Cast(textStyle);
404         JsSetFont(textObject);
405     }
406 }
407 
JsSetFontDefault()408 void JSProgress::JsSetFontDefault()
409 {
410     RefPtr<TextTheme> textTheme = GetTheme<TextTheme>();
411     RefPtr<ProgressTheme> progressTheme = GetTheme<ProgressTheme>();
412     ProgressModel::GetInstance()->SetFontSize(progressTheme->GetTextSize());
413     ProgressModel::GetInstance()->SetFontFamily(textTheme->GetTextStyle().GetFontFamilies());
414     ProgressModel::GetInstance()->SetFontWeight(textTheme->GetTextStyle().GetFontWeight());
415     ProgressModel::GetInstance()->SetItalicFontStyle(textTheme->GetTextStyle().GetFontStyle());
416 }
417 
JsSetFont(const JSRef<JSObject> & textObject)418 void JSProgress::JsSetFont(const JSRef<JSObject>& textObject)
419 {
420     RefPtr<ProgressTheme> theme = GetTheme<ProgressTheme>();
421     CHECK_NULL_VOID(theme);
422     RefPtr<TextTheme> textTheme = GetTheme<TextTheme>();
423     CHECK_NULL_VOID(textTheme);
424     auto size = textObject->GetProperty("size");
425     CalcDimension fontSize;
426     if (!ParseJsDimensionNG(size, fontSize, DimensionUnit::FP)) {
427         fontSize = theme->GetTextSize();
428     }
429     if (LessNotEqual(fontSize.Value(), 0.0) || fontSize.Unit() == DimensionUnit::PERCENT) {
430         fontSize = theme->GetTextSize();
431     }
432     ProgressModel::GetInstance()->SetFontSize(fontSize);
433 
434     auto fontWeight = textObject->GetProperty("weight");
435     if (!fontWeight->IsNull()) {
436         std::string weight;
437         if (fontWeight->IsNumber()) {
438             weight = std::to_string(fontWeight->ToNumber<int32_t>());
439         } else {
440             ParseJsString(fontWeight, weight);
441         }
442         ProgressModel::GetInstance()->SetFontWeight(ConvertStrToFontWeight(weight));
443     } else {
444         ProgressModel::GetInstance()->SetFontWeight(textTheme->GetTextStyle().GetFontWeight());
445     }
446 
447     auto family = textObject->GetProperty("family");
448     if (!family->IsNull() && family->IsString()) {
449         auto familyVal = family->ToString();
450         ProgressModel::GetInstance()->SetFontFamily(ConvertStrToFontFamilies(familyVal));
451     } else {
452         ProgressModel::GetInstance()->SetFontFamily(textTheme->GetTextStyle().GetFontFamilies());
453     }
454 
455     auto style = textObject->GetProperty("style");
456     if (!style->IsNull() && style->IsNumber()) {
457         auto styleVal = static_cast<FontStyle>(style->ToNumber<int32_t>());
458         ProgressModel::GetInstance()->SetItalicFontStyle(styleVal);
459     } else {
460         ProgressModel::GetInstance()->SetItalicFontStyle(textTheme->GetTextStyle().GetFontStyle());
461     }
462 }
463 
ConvertGradientColor(const JsiRef<JsiValue> & param,NG::Gradient & gradient)464 bool JSProgress::ConvertGradientColor(const JsiRef<JsiValue>& param, NG::Gradient& gradient)
465 {
466     if (param->IsNull() || param->IsUndefined() || !param->IsObject()) {
467         return false;
468     }
469 
470     JSLinearGradient* jsLinearGradient = JSRef<JSObject>::Cast(param)->Unwrap<JSLinearGradient>();
471     auto proxy = param->GetLocalHandle();
472     auto vm = param->GetEcmaVM();
473     if (proxy->IsProxy(vm)) {
474         panda::Local<panda::ProxyRef> thisProxiedObj =
475             static_cast<panda::Local<panda::ProxyRef>>(proxy);
476         jsLinearGradient = static_cast<JSLinearGradient *>(
477             panda::Local<panda::ObjectRef>(thisProxiedObj->GetTarget(vm))
478                 ->GetNativePointerField(vm, 0));
479     }
480 
481     if (!jsLinearGradient || jsLinearGradient->GetGradient().empty()) {
482         return false;
483     }
484 
485     size_t size = jsLinearGradient->GetGradient().size();
486     if (size == 1) {
487         // If there is only one color, then this color is used for both the begin and end side.
488         NG::GradientColor gradientColor;
489         gradientColor.SetLinearColor(LinearColor(jsLinearGradient->GetGradient().front().first));
490         gradientColor.SetDimension(jsLinearGradient->GetGradient().front().second);
491         gradient.AddColor(gradientColor);
492         gradient.AddColor(gradientColor);
493         return true;
494     }
495 
496     for (size_t colorIndex = 0; colorIndex < size; colorIndex++) {
497         NG::GradientColor gradientColor;
498         gradientColor.SetLinearColor(LinearColor(jsLinearGradient->GetGradient().at(colorIndex).first));
499         gradientColor.SetDimension(jsLinearGradient->GetGradient().at(colorIndex).second);
500         gradient.AddColor(gradientColor);
501     }
502     return true;
503 }
504 
JsSetLinearStyleOptions(const JSCallbackInfo & info)505 void JSProgress::JsSetLinearStyleOptions(const JSCallbackInfo& info)
506 {
507     auto paramObject = JSRef<JSObject>::Cast(info[0]);
508     RefPtr<ProgressTheme> theme = GetTheme<ProgressTheme>();
509 
510     // Parse stroke width
511     CalcDimension strokeWidthDimension;
512     auto versionTenOrLarger = Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN);
513     auto strokeWidth = paramObject->GetProperty("strokeWidth");
514     if (strokeWidth->IsUndefined() || strokeWidth->IsNull() ||
515         (versionTenOrLarger ? !ParseJsDimensionVpNG(strokeWidth, strokeWidthDimension)
516                             : !ParseJsDimensionVp(strokeWidth, strokeWidthDimension))) {
517         strokeWidthDimension = theme->GetTrackThickness();
518     }
519 
520     if (LessOrEqual(strokeWidthDimension.Value(), 0.0f) || strokeWidthDimension.Unit() == DimensionUnit::PERCENT) {
521         strokeWidthDimension = theme->GetTrackThickness();
522     }
523 
524     ProgressModel::GetInstance()->SetStrokeWidth(strokeWidthDimension);
525 
526     auto jsSweepingEffect = paramObject->GetProperty("enableScanEffect");
527     bool sweepingEffect = false;
528     if (!ParseJsBool(jsSweepingEffect, sweepingEffect)) {
529         sweepingEffect = false;
530     }
531     ProgressModel::GetInstance()->SetLinearSweepingEffect(sweepingEffect);
532 
533     // Parse stroke radius
534     CalcDimension strokeRadiusDimension;
535     auto strokeRadius = paramObject->GetProperty("strokeRadius");
536     if (strokeRadius->IsUndefined() || strokeRadius->IsNull() ||
537         !ParseJsDimensionVpNG(strokeRadius, strokeRadiusDimension)) {
538         ProgressModel::GetInstance()->ResetStrokeRadius();
539         return;
540     }
541 
542     if (LessNotEqual(strokeRadiusDimension.Value(), 0.0f) || strokeRadiusDimension.Unit() == DimensionUnit::PERCENT) {
543         ProgressModel::GetInstance()->ResetStrokeRadius();
544         return;
545     }
546 
547     ProgressModel::GetInstance()->SetStrokeRadius(strokeRadiusDimension);
548 }
549 
JsSetBorderRadius(const JSRef<JSObject> & paramObject)550 void JSProgress::JsSetBorderRadius(const JSRef<JSObject>& paramObject)
551 {
552     CalcDimension radiusDimension;
553     auto borderRadius = paramObject->GetProperty("borderRadius");
554     if (!borderRadius->IsObject() || !ParseJsLengthMetricsVp(JSRef<JSObject>::Cast(borderRadius), radiusDimension)) {
555         ProgressModel::GetInstance()->ResetBorderRadius();
556         return;
557     }
558     if (LessNotEqual(radiusDimension.Value(), 0.0f) || radiusDimension.Unit() == DimensionUnit::PERCENT) {
559         ProgressModel::GetInstance()->ResetBorderRadius();
560         return;
561     }
562     ProgressModel::GetInstance()->SetBorderRadius(radiusDimension);
563 }
564 } // namespace OHOS::Ace::Framework
565