diff --git a/frameworks/bridge/declarative_frontend/jsview/js_menu_item.cpp b/frameworks/bridge/declarative_frontend/jsview/js_menu_item.cpp index 1adf1948a2bbc07b2775b23ec958ed5a59862dd0..e8e206e83150094aed1d4eb39aef9434dab87eb7 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_menu_item.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_menu_item.cpp @@ -120,24 +120,6 @@ void JSMenuItem::AddMenuItemOptionsResource(const RefPtr& conten props.labelInfo = labelInfoStr; }); } - if (startIconObj) { - menuItemProps.AddResource("MenuItem.StartIcon", startIconObj, [](const RefPtr& resObj, - MenuItemProperties& props) { - std::string iconStr; - CHECK_NE_VOID(ResourceParseUtils::ParseResMedia(resObj, iconStr), true); - ImageSourceInfo imageSourceInfo(iconStr); - props.startIcon = imageSourceInfo; - }); - } - if (endIconObj) { - menuItemProps.AddResource("MenuItem.EndIcon", endIconObj, [](const RefPtr& resObj, - MenuItemProperties& props) { - std::string iconStr; - CHECK_NE_VOID(ResourceParseUtils::ParseResMedia(resObj, iconStr), true); - ImageSourceInfo imageSourceInfo(iconStr); - props.endIcon = imageSourceInfo; - }); - } } void JSMenuItem::Create(const JSCallbackInfo& info) @@ -325,8 +307,27 @@ void JSMenuItem::ContentFont(const JSCallbackInfo& info) } } + ParseContentFontFamily(obj); + MenuItemModel::GetInstance()->SetFontSize(fontSize); + if (SystemProperties::ConfigChangePerform()) { + MenuItemModel::GetInstance()->CreateWithDimensionFpResourceObj( + fontSizeResObj, MenuItemFontSizeType::FONT_SIZE); + } + MenuItemModel::GetInstance()->SetFontWeight(ConvertStrToFontWeight(weight)); +} + +void JSMenuItem::ParseContentFontFamily(const JSRef& obj) +{ auto jsFamily = obj->GetProperty("family"); - if (!jsFamily->IsNull() && jsFamily->IsString()) { + if (jsFamily->IsNull()) { + return; + } + if (jsFamily->IsString()) { + auto familyVal = jsFamily->ToString(); + auto fontFamilies = ConvertStrToFontFamilies(familyVal); + MenuItemModel::GetInstance()->SetFontFamily(fontFamilies); + } + else if (jsFamily->IsObject()) { RefPtr familyResObj; std::vector fontFamilies; if (ParseJsFontFamilies(jsFamily, fontFamilies, familyResObj)) { @@ -337,12 +338,6 @@ void JSMenuItem::ContentFont(const JSCallbackInfo& info) familyResObj, MenuItemFontFamilyType::FONT_FAMILY); } } - MenuItemModel::GetInstance()->SetFontSize(fontSize); - if (SystemProperties::ConfigChangePerform()) { - MenuItemModel::GetInstance()->CreateWithDimensionFpResourceObj( - fontSizeResObj, MenuItemFontSizeType::FONT_SIZE); - } - MenuItemModel::GetInstance()->SetFontWeight(ConvertStrToFontWeight(weight)); } void JSMenuItem::ContentFontColor(const JSCallbackInfo& info) @@ -398,8 +393,27 @@ void JSMenuItem::LabelFont(const JSCallbackInfo& info) } } + ParseLabelFontFamily(obj); + MenuItemModel::GetInstance()->SetLabelFontSize(fontSize); + if (SystemProperties::ConfigChangePerform()) { + MenuItemModel::GetInstance()->CreateWithDimensionFpResourceObj( + fontSizeResObj, MenuItemFontSizeType::LABEL_FONT_SIZE); + } + MenuItemModel::GetInstance()->SetLabelFontWeight(ConvertStrToFontWeight(weight)); +} + +void JSMenuItem::ParseLabelFontFamily(const JSRef& obj) +{ auto jsFamily = obj->GetProperty("family"); - if (!jsFamily->IsNull() && jsFamily->IsString()) { + if (jsFamily->IsNull()) { + return; + } + if (jsFamily->IsString()) { + auto familyVal = jsFamily->ToString(); + auto fontFamilies = ConvertStrToFontFamilies(familyVal); + MenuItemModel::GetInstance()->SetLabelFontFamily(fontFamilies); + } + else if (jsFamily->IsObject()) { RefPtr familyResObj; std::vector fontFamilies; if (ParseJsFontFamilies(jsFamily, fontFamilies, familyResObj)) { @@ -410,12 +424,6 @@ void JSMenuItem::LabelFont(const JSCallbackInfo& info) familyResObj, MenuItemFontFamilyType::LABEL_FONT_FAMILY); } } - MenuItemModel::GetInstance()->SetLabelFontSize(fontSize); - if (SystemProperties::ConfigChangePerform()) { - MenuItemModel::GetInstance()->CreateWithDimensionFpResourceObj( - fontSizeResObj, MenuItemFontSizeType::LABEL_FONT_SIZE); - } - MenuItemModel::GetInstance()->SetLabelFontWeight(ConvertStrToFontWeight(weight)); } void JSMenuItem::LabelFontColor(const JSCallbackInfo& info) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_menu_item.h b/frameworks/bridge/declarative_frontend/jsview/js_menu_item.h index a2d5912bb4c83c628e02c093c7b926c3bf18e105..f67a461c7f4d289aeb90aac33c8f430e49ac349f 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_menu_item.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_menu_item.h @@ -40,6 +40,8 @@ private: static void AddMenuItemOptionsResource(const RefPtr& contentStrObj, const RefPtr& labelStrObj, const RefPtr& startIconObj, const RefPtr& endIconObj, MenuItemProperties& menuItemProps); + static void ParseContentFontFamily(const JSRef& obj); + static void ParseLabelFontFamily(const JSRef& obj); }; } // namespace OHOS::Ace::Framework #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_MENU_ITEM_H diff --git a/frameworks/bridge/declarative_frontend/jsview/js_menu_item_group.cpp b/frameworks/bridge/declarative_frontend/jsview/js_menu_item_group.cpp index 0ffd57e6247f03fd799c0ef221b57092e9874d18..5645504f7755ebd0b0180a567370bb9503ea5d27 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_menu_item_group.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_menu_item_group.cpp @@ -66,6 +66,7 @@ void JSMenuItemGroup::Create(const JSCallbackInfo& info) return; } } + return; } } diff --git a/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_layout_algorithm.h b/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_layout_algorithm.h index 1e2f6c19bc289cc0ee347b165bb86784d705492c..d33c9bb8fbb56f403df60c7e415b5a72a0554832 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_layout_algorithm.h @@ -35,4 +35,4 @@ private: ACE_DISALLOW_COPY_AND_MOVE(MenuDividerLayoutAlgorithm); }; } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DIVIDER_DIVIDER_LAYOUT_ALGORITHM_H \ No newline at end of file +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MENU_MENU_DIVIDER_MENU_DIVIDER_LAYOUT_ALGORITHM_H diff --git a/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_modifier.h b/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_modifier.h index f22e38586060ed0269ad59e8022df0708d596ca0..da8ce48678f94611883dd95863b519d1775644a5 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_modifier.h +++ b/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_modifier.h @@ -98,4 +98,4 @@ private: }; } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DIVIDER_DIVIDER_MODIFIER_H +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_DIVIDER_MENU_DIVIDER_MODIFIER_H diff --git a/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_paint_method.h b/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_paint_method.h index 859173e46f2157affe100b71b9eeeb38f528ca27..8d246d7f9ba7c0cfc51c1487dcbafdbbd6bd1fe7 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_paint_method.h +++ b/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_paint_method.h @@ -95,4 +95,4 @@ private: }; } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DIVIDER_DIVIDER_PAINT_METHOD_H +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MENU_MENU_DIVIDER_MENU_DIVIDER_PAINT_METHOD_H diff --git a/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_paint_property.h b/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_paint_property.h index 8b62adcb126438c72f14eabb50cbe34124ff471c..b9c3b98946d07d71843d41935c06842cc7592f94 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_paint_property.h +++ b/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_paint_property.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MENU_MENU_DIVIER_MENU_DIVIDER_PAINT_PROPERTY_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MENU_MENU_DIVIER_MENU_DIVIDER_PAINT_PROPERTY_H +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MENU_MENU_DIVIDER_MENU_DIVIDER_PAINT_PROPERTY_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MENU_MENU_DIVIDER_MENU_DIVIDER_PAINT_PROPERTY_H #include "core/components/common/layout/constants.h" #include "core/components/common/properties/color.h" @@ -79,4 +79,4 @@ public: ACE_DISALLOW_COPY_AND_MOVE(MenuDividerPaintProperty); }; } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DIVIDER_DIVIDER_RENDER_PROPERTY_H +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MENU_MENU_DIVIDER_MENU_DIVIDER_RENDER_PROPERTY_H diff --git a/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_pattern.h b/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_pattern.h index 42f897c2e982807b4c9be2ce43e209e44e47fc36..ca3593e6845a794d9bdd9c7ed84a4019eca4eec0 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_pattern.h +++ b/frameworks/core/components_ng/pattern/menu/menu_divider/menu_divider_pattern.h @@ -60,4 +60,4 @@ private: }; } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DIVIDER_DIVIDER_PATTERN_H +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_DIVIDER_MENU_DIVIDER_PATTERN_H diff --git a/frameworks/core/components_ng/pattern/select/select_model_ng.cpp b/frameworks/core/components_ng/pattern/select/select_model_ng.cpp index fdb2f49f28e85910d66ea01cc88b6c9e32886074..427253b757de7e51bd76821000374760219b4366 100644 --- a/frameworks/core/components_ng/pattern/select/select_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/select/select_model_ng.cpp @@ -39,7 +39,6 @@ void SetSelectDefaultSize(const RefPtr& select) CalcLength(theme->GetSelectDefaultHeight(pattern->GetControlSize())))); } } - } // namespace void SelectModelNG::Create(const std::vector& params) @@ -1065,14 +1064,6 @@ void SelectModelNG::SetChangeValue(FrameNode* frameNode, int index, const std::s pattern->SetItemSelected(index, value); } -void SelectModelNG::SetOnSelect(FrameNode* frameNode, NG::SelectEvent&& onSelect) -{ - CHECK_NULL_VOID(frameNode); - auto hub = frameNode->GetOrCreateEventHub(); - CHECK_NULL_VOID(hub); - hub->SetSelectEvent(std::move(onSelect)); -} - void SelectModelNG::SetMenuBackgroundColor(FrameNode* frameNode, const Color& color) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(frameNode); @@ -1087,6 +1078,14 @@ void SelectModelNG::SetMenuBackgroundBlurStyle(FrameNode* frameNode, const BlurS pattern->SetMenuBackgroundBlurStyle(blurStyle); } +void SelectModelNG::SetOnSelect(FrameNode* frameNode, NG::SelectEvent&& onSelect) +{ + CHECK_NULL_VOID(frameNode); + auto hub = frameNode->GetOrCreateEventHub(); + CHECK_NULL_VOID(hub); + hub->SetSelectEvent(std::move(onSelect)); +} + void SelectModelNG::SetLayoutDirection(TextDirection value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); @@ -1124,21 +1123,6 @@ void SelectModelNG::ResetBackgroundColor() ACE_UPDATE_PAINT_PROPERTY(SelectPaintProperty, BackgroundColorSetByUser, false); } -void SelectModelNG::SetMenuOutline(const MenuParam& menuParam) -{ - auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); - CHECK_NULL_VOID(pattern); - pattern->SetMenuOutline(menuParam); -} - -void SelectModelNG::SetMenuOutline(FrameNode* frameNode, const MenuParam& menuParam) -{ - CHECK_NULL_VOID(frameNode); - auto pattern = frameNode->GetPattern(); - CHECK_NULL_VOID(pattern); - pattern->SetMenuOutline(menuParam); -} - void SelectModelNG::SetTextModifierApply(const std::function)>& textApply) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); @@ -1172,6 +1156,21 @@ void SelectModelNG::SetSelectedOptionTextModifier( ACE_UPDATE_PAINT_PROPERTY(SelectPaintProperty, SelectedOptionTextModifierSetByUser, true); } +void SelectModelNG::SetMenuOutline(const MenuParam& menuParam) +{ + auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); + CHECK_NULL_VOID(pattern); + pattern->SetMenuOutline(menuParam); +} + +void SelectModelNG::SetMenuOutline(FrameNode* frameNode, const MenuParam& menuParam) +{ + CHECK_NULL_VOID(frameNode); + auto pattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pattern); + pattern->SetMenuOutline(menuParam); +} + void SelectModelNG::SetShowInSubWindow(bool isShowInSubWindow) { auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); diff --git a/frameworks/core/components_ng/pattern/select/select_model_ng.h b/frameworks/core/components_ng/pattern/select/select_model_ng.h index 3bc68b9a4481c63a9f9d67db66a9ec6a0da7b330..1d97523394c5ff107883f0a57c1de4e34f34b7e8 100644 --- a/frameworks/core/components_ng/pattern/select/select_model_ng.h +++ b/frameworks/core/components_ng/pattern/select/select_model_ng.h @@ -76,9 +76,6 @@ public: void SetAvoidance(AvoidanceMode mode) override; void SetSelectChangeEvent(NG::SelectChangeEvent&& selectChangeEvent) override; void SetValueChangeEvent(NG::ValueChangeEvent&& valueChangeEvent) override; - void SetOptionWidth(const Dimension& value) override; - void SetOptionHeight(const Dimension& value) override; - void SetOptionWidthFitTrigger(bool isFitTrigger) override; void SetHasOptionWidth(bool hasOptionWidth) override; void SetMenuBackgroundColor(const Color& color) override; void SetMenuBackgroundBlurStyle(const BlurStyleOption& blurStyle) override; @@ -108,7 +105,6 @@ public: void BackgroundColor(const Color& color) override; void ResetBackgroundColor() override; void ResetFontColor() override; - void SetMenuOutline(const MenuParam& menuParam) override; void SetTextModifierApply(const std::function)>& textApply) override; void SetArrowModifierApply(const std::function)>& arrowApply) override; void SetOptionTextModifier(const std::function)>& optionApply) override; @@ -117,6 +113,7 @@ public: void ResetShowInSubWindow() override; void SetShowDefaultSelectedIcon(bool show) override; void ResetShowDefaultSelectedIcon() override; + void SetMenuOutline(const MenuParam& menuParam) override; static RefPtr CreateFrameNode(int32_t nodeId); static void InitSelect(FrameNode* frameNode, const std::vector& params); @@ -145,13 +142,16 @@ public: static void SetSelectedOptionFontWeight(FrameNode* frameNode, const FontWeight& value); static void SetSelectedOptionFontFamily(FrameNode* frameNode, const std::vector& value); static void SetSelectedOptionItalicFontStyle(FrameNode* frameNode, const Ace::FontStyle& value); + void SetOptionWidth(const Dimension& value) override; + void SetOptionHeight(const Dimension& value) override; + void SetOptionWidthFitTrigger(bool isFitTrigger) override; static void SetOptionWidth(FrameNode* frameNode, const Dimension& value); static void SetHasOptionWidth(FrameNode* frameNode, bool hasOptionWidth); static void SetOptionHeight(FrameNode* frameNode, const Dimension& value); static void SetOptionWidthFitTrigger(FrameNode* frameNode, bool isFitTrigger); - static void SetOnSelect(FrameNode* frameNode, NG::SelectEvent&& onSelect); static void SetMenuBackgroundColor(FrameNode* frameNode, const Color& color); static void SetMenuBackgroundBlurStyle(FrameNode* frameNode, const BlurStyleOption& blurStyle); + static void SetOnSelect(FrameNode* frameNode, NG::SelectEvent&& onSelect); static void SetLayoutDirection(FrameNode* frameNode, TextDirection value); static void SetMenuOutline(FrameNode* frameNode, const MenuParam& menuParam); static void SetShowInSubWindow(FrameNode* frameNode, bool isShowInSubWindow); diff --git a/frameworks/core/components_ng/pattern/select/select_pattern.cpp b/frameworks/core/components_ng/pattern/select/select_pattern.cpp index fab52da26c295d0b365b6a8160df379b8c23826f..544245329b340c0f88df7a90ec5321f1976fba12 100644 --- a/frameworks/core/components_ng/pattern/select/select_pattern.cpp +++ b/frameworks/core/components_ng/pattern/select/select_pattern.cpp @@ -81,22 +81,6 @@ constexpr uint32_t RENDERINGSTRATEGY_MULTIPLE_COLOR = 1; constexpr int32_t FIRST_NODE_INDEX = 0; -static std::string ConvertControlSizeToString(ControlSize controlSize) -{ - std::string result; - switch (controlSize) { - case ControlSize::SMALL: - result = "ControlSize.SMALL"; - break; - case ControlSize::NORMAL: - result = "ControlSize.NORMAL"; - break; - default: - break; - } - return result; -} - void RecordChange(RefPtr host, int32_t index, const std::string& value) { if (Recorder::EventRecorder::Get().IsComponentRecordEnable()) { @@ -115,6 +99,22 @@ void RecordChange(RefPtr host, int32_t index, const std::string& valu } } +static std::string ConvertControlSizeToString(ControlSize controlSize) +{ + std::string result; + switch (controlSize) { + case ControlSize::SMALL: + result = "ControlSize.SMALL"; + break; + case ControlSize::NORMAL: + result = "ControlSize.NORMAL"; + break; + default: + break; + } + return result; +} + static std::string ConvertVectorToString(std::vector vec) { std::ostringstream oss; @@ -140,7 +140,7 @@ void SelectPattern::OnModifyDone() auto host = GetHost(); CHECK_NULL_VOID(host); - auto eventHub = host->GetOrCreateEventHub(); + auto eventHub = host->GetEventHub(); CHECK_NULL_VOID(eventHub); if (!eventHub->IsEnabled()) { SetDisabledStyle(); @@ -201,7 +201,7 @@ void SelectPattern::SetItemSelected(int32_t index, const std::string& value) text_->MarkModifyDone(); host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); menuPattern->HideMenu(HideMenuType::SELECT_SELECTED); - auto hub = host->GetOrCreateEventHub(); + auto hub = host->GetEventHub(); CHECK_NULL_VOID(hub); auto onSelect = hub->GetSelectEvent(); @@ -392,7 +392,7 @@ void SelectPattern::PlayBgColorAnimation(bool isHoverChange) { auto host = GetHost(); CHECK_NULL_VOID(host); - auto pipeline = host->GetContextRefPtr(); + auto* pipeline = host->GetContextWithCheck(); CHECK_NULL_VOID(pipeline); auto selectTheme = pipeline->GetTheme(); CHECK_NULL_VOID(selectTheme); @@ -414,7 +414,7 @@ void SelectPattern::PlayBgColorAnimation(bool isHoverChange) auto renderContext = host->GetRenderContext(); CHECK_NULL_VOID(renderContext); renderContext->BlendBgColor(pattern->GetBgBlendColor()); - }, nullptr, nullptr, pipeline); + }); } // change background color when hovered @@ -462,7 +462,7 @@ void SelectPattern::RegisterOnPress() { auto host = GetHost(); CHECK_NULL_VOID(host); - auto eventHub = host->GetOrCreateEventHub(); + auto eventHub = host->GetEventHub(); CHECK_NULL_VOID(eventHub); std::function callback = [weak = WeakClaim(this)](const UIState& state) { auto pattern = weak.Upgrade(); @@ -505,7 +505,7 @@ void SelectPattern::CreateSelectedCallback() pattern->SetSelected(index); pattern->UpdateText(index); pattern->isSelected_ = true; - auto hub = host->GetOrCreateEventHub(); + auto hub = host->GetEventHub(); CHECK_NULL_VOID(hub); // execute change event callback auto selectChangeEvent = hub->GetSelectChangeEvent(); @@ -530,7 +530,7 @@ void SelectPattern::CreateSelectedCallback() RecordChange(host, index, value); }; for (auto&& option : options_) { - auto hub = option->GetOrCreateEventHub(); + auto hub = option->GetEventHub(); // no std::move, need to set multiple options hub->SetOnSelect(callback); option->MarkModifyDone(); @@ -1135,7 +1135,7 @@ void SelectPattern::ResetOptionToInitProps( { if (textOptionApply_) { optionPattern->SetOptionTextModifier(textOptionApply_); - } else if (textSelectOptionApply_ && !textOptionApply_) { + } else if (textSelectOptionApply_) { optionPattern->ResetSelectTextProps(); optionPattern->ApplyOptionThemeStyles(); } else { @@ -2037,6 +2037,7 @@ bool SelectPattern::OnThemeScopeUpdate(int32_t themeScopeId) selectRenderContext->UpdateBackgroundColor(selectTheme->GetButtonBackgroundColor()); result = true; } + return result; } @@ -2056,7 +2057,7 @@ void SelectPattern::OnLanguageConfigurationUpdate() pattern->UpdateText(index); auto host = pattern->GetHost(); CHECK_NULL_VOID(host); - auto hub = host->GetOrCreateEventHub(); + auto hub = host->GetEventHub(); CHECK_NULL_VOID(hub); if (index >= static_cast(pattern->options_.size()) || index < 0) { return; @@ -2333,14 +2334,30 @@ void SelectPattern::SetDividerMode(const std::optional& mode) menuPattern->UpdateMenuItemDivider(); } -void SelectPattern::SetMenuOutline(const MenuParam& menuParam) +void SelectPattern::DumpInfo() { - auto menu = GetMenuNode(); - CHECK_NULL_VOID(menu); - auto renderContext = menu->GetRenderContext(); - CHECK_NULL_VOID(renderContext); - renderContext->SetOuterBorderWidth(menuParam.outlineWidth.value_or(BorderWidthProperty())); - renderContext->SetOuterBorderColor(menuParam.outlineColor.value_or(BorderColorProperty())); + DumpLog::GetInstance().AddDesc("Selected: " + std::to_string(selected_)); + DumpLog::GetInstance().AddDesc("FontColor: " + fontColor_.value_or(Color()).ToString()); + DumpLog::GetInstance().AddDesc( + "SelectedOptionFontSize: " + selectedFont_.FontSize.value_or(Dimension()).ToString()); + DumpLog::GetInstance().AddDesc( + "SelectedOptionFontStyle: " + StringUtils::ToString(selectedFont_.FontStyle.value_or(Ace::FontStyle::NORMAL))); + DumpLog::GetInstance().AddDesc("SelectedOptionFontWeight: " + + StringUtils::FontWeightToString(selectedFont_.FontWeight.value_or(FontWeight::NORMAL))); + DumpLog::GetInstance().AddDesc("SelectedOptionFontFamily: " + + ConvertVectorToString(selectedFont_.FontFamily.value_or(std::vector()))); + DumpLog::GetInstance().AddDesc("SelectedOptionFontColor: " + selectedFont_.FontColor.value_or(Color()).ToString()); + DumpLog::GetInstance().AddDesc("SelectedBgColor: " + selectedBgColor_.value_or(Color()).ToString()); + DumpLog::GetInstance().AddDesc("OptionFontSize: " + optionFont_.FontSize.value_or(Dimension()).ToString()); + DumpLog::GetInstance().AddDesc( + "OptionFontStyle: " + StringUtils::ToString(optionFont_.FontStyle.value_or(Ace::FontStyle::NORMAL))); + DumpLog::GetInstance().AddDesc( + "OptionFontWeight: " + StringUtils::FontWeightToString(optionFont_.FontWeight.value_or(FontWeight::NORMAL))); + DumpLog::GetInstance().AddDesc( + "OptionFontFamily: " + ConvertVectorToString(optionFont_.FontFamily.value_or(std::vector()))); + DumpLog::GetInstance().AddDesc("OptionFontColor: " + optionFont_.FontColor.value_or(Color()).ToString()); + DumpLog::GetInstance().AddDesc("OptionBgColor: " + optionBgColor_.value_or(Color()).ToString()); + DumpLog::GetInstance().AddDesc("ControlSize: " + ConvertControlSizeToString(controlSize_)); } void SelectPattern::SetTextModifierApply(const std::function)>& textApply) @@ -2491,30 +2508,14 @@ void SelectPattern::UpdateSelectedOptionFontFromPattern(const RefPtr()))); - DumpLog::GetInstance().AddDesc("SelectedOptionFontColor: " + selectedFont_.FontColor.value_or(Color()).ToString()); - DumpLog::GetInstance().AddDesc("SelectedBgColor: " + selectedBgColor_.value_or(Color()).ToString()); - DumpLog::GetInstance().AddDesc("OptionFontSize: " + optionFont_.FontSize.value_or(Dimension()).ToString()); - DumpLog::GetInstance().AddDesc( - "OptionFontStyle: " + StringUtils::ToString(optionFont_.FontStyle.value_or(Ace::FontStyle::NORMAL))); - DumpLog::GetInstance().AddDesc( - "OptionFontWeight: " + StringUtils::FontWeightToString(optionFont_.FontWeight.value_or(FontWeight::NORMAL))); - DumpLog::GetInstance().AddDesc( - "OptionFontFamily: " + ConvertVectorToString(optionFont_.FontFamily.value_or(std::vector()))); - DumpLog::GetInstance().AddDesc("OptionFontColor: " + optionFont_.FontColor.value_or(Color()).ToString()); - DumpLog::GetInstance().AddDesc("OptionBgColor: " + optionBgColor_.value_or(Color()).ToString()); - DumpLog::GetInstance().AddDesc("ControlSize: " + ConvertControlSizeToString(controlSize_)); + auto menu = GetMenuNode(); + CHECK_NULL_VOID(menu); + auto renderContext = menu->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + renderContext->SetOuterBorderWidth(menuParam.outlineWidth.value_or(BorderWidthProperty())); + renderContext->SetOuterBorderColor(menuParam.outlineColor.value_or(BorderColorProperty())); } void SelectPattern::SetOptionTextModifierByUser( @@ -2595,7 +2596,6 @@ void SelectPattern::SetModifierByUser(const RefPtr& theme, const Re if (props->GetTextModifierSetByUserValue(false)) { SetTextModifierApply(textApply_); } - SetOptionTextModifierByUser(theme, props); SetSelectedOptionTextModifierByUser(theme, props); SetArrowModifierByUser(theme, props); diff --git a/frameworks/core/components_ng/property/menu_property.h b/frameworks/core/components_ng/property/menu_property.h index e34b76d3b0d5055fa6e081e23d542290d1459d25..043df4618eaf300d146c9789418faae8e3887319 100644 --- a/frameworks/core/components_ng/property/menu_property.h +++ b/frameworks/core/components_ng/property/menu_property.h @@ -19,6 +19,7 @@ #include "base/geometry/dimension.h" #include "core/components/common/properties/placement.h" #include "core/components_ng/event/gesture_event_hub.h" +#include "core/components_ng/property/border_property.h" #include "core/components_ng/property/transition_property.h" namespace OHOS::Ace::NG { @@ -107,6 +108,14 @@ struct MenuParam { bool disappearScaleToTarget = false; std::optional outlineWidth; std::optional outlineColor; + std::optional maskEnable; + std::optional maskType; + std::optional modalMode; + std::optional previewScaleMode; + std::optional availableLayoutAreaMode; + std::optional anchorPosition; + bool isDarkMode = false; + bool isWithTheme = false; struct resourceUpdater { RefPtr resObj; std::function&, MenuParam&)> updateFunc; @@ -122,6 +131,14 @@ struct MenuParam { resMap_[key] = { resObj, std::move(updateFunc) }; } + void AddResourceNoUpdate(const std::string& key, const RefPtr& resObj) + { + if (resObj == nullptr) { + return; + } + resMap_[key] = { resObj, std::move(nullptr) }; + } + const RefPtr GetResource(const std::string& key) const { auto iter = resMap_.find(key); @@ -142,14 +159,6 @@ struct MenuParam { resourceUpdater.updateFunc(resourceUpdater.resObj, *this); } } - std::optional maskEnable; - std::optional maskType; - std::optional modalMode; - std::optional previewScaleMode; - std::optional availableLayoutAreaMode; - std::optional anchorPosition; - bool isDarkMode = false; - bool isWithTheme = false; }; } // namespace OHOS::Ace::NG diff --git a/test/unittest/core/pattern/select/select_pattern_test_controlsize_ng.cpp b/test/unittest/core/pattern/select/select_pattern_test_controlsize_ng.cpp index 95d81d5711c84fc28393be14c384aafdf391de0a..a563d2ad3dec3db2ed9be89e3adb3643308f3c67 100644 --- a/test/unittest/core/pattern/select/select_pattern_test_controlsize_ng.cpp +++ b/test/unittest/core/pattern/select/select_pattern_test_controlsize_ng.cpp @@ -70,10 +70,8 @@ constexpr float FULL_SCREEN_HEIGHT = 1136.0f; const SizeF FULL_SCREEN_SIZE(FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT); const std::vector FONT_FAMILY_VALUE = { "cursive" }; const Dimension FONT_SIZE_VALUE = Dimension(20.1, DimensionUnit::PX); -const Dimension FONT_SIZE_VALUE_VP = Dimension(30.1, DimensionUnit::VP); const Ace::FontStyle ITALIC_FONT_STYLE_VALUE = Ace::FontStyle::ITALIC; const Ace::FontWeight FONT_WEIGHT_VALUE = Ace::FontWeight::W100; -const Ace::FontWeight FONT_WEIGHT_VALUE_LIGHTER = Ace::FontWeight::LIGHTER; const Color TEXT_COLOR_VALUE = Color::FromRGB(255, 100, 100); const Color BG_COLOR_VALUE = Color::FromRGB(100, 255, 100); const std::vector CREATE_VALUE = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE }, @@ -358,74 +356,6 @@ HWTEST_F(SelectPatternTestControlSizeNg, SetControlSize006, TestSize.Level1) EXPECT_NE(pattern->GetControlSize(), ControlSize::SMALL); } -/** - * @tc.name: SetControlSize007 - * @tc.desc: Test SelectPattern SetControlSize - * @tc.type: FUNC - */ -HWTEST_F(SelectPatternTestControlSizeNg, SetControlSize007, TestSize.Level1) -{ - /** - * @tc.steps: step1. Create select model, select frame node and select pattern. - * @tc.expected: Objects are created successfully. - */ - TestProperty testProperty; - testProperty.FontSize = std::make_optional(FONT_SIZE_VALUE_VP); - testProperty.FontStyle = std::make_optional(ITALIC_FONT_STYLE_VALUE); - testProperty.FontWeight = std::make_optional(FONT_WEIGHT_VALUE); - testProperty.FontColor = std::make_optional(TEXT_COLOR_VALUE); - testProperty.FontFamily = std::make_optional(FONT_FAMILY_VALUE); - auto frameNode = CreateSelect(CREATE_VALUE, testProperty); - ASSERT_NE(frameNode, nullptr); - auto pattern = frameNode->GetPattern(); - ASSERT_NE(pattern, nullptr); - - /** - * @tc.steps: step2. Get ControlSize, compare the set value with the ControlSize. - * @tc.expected: SelectPattern's ControlSize and the set value are equal. Restore the default value. - */ - auto backupControlSize = pattern->GetControlSize(); - auto settingControlSize = ControlSize::NORMAL; - pattern->SetControlSize(settingControlSize); - EXPECT_EQ(pattern->GetControlSize(), settingControlSize); - pattern->SetControlSize(backupControlSize); - EXPECT_EQ(pattern->GetControlSize(), backupControlSize); -} - -/** - * @tc.name: SetControlSize008 - * @tc.desc: Test SelectPattern SetControlSize - * @tc.type: FUNC - */ -HWTEST_F(SelectPatternTestControlSizeNg, SetControlSize008, TestSize.Level1) -{ - /** - * @tc.steps: step1. Create select model, select frame node and select pattern. - * @tc.expected: Objects are created successfully. - */ - TestProperty testProperty; - testProperty.FontSize = std::make_optional(FONT_SIZE_VALUE); - testProperty.FontStyle = std::make_optional(ITALIC_FONT_STYLE_VALUE); - testProperty.FontWeight = std::make_optional(FONT_WEIGHT_VALUE_LIGHTER); - testProperty.FontColor = std::make_optional(TEXT_COLOR_VALUE); - testProperty.FontFamily = std::make_optional(FONT_FAMILY_VALUE); - auto frameNode = CreateSelect(CREATE_VALUE, testProperty); - ASSERT_NE(frameNode, nullptr); - auto pattern = frameNode->GetPattern(); - ASSERT_NE(pattern, nullptr); - - /** - * @tc.steps: step2. Get ControlSize, compare the set value with the ControlSize. - * @tc.expected: SelectPattern's ControlSize and the set value are equal. Restore the default value. - */ - auto backupControlSize = pattern->GetControlSize(); - auto settingControlSize = ControlSize::NORMAL; - pattern->SetControlSize(settingControlSize); - EXPECT_EQ(pattern->GetControlSize(), settingControlSize); - pattern->SetControlSize(backupControlSize); - EXPECT_EQ(pattern->GetControlSize(), backupControlSize); -} - /** * @tc.name: SelectLayoutAlgorithmTest001 * @tc.desc: Test SelectLayoutAlgorithm::Measure. @@ -940,102 +870,6 @@ HWTEST_F(SelectPatternTestControlSizeNg, SetTextModifierApply003, TestSize.Level EXPECT_EQ(property->GetFontWeight(), Ace::FontWeight::BOLD); EXPECT_EQ(property->GetTextAlign(), TextAlign::JUSTIFY); } -/** - * @tc.name: SetTextModifierApply004 - * @tc.desc: Test SelectPattern SetTextModifierApply - * @tc.type: FUNC - */ -HWTEST_F(SelectPatternTestControlSizeNg, SetTextModifierApply004, TestSize.Level1) -{ - /** - * @tc.steps: step1. Create select. - */ - SelectModelNG selectModelInstance; - std::vector params = { { OPTION_TEXT, FILE_SOURCE } }; - selectModelInstance.Create(params); - auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); - ASSERT_NE(select, nullptr); - auto selectPattern = select->GetPattern(); - ASSERT_NE(selectPattern, nullptr); - auto frameNode = selectPattern->text_; - ASSERT_NE(frameNode, nullptr); - /** - * @tc.steps: step2. Set text and init some props. - */ - auto property = frameNode->GetLayoutProperty(); - ASSERT_NE(property, nullptr); - property->UpdateMaxLines(20); - /** - * @tc.steps: step3. set applyFunc dont eq nullptr and set some props. - */ - auto applyFunc = [](WeakPtr weakNode) { - auto textNode = weakNode.Upgrade(); - auto property = textNode->GetLayoutProperty(); - ASSERT_NE(property, nullptr); - property->UpdateMaxLines(8); - property->UpdateFontSize(Dimension(80)); - property->UpdateTextColor(Color::GREEN); - property->UpdateFontWeight(Ace::FontWeight::W600); - property->UpdateTextAlign(TextAlign::JUSTIFY); - }; - selectModelInstance.SetTextModifierApply(applyFunc); - property = frameNode->GetLayoutProperty(); - EXPECT_EQ(property->GetMaxLines(), 8); - EXPECT_EQ(property->GetFontSize(), Dimension(80)); - EXPECT_EQ(property->GetTextColor(), Color::GREEN); - EXPECT_EQ(property->GetFontWeight(), Ace::FontWeight::W600); - EXPECT_EQ(property->GetTextAlign(), TextAlign::JUSTIFY); -} -/** - * @tc.name: SetTextModifierApply005 - * @tc.desc: Test SelectPattern SetTextModifierApply - * @tc.type: FUNC - */ -HWTEST_F(SelectPatternTestControlSizeNg, SetTextModifierApply005, TestSize.Level1) -{ - /** - * @tc.steps: step1. Create select. - */ - SelectModelNG selectModelInstance; - std::vector params = { { OPTION_TEXT, FILE_SOURCE } }; - selectModelInstance.Create(params); - auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); - ASSERT_NE(select, nullptr); - auto selectPattern = select->GetPattern(); - ASSERT_NE(selectPattern, nullptr); - auto frameNode = selectPattern->text_; - ASSERT_NE(frameNode, nullptr); - /** - * @tc.steps: step2. Set text and init some props. - */ - auto property = frameNode->GetLayoutProperty(); - ASSERT_NE(property, nullptr); - property->UpdateMaxLines(10); - property->UpdateFontSize(Dimension(100)); - property->UpdateTextColor(Color::RED); - property->UpdateFontWeight(Ace::FontWeight::BOLD); - property->UpdateTextAlign(TextAlign::LEFT); - /** - * @tc.steps: step3. set applyFunc dont eq nullptr and set some props. - */ - auto applyFunc = [](WeakPtr weakNode) { - auto textNode = weakNode.Upgrade(); - auto property = textNode->GetLayoutProperty(); - ASSERT_NE(property, nullptr); - property->UpdateMaxLines(15); - property->UpdateFontSize(Dimension(60)); - property->UpdateTextColor(Color::BLUE); - property->UpdateFontWeight(Ace::FontWeight::MEDIUM); - property->UpdateTextAlign(TextAlign::CENTER); - }; - selectModelInstance.SetTextModifierApply(applyFunc); - property = frameNode->GetLayoutProperty(); - EXPECT_EQ(property->GetMaxLines(), 15); - EXPECT_EQ(property->GetFontSize(), Dimension(60)); - EXPECT_EQ(property->GetTextColor(), Color::BLUE); - EXPECT_EQ(property->GetFontWeight(), Ace::FontWeight::MEDIUM); - EXPECT_EQ(property->GetTextAlign(), TextAlign::CENTER); -} /** * @tc.name: SetArrowModifierApplyTest001 * @tc.desc: Test SetArrowModifierApply diff --git a/test/unittest/core/pattern/select/select_pattern_test_ng.cpp b/test/unittest/core/pattern/select/select_pattern_test_ng.cpp index 57edd760404c0b96e4885e391c8c0b9bad2e17f2..b87bcdb66f94efab9ca0b413449b6eac8ab4281e 100644 --- a/test/unittest/core/pattern/select/select_pattern_test_ng.cpp +++ b/test/unittest/core/pattern/select/select_pattern_test_ng.cpp @@ -2979,6 +2979,55 @@ HWTEST_F(SelectPatternTestNg, SetModifierByUser002, TestSize.Level1) ASSERT_NE(selectPattern->fontColor_, Color::GREEN); } +/** + * * @tc.name: FontColorByUser001 + * @tc.desc: Test FontColorByUser func. + * @tc.type: FUNC + */ +HWTEST_F(SelectPatternTestNg, FontColorByUser001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create select model, initialize frame node, obtain related objects. + * @tc.expected: step1. Select model and frame node are created successfully, related objects are obtained. + */ + SelectModelNG selectModelInstance; + std::vector params = { { OPTION_TEXT, FILE_SOURCE } }; + selectModelInstance.Create(params); + selectModelInstance.SetFontColorByUser(true); + auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + ASSERT_NE(select, nullptr); + auto props = select->GetPaintProperty(); + ASSERT_NE(props, nullptr); + EXPECT_TRUE(props->GetFontColorSetByUserValue(false)); + + /** + * @tc.steps: step2. call ResetFontColor. + * @tc.expected: step2. Font color is reset, FontColorSetByUser flag is updated. + */ + selectModelInstance.ResetFontColor(); + EXPECT_FALSE(props->GetFontColorSetByUserValue(false)); + + auto pipeline = select->GetContextWithCheck(); + ASSERT_NE(pipeline, nullptr); + auto selectTheme = pipeline->GetTheme(select->GetThemeScopeId()); + ASSERT_NE(selectTheme, nullptr); + auto selectPattern = select->GetPattern(); + ASSERT_NE(selectPattern, nullptr); + + /** + * @tc.steps: step3. Test UpdateComponentColor with BACKGROUND_COLOR. + * @tc.expected: The color is updated correctly. + */ + selectPattern->SetModifierByUser(selectTheme, props); + ASSERT_NE(selectPattern->text_, nullptr); + auto textProps = selectPattern->text_->GetLayoutProperty(); + ASSERT_NE(textProps, nullptr); + ASSERT_EQ(textProps->GetTextColor(), selectTheme->GetFontColor()); + auto context = selectPattern->text_->GetRenderContext(); + ASSERT_NE(context, nullptr); + ASSERT_EQ(context->GetForegroundColor(), selectTheme->GetFontColor()); +} + /** * @tc.name: SetOptionBgColorByUser001 * @tc.desc: Test SetOptionBgColorByUser func @@ -3111,55 +3160,6 @@ HWTEST_F(SelectPatternTestNg, SetColorByUser, TestSize.Level1) g_isConfigChangePerform = false; } -/** - * @tc.name: FontColorByUser001 - * @tc.desc: Test FontColorByUser func. - * @tc.type: FUNC - */ -HWTEST_F(SelectPatternTestNg, FontColorByUser001, TestSize.Level1) -{ - /** - * @tc.steps: step1. Create select model, initialize frame node, obtain related objects. - * @tc.expected: step1. Select model and frame node are created successfully, related objects are obtained. - */ - SelectModelNG selectModelInstance; - std::vector params = { { OPTION_TEXT, FILE_SOURCE } }; - selectModelInstance.Create(params); - selectModelInstance.SetFontColorByUser(true); - auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); - ASSERT_NE(select, nullptr); - auto props = select->GetPaintProperty(); - ASSERT_NE(props, nullptr); - EXPECT_TRUE(props->GetFontColorSetByUserValue(false)); - - /** - * @tc.steps: step2. call ResetFontColor. - * @tc.expected: step2. Font color is reset, FontColorSetByUser flag is updated. - */ - selectModelInstance.ResetFontColor(); - EXPECT_FALSE(props->GetFontColorSetByUserValue(false)); - - auto pipeline = select->GetContextWithCheck(); - ASSERT_NE(pipeline, nullptr); - auto selectTheme = pipeline->GetTheme(select->GetThemeScopeId()); - ASSERT_NE(selectTheme, nullptr); - auto selectPattern = select->GetPattern(); - ASSERT_NE(selectPattern, nullptr); - - /** - * @tc.steps: step3. Test UpdateComponentColor with BACKGROUND_COLOR. - * @tc.expected: The color is updated correctly. - */ - selectPattern->SetModifierByUser(selectTheme, props); - ASSERT_NE(selectPattern->text_, nullptr); - auto textProps = selectPattern->text_->GetLayoutProperty(); - ASSERT_NE(textProps, nullptr); - ASSERT_EQ(textProps->GetTextColor(), selectTheme->GetFontColor()); - auto context = selectPattern->text_->GetRenderContext(); - ASSERT_NE(context, nullptr); - ASSERT_EQ(context->GetForegroundColor(), selectTheme->GetFontColor()); -} - /** * @tc.name: UpdateComponentColor001 * @tc.desc: Test UpdateComponentColor. diff --git a/test/unittest/core/pattern/select/select_test_ng.cpp b/test/unittest/core/pattern/select/select_test_ng.cpp index e296accff6b948591b805c3d5b044e01a79a353d..bcc1459f59d7a4c87cb5c81095f139f12b03779a 100644 --- a/test/unittest/core/pattern/select/select_test_ng.cpp +++ b/test/unittest/core/pattern/select/select_test_ng.cpp @@ -33,7 +33,6 @@ #include "core/components/scroll/scroll_bar_theme.h" #include "core/components/select/select_theme.h" #include "core/components/text/text_theme.h" -#include "core/components/text_field/textfield_theme.h" #include "core/components/theme/icon_theme.h" #include "core/components_ng/base/view_stack_processor.h" #include "core/components_ng/layout/layout_wrapper.h" @@ -57,7 +56,6 @@ using namespace testing; using namespace testing::ext; -using namespace OHOS::Ace::Framework; namespace OHOS::Ace::NG { namespace { @@ -113,15 +111,15 @@ class SelectTestNg : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); - void SetUp() override; void TearDown() override; void InitSelectTestNg(); - RefPtr frameNode_; - RefPtr selectPattern_; - RefPtr selectAccessibilityProperty_; protected: static RefPtr CreateSelect(const std::vector& value, const TestProperty& test); + + RefPtr frameNode_; + RefPtr selectPattern_; + RefPtr selectAccessibilityProperty_; }; void SelectTestNg::SetUpTestCase() @@ -141,8 +139,6 @@ void SelectTestNg::TearDownTestCase() MockPipelineContext::TearDown(); } -void SelectTestNg::SetUp() {} - void SelectTestNg::TearDown() { frameNode_ = nullptr; @@ -280,13 +276,9 @@ HWTEST_F(SelectTestNg, SelectSetMenuAlign001, TestSize.Level1) { OPTION_TEXT_2, INTERNAL_SOURCE } }; selectModelInstance.Create(params); MenuAlign menuAlign; - /** - * @tc.cases: case1. verify the SetMenuAlign function. - */ menuAlign.alignType = MenuAlignType::END; menuAlign.offset = DimensionOffset(Dimension(OFFSETX, DimensionUnit::VP), Dimension(OFFSETY, DimensionUnit::VP)); auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); - ASSERT_FALSE(select->GetChildren().empty()); EXPECT_TRUE(select && select->GetTag() == V2::SELECT_ETS_TAG); auto selectPattern = select->GetPattern(); ASSERT_NE(selectPattern, nullptr); @@ -367,7 +359,7 @@ HWTEST_F(SelectTestNg, OnModifyDone001, TestSize.Level1) */ selectPattern->OnModifyDone(); auto host = selectPattern->GetHost(); - EXPECT_NE(host->GetOrCreateEventHub(), nullptr); + EXPECT_NE(host->GetEventHub(), nullptr); } /** * @tc.name: UpdateSelectedProps001 @@ -1954,7 +1946,7 @@ HWTEST_F(SelectTestNg, OnAfterModifyDone001, TestSize.Level1) */ selectPattern->OnAfterModifyDone(); auto host = selectPattern->GetHost(); - EXPECT_NE(host->GetOrCreateEventHub(), nullptr); + EXPECT_NE(host->GetEventHub(), nullptr); } /** @@ -2292,6 +2284,31 @@ HWTEST_F(SelectTestNg, SelectLayoutPropertyTest007, TestSize.Level1) EXPECT_EQ(icon->GetTag(), V2::SYMBOL_ETS_TAG); } +/** + * @tc.name: SelectLayoutPropertyTest008 + * @tc.desc: Test Select set textDirection. + * @tc.type: FUNC + */ +HWTEST_F(SelectTestNg, SelectLayoutPropertyTest008, TestSize.Level1) +{ + SelectModelNG selectModelInstance; + // create select + std::vector params = { {OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT, INTERNAL_SOURCE}, + { OPTION_TEXT_2, INTERNAL_SOURCE } }; + selectModelInstance.Create(params); + auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + ASSERT_NE(select, nullptr); + auto selectPattern = select->GetPattern(); + /** + * @tc.cases: case1. verify the SetLayoutDirection function. + */ + selectPattern->SetLayoutDirection(TextDirection::RTL); + auto layoutProps = selectPattern->GetLayoutProperty(); + ASSERT_NE(layoutProps, nullptr); + auto direction = layoutProps->GetNonAutoLayoutDirection(); + ASSERT_EQ(direction, TextDirection::RTL); +} + /** * @tc.name: SelectMenuOutline001 * @tc.desc: Test SelectModelNG SelectMenuOutline.