• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TEXTPICKER_THEME_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_TEXTPICKER_THEME_H
18 
19 #include "bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h"
20 #include "bridge/declarative_frontend/jsview/js_view_abstract.h"
21 #include "core/components_ng/base/view_abstract_model.h"
22 #include "core/components_ng/base/view_stack_model.h"
23 #include "core/components_ng/pattern/text_picker/textpicker_model.h"
24 
25 namespace OHOS::Ace::Framework {
26 class JSTextPickerTheme {
27 public:
ApplyTheme()28     static void ApplyTheme()
29     {
30         auto themePicker = JSViewAbstract::GetTheme<PickerTheme>();
31         CHECK_NULL_VOID(themePicker);
32         auto themeColors = JSThemeUtils::GetThemeColors();
33         if (!themeColors) {
34             return;
35         }
36         NG::PickerTextStyle textStyle;
37         auto selectedStyle = themePicker->GetOptionStyle(true, false);
38         textStyle.textColor = themeColors.value().FontEmphasize();
39         textStyle.fontSize = selectedStyle.GetFontSize();
40         textStyle.fontWeight = selectedStyle.GetFontWeight();
41         TextPickerModel::GetInstance()->SetSelectedTextStyle(themePicker, textStyle);
42 
43         auto disappearStyle = themePicker->GetDisappearOptionStyle();
44         textStyle.textColor = themeColors.value().FontPrimary();
45         textStyle.fontSize = disappearStyle.GetFontSize();
46         textStyle.fontWeight = disappearStyle.GetFontWeight();
47         TextPickerModel::GetInstance()->SetDisappearTextStyle(themePicker, textStyle);
48 
49         auto normalStyle = themePicker->GetOptionStyle(false, false);
50         textStyle.textColor = themeColors.value().FontPrimary();
51         textStyle.fontSize = normalStyle.GetFontSize();
52         textStyle.fontWeight = normalStyle.GetFontWeight();
53         TextPickerModel::GetInstance()->SetNormalTextStyle(themePicker, textStyle);
54 
55         auto targetNode = NG::ViewStackProcessor::GetInstance()->GetMainFrameNode();
56         CHECK_NULL_VOID(targetNode);
57         targetNode->MarkModifyDone();
58     }
59 
ObtainSelectedTextStyle(NG::PickerTextStyle & textStyle)60     static bool ObtainSelectedTextStyle(NG::PickerTextStyle& textStyle)
61     {
62         if (auto themeColors = JSThemeUtils::GetThemeColors(); themeColors.has_value()) {
63             textStyle.textColor = themeColors.value().FontEmphasize();
64             return true;
65         }
66         return false;
67     }
68 
ObtainTextStyle(NG::PickerTextStyle & textStyle)69     static bool ObtainTextStyle(NG::PickerTextStyle& textStyle)
70     {
71         if (auto themeColors = JSThemeUtils::GetThemeColors(); themeColors.has_value()) {
72             textStyle.textColor = themeColors.value().FontPrimary();
73             return true;
74         }
75         return false;
76     }
77 };
78 } // namespace OHOS::Ace::Framework
79 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_TEXTPICKER_THEME_H
80