diff --git a/frameworks/core/components/theme/theme_manager_impl.cpp b/frameworks/core/components/theme/theme_manager_impl.cpp index 0a28469716a1ce216f6213accfe909456aa3fbb0..4d1b88db6f7cb6fed587cc5db16cee9989aca749 100644 --- a/frameworks/core/components/theme/theme_manager_impl.cpp +++ b/frameworks/core/components/theme/theme_manager_impl.cpp @@ -226,8 +226,7 @@ ThemeManagerImpl::ThemeManagerImpl(RefPtr& resourceAdapter) void ThemeManagerImpl::RegisterThemeKit(ThemeType type, Ace::Kit::BuildFunc func) { - auto key = GetThemesMapKey(type); - auto findIter = themes_.find(key); + auto findIter = themes_.find(type); if (findIter != themes_.end()) { return; } @@ -245,8 +244,7 @@ std::string ThemeManagerImpl::GetThemesMapKey(ThemeType type) const RefPtr ThemeManagerImpl::GetTheme(ThemeType type) { - auto key = GetThemesMapKey(type); - auto findIter = themes_.find(key); + auto findIter = themes_.find(type); if (findIter != themes_.end()) { return findIter->second; } @@ -264,8 +262,7 @@ RefPtr ThemeManagerImpl::GetThemeOrigin(ThemeType type) } auto theme = builderIter->second(themeConstants_); - auto key = GetThemesMapKey(type); - themes_.emplace(key, theme); + themes_.emplace(type, theme); return theme; } @@ -275,7 +272,6 @@ RefPtr ThemeManagerImpl::GetThemeKit(ThemeType type) if (builderIterKit == THEME_BUILDERS_KIT.end()) { return nullptr; } - auto key = GetThemesMapKey(type); if (auto pipeline = NG::PipelineContext::GetCurrentContext(); pipeline) { ColorMode localMode = pipeline->GetLocalColorMode(); ColorMode systemMode = pipeline->GetColorMode(); @@ -293,12 +289,12 @@ RefPtr ThemeManagerImpl::GetThemeKit(ThemeType type) ResourceManager::GetInstance().UpdateColorMode( pipeline->GetBundleName(), pipeline->GetModuleName(), pipeline->GetInstanceId(), localMode); } - themes_.emplace(key, theme); + themes_.emplace(type, theme); return theme; } auto theme = builderIterKit->second(); - themes_.emplace(key, theme); + themes_.emplace(type, theme); return theme; } @@ -411,8 +407,7 @@ RefPtr ThemeManagerImpl::GetThemeKit(ThemeType type, int32_t themeScopeId Color ThemeManagerImpl::GetBackgroundColor() const { - auto key = GetThemesMapKey(AppTheme::TypeId()); - auto findIter = themes_.find(key); + auto findIter = themes_.find(AppTheme::TypeId()); if (findIter != themes_.end()) { auto appTheme = AceType::DynamicCast(findIter->second); if (appTheme) { diff --git a/frameworks/core/components/theme/theme_manager_impl.h b/frameworks/core/components/theme/theme_manager_impl.h index 0b0cf9e6e4a0efb8d7d48e9587d8f1192801b841..b9c50fce269c28d56c25808cd31d1fea20052249 100644 --- a/frameworks/core/components/theme/theme_manager_impl.h +++ b/frameworks/core/components/theme/theme_manager_impl.h @@ -139,7 +139,7 @@ public: private: using ThemeWrappers = std::unordered_map>; - std::unordered_map> themes_; + std::unordered_map> themes_; ThemeWrappers themeWrappersLight_; ThemeWrappers themeWrappersDark_; diff --git a/test/unittest/core/manager/theme_manager_test_ng.cpp b/test/unittest/core/manager/theme_manager_test_ng.cpp index 46d82259de1933eda3614d78860065ca1a731e2c..c43509671cf505518a80af0ee3bc7a0a3e2c4b46 100644 --- a/test/unittest/core/manager/theme_manager_test_ng.cpp +++ b/test/unittest/core/manager/theme_manager_test_ng.cpp @@ -77,4 +77,20 @@ HWTEST_F(ThemeManagerTestNg, GetThemesMapKey001, TestSize.Level1) themeManager->GetThemesMapKey(ButtonTheme::TypeId()); EXPECT_TRUE(AceType::InstanceOf(theme)); } + +/** + * @tc.name: GetCurrentColorMode001 + * @tc.desc: GetCurrentColorMode + * @tc.type: FUNC + */ +HWTEST_F(ThemeManagerTestNg, GetCurrentColorMode001, TestSize.Level1) +{ + /** + * @tc.steps: create themeManager + */ + auto themeManager = AceType::MakeRefPtr(); + auto theme = themeManager->GetThemeOrigin(ButtonTheme::TypeId()); + themeManager->GetCurrentColorMode(); + EXPECT_TRUE(AceType::InstanceOf(theme)); +} }