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_DATEPICKER_THEME_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_DATEPICKER_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/picker/picker_model.h" 24 25 namespace OHOS::Ace::Framework { 26 class JSDatePickerTheme { 27 public: ApplyTheme()28 static bool ApplyTheme() 29 { 30 auto themePicker = JSViewAbstract::GetTheme<PickerTheme>(); 31 CHECK_NULL_RETURN(themePicker, false); 32 auto themeColors = JSThemeUtils::GetThemeColors(); 33 if (!themeColors) { 34 return false; 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 DatePickerModel::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 DatePickerModel::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 DatePickerModel::GetInstance()->SetNormalTextStyle(themePicker, textStyle); 54 55 auto targetNode = NG::ViewStackProcessor::GetInstance()->GetMainFrameNode(); 56 CHECK_NULL_RETURN(targetNode, false); 57 targetNode->MarkModifyDone(); 58 return true; 59 } 60 ObtainSelectedTextStyle(NG::PickerTextStyle & textStyle)61 static bool ObtainSelectedTextStyle(NG::PickerTextStyle& textStyle) 62 { 63 if (auto themeColors = JSThemeUtils::GetThemeColors(); themeColors.has_value()) { 64 textStyle.textColor = themeColors.value().FontEmphasize(); 65 return true; 66 } 67 return false; 68 } 69 ObtainTextStyle(NG::PickerTextStyle & textStyle)70 static bool ObtainTextStyle(NG::PickerTextStyle& textStyle) 71 { 72 if (auto themeColors = JSThemeUtils::GetThemeColors(); themeColors.has_value()) { 73 textStyle.textColor = themeColors.value().FontPrimary(); 74 return true; 75 } 76 return false; 77 } 78 }; 79 } // namespace OHOS::Ace::Framework 80 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_DATEPICKER_THEME_H 81