1 /*
2  * Copyright (c) 2024 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 #ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_PROGRESS_THEME_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_PROGRESS_THEME_H
18 
19 #include "bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h"
20 #include "core/components_ng/base/view_abstract_model.h"
21 #include "core/components_ng/base/view_stack_model.h"
22 #include "core/components_ng/pattern/progress/progress_model.h"
23 
24 namespace OHOS::Ace::Framework {
25 class JSProgressTheme {
26 public:
ApplyTheme(const ProgressStyle & style)27     static void ApplyTheme(const ProgressStyle& style)
28     {
29         auto themeColors = JSThemeUtils::GetThemeColors();
30         if (!themeColors) {
31             // no need to apply custom theme colors
32             return;
33         }
34         if (style != ProgressStyle::Capsule) {
35             ProgressModel::GetInstance()->SetBackgroundColor(themeColors->CompBackgroundTertiary());
36         }
37         if (style == ProgressStyle::Capsule) {
38             NG::GradientColor endSideColor;
39             NG::GradientColor beginSideColor;
40             OHOS::Ace::NG::Gradient gradient;
41             endSideColor.SetLinearColor(LinearColor(themeColors->CompEmphasizeSecondary()));
42             endSideColor.SetDimension(Dimension(0.0f));
43             beginSideColor.SetLinearColor(LinearColor(themeColors->CompEmphasizeSecondary()));
44             beginSideColor.SetDimension(Dimension(1.0f));
45             gradient.AddColor(endSideColor);
46             gradient.AddColor(beginSideColor);
47             ProgressModel::GetInstance()->SetGradientColor(gradient);
48             ProgressModel::GetInstance()->SetColor(themeColors->CompEmphasizeSecondary());
49             // normal
50             ViewStackModel::GetInstance()->SetVisualState(VisualState::NORMAL);
51             auto borderColor = themeColors->CompEmphasizeSecondary();
52             ViewAbstractModel::GetInstance()->SetBorderColor(borderColor, borderColor, borderColor, borderColor);
53             ViewAbstractModel::GetInstance()->SetColorBlend(Color::BLACK); // default for restore color after pressed
54             // clear state
55             ViewStackModel::GetInstance()->ClearVisualState();
56         } else if (style == ProgressStyle::Linear || style == ProgressStyle::Eclipse) {
57             NG::GradientColor endSideColor;
58             NG::GradientColor beginSideColor;
59             OHOS::Ace::NG::Gradient gradient;
60             endSideColor.SetLinearColor(LinearColor(themeColors->BackgroundEmphasize()));
61             endSideColor.SetDimension(Dimension(0.0f));
62             beginSideColor.SetLinearColor(LinearColor(themeColors->BackgroundEmphasize()));
63             beginSideColor.SetDimension(Dimension(1.0f));
64             gradient.AddColor(endSideColor);
65             gradient.AddColor(beginSideColor);
66             ProgressModel::GetInstance()->SetGradientColor(gradient);
67             ProgressModel::GetInstance()->SetColor(themeColors->BackgroundEmphasize());
68         }
69     }
70 };
71 } // namespace OHOS::Ace::Framework
72 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_PROGRESS_THEME_H
73