From e8a399823e559e49d5b6d0a6af5e11503cdbac89 Mon Sep 17 00:00:00 2001 From: FredTT Date: Fri, 12 Sep 2025 15:43:23 +0800 Subject: [PATCH] change select Signed-off-by: FredTT --- .../interfaces/cj_ffi/cj_select_ffi.cpp | 2 ++ .../declarative_frontend/jsview/js_select.cpp | 2 ++ .../menu_item/menu_item_layout_algorithm.cpp | 24 ++++++++++----- .../pattern/menu/menu_layout_algorithm.cpp | 13 +++++---- .../pattern/menu/menu_layout_property.h | 2 ++ .../pattern/menu/menu_pattern.cpp | 29 +++++++++++++++++++ .../components_ng/pattern/menu/menu_pattern.h | 1 + .../components_ng/pattern/menu/menu_view.cpp | 1 + .../scroll/scroll_layout_algorithm.cpp | 8 +++-- .../pattern/scroll/scroll_pattern.cpp | 10 +++++++ .../pattern/scroll/scroll_pattern.h | 7 +++++ .../pattern/select/select_layout_property.h | 2 ++ .../pattern/select/select_model.h | 6 ++++ .../pattern/select/select_model_ng.cpp | 14 +++++++++ .../pattern/select/select_model_ng.h | 2 ++ .../pattern/select/select_pattern.cpp | 24 +++++++++++++++ .../pattern/select/select_pattern.h | 1 + .../native/implementation/select_modifier.cpp | 5 ++++ .../native/node/select_modifier.cpp | 5 ++++ 19 files changed, 143 insertions(+), 15 deletions(-) diff --git a/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_select_ffi.cpp b/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_select_ffi.cpp index b76a1a1319f..ac1f9a90054 100644 --- a/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_select_ffi.cpp +++ b/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_select_ffi.cpp @@ -180,8 +180,10 @@ void FfiOHOSAceFrameworkSelectSetOptionWidthWithMode(const char* value) SelectModel::GetInstance()->SetHasOptionWidth(true); std::string modeFlag(value); if (modeFlag.compare("fit_content") == 0) { + SelectModel::GetInstance()->SetOptionWidthMode(OptionWidthMode::FIT_CONTENT); SelectModel::GetInstance()->SetOptionWidthFitTrigger(false); } else if (modeFlag.compare("fit_trigger") == 0) { + SelectModel::GetInstance()->SetOptionWidthMode(OptionWidthMode::FIT_TRIGGER); SelectModel::GetInstance()->SetOptionWidthFitTrigger(true); } else { LOGE("OptionWidth is null or undefined"); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_select.cpp b/frameworks/bridge/declarative_frontend/jsview/js_select.cpp index d83f94c35c3..48f7012f236 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_select.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_select.cpp @@ -822,8 +822,10 @@ void JSSelect::SetOptionWidth(const JSCallbackInfo& info) SelectModel::GetInstance()->SetHasOptionWidth(true); std::string modeFlag = info[0]->ToString(); if (modeFlag.compare("fit_content") == 0) { + SelectModel::GetInstance()->SetOptionWidthMode(OptionWidthMode::FIT_CONTENT); SelectModel::GetInstance()->SetOptionWidthFitTrigger(false); } else if (modeFlag.compare("fit_trigger") == 0) { + SelectModel::GetInstance()->SetOptionWidthMode(OptionWidthMode::FIT_TRIGGER); SelectModel::GetInstance()->SetOptionWidthFitTrigger(true); } else if (IsPercentStr(modeFlag)) { return; diff --git a/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_layout_algorithm.cpp index 2e3a36e3f81..81f40c5991a 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_layout_algorithm.cpp @@ -497,11 +497,16 @@ void MenuItemLayoutAlgorithm::MeasureMenuItem(LayoutWrapper* layoutWrapper, cons auto pattern = menuItemNode->GetPattern(); CHECK_NULL_VOID(pattern); if (isOption_ && showDefaultSelectedIcon_) { - if (pattern->IsSelectOption() && pattern->GetHasOptionWidth()) { - auto selectOptionWidth = pattern->GetSelectOptionWidth(); - layoutConstraint->minSize.SetWidth(selectOptionWidth); - layoutConstraint->maxSize.SetWidth(selectOptionWidth); - layoutConstraint->selfIdealSize.SetWidth(selectOptionWidth); + if (pattern->IsSelectOption()) { + auto menuPattern = pattern->GetMenuPattern(); + CHECK_NULL_VOID(menuPattern); + auto optional = menuPattern->GetSelectMenuWidthOptional(true); + if (optional.has_value()) { + auto selectOptionWidth = optional.value(); + layoutConstraint->minSize.SetWidth(selectOptionWidth); + layoutConstraint->maxSize.SetWidth(selectOptionWidth); + layoutConstraint->selfIdealSize.SetWidth(selectOptionWidth); + } } UpdateIconMargin(layoutWrapper); } @@ -580,8 +585,13 @@ void MenuItemLayoutAlgorithm::MeasureOption(LayoutWrapper* layoutWrapper, const } } idealSize.SetHeight(std::max(minOptionHeight, idealSize.Height())); - if (optionPattern->IsSelectOption() && optionPattern->GetHasOptionWidth()) { - idealSize.SetWidth(optionPattern->GetSelectOptionWidth()); + if (optionPattern->IsSelectOption()) { + auto menuPattern = optionPattern->GetMenuPattern(); + CHECK_NULL_VOID(menuPattern); + auto optional = menuPattern->GetSelectMenuWidthOptional(true); + if (optional.has_value()) { + idealSize.SetWidth(optional.value()); + } } if (rowChild && (rowChild->GetHostTag() == V2::PASTE_BUTTON_ETS_TAG)) { float dividerWidth = static_cast(selectTheme->GetDefaultDividerWidth().ConvertToPx()); diff --git a/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.cpp index f51c3edccaf..77026b518e1 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.cpp @@ -803,11 +803,14 @@ void MenuLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) // calculate menu main size auto childConstraint = CreateChildConstraint(layoutWrapper); - if (menuPattern->IsSelectMenu() && menuPattern->GetHasOptionWidth()) { - auto selectMenuWidth = menuPattern->GetSelectMenuWidth(); - childConstraint.maxSize.SetWidth(selectMenuWidth); - childConstraint.parentIdealSize.SetWidth(selectMenuWidth); - childConstraint.selfIdealSize.SetWidth(selectMenuWidth); + if (menuPattern->IsSelectMenu()) { + auto optional = menuPattern->GetSelectMenuWidthOptional(); + if (optional.has_value()) { + auto selectMenuWidth = optional.value(); + childConstraint.maxSize.SetWidth(selectMenuWidth); + childConstraint.parentIdealSize.SetWidth(selectMenuWidth); + childConstraint.selfIdealSize.SetWidth(selectMenuWidth); + } } // The menu width child Constraint is added to the 2in1 device in API13 diff --git a/frameworks/core/components_ng/pattern/menu/menu_layout_property.h b/frameworks/core/components_ng/pattern/menu/menu_layout_property.h index da1185c51a2..4c56f104a31 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_layout_property.h +++ b/frameworks/core/components_ng/pattern/menu/menu_layout_property.h @@ -133,6 +133,8 @@ public: ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SelectMenuModifiedWidth, float, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SelectModifiedHeight, float, PROPERTY_UPDATE_MEASURE); + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(OptionWidth, Dimension, PROPERTY_UPDATE_NORMAL); + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(OptionWidthMode, OptionWidthMode, PROPERTY_UPDATE_NORMAL); ACE_DEFINE_PROPERTY_GROUP(MenuItemFontStyle, MenuItemFontStyle); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(MenuItemFontStyle, FontSize, Dimension, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(MenuItemFontStyle, FontColor, Color, PROPERTY_UPDATE_MEASURE); diff --git a/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp b/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp index 628b772f133..8cb7a8de270 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp +++ b/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp @@ -462,6 +462,7 @@ void MenuPattern::FireBuilder() auto scrollPattern = scroll->GetPattern(); CHECK_NULL_VOID(scrollPattern); scrollPattern->SetIsSelectScroll(true); + scrollPattern->BindSelectMenu(host); scroll->MountToParent(host); scroll->MarkModifyDone(); host->MarkModifyDone(); @@ -2871,4 +2872,32 @@ bool MenuPattern::IsSelectOverlayDefaultModeRightClickMenu() CHECK_NULL_RETURN(menuWrapperPattern, false); return !menuWrapperPattern->GetIsSelectOverlaySubWindowWrapper(); } + +std::optional MenuPattern::GetSelectMenuWidthOptional(bool isOption) +{ + if (!hasOptionWidth_) { + return std::nullopt; + } + auto optionOffset = isOption ? OPTION_MARGIN.ConvertToPx() : 0; + auto defaultMinWidth = MIN_SELECT_MENU_WIDTH.ConvertToPx() - optionOffset; + RefPtr columnInfo = GridSystemManager::GetInstance().GetInfoByType(GridColumnType::MENU); + CHECK_NULL_RETURN(columnInfo, defaultMinWidth); + auto parent = columnInfo->GetParent(); + CHECK_NULL_RETURN(parent, defaultMinWidth); + parent->BuildColumnWidth(); + auto defaultWidth = static_cast(columnInfo->GetWidth(COLUMN_NUM)) - optionOffset; + float finalWidth = defaultMinWidth; + auto menuLayoutProperty = GetLayoutProperty(); + CHECK_NULL_RETURN(parent, defaultMinWidth); + if (menuLayoutProperty->GetOptionWidthModeValue(OptionWidthMode::FIT_CONTENT) == OptionWidthMode::FIT_TRIGGER) { + finalWidth = targetSize_.Width() - optionOffset; + } else if (menuLayoutProperty->HasOptionWidth()) { + finalWidth = menuLayoutProperty->GetOptionWidthValue().ConvertToPx() - optionOffset; + } + + if (LessNotEqual(finalWidth, defaultMinWidth)) { + finalWidth = defaultWidth; + } + return finalWidth; +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/menu/menu_pattern.h b/frameworks/core/components_ng/pattern/menu/menu_pattern.h index a1b68325981..f69b2d67977 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_pattern.h +++ b/frameworks/core/components_ng/pattern/menu/menu_pattern.h @@ -374,6 +374,7 @@ public: } float GetSelectMenuWidth(); + std::optional GetSelectMenuWidthOptional(bool isOption = false); void HideSubMenu(); void OnModifyDone() override; diff --git a/frameworks/core/components_ng/pattern/menu/menu_view.cpp b/frameworks/core/components_ng/pattern/menu/menu_view.cpp index 30bd01e52f2..b593c43252f 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_view.cpp +++ b/frameworks/core/components_ng/pattern/menu/menu_view.cpp @@ -1666,6 +1666,7 @@ RefPtr MenuView::Create( auto scrollPattern = scroll->GetPattern(); CHECK_NULL_RETURN(scrollPattern, nullptr); scrollPattern->SetIsSelectScroll(true); + scrollPattern->BindSelectMenu(menuNode); scroll->MountToParent(menuNode); scroll->MarkModifyDone(); menuPattern->SetIsSelectMenu(true); diff --git a/frameworks/core/components_ng/pattern/scroll/scroll_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/scroll/scroll_layout_algorithm.cpp index 80bb6403dfa..314819d9631 100644 --- a/frameworks/core/components_ng/pattern/scroll/scroll_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/scroll/scroll_layout_algorithm.cpp @@ -94,9 +94,11 @@ void ScrollLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) CHECK_NULL_VOID(scrollNode); auto scrollPattern = scrollNode->GetPattern(); CHECK_NULL_VOID(scrollPattern); - if (scrollPattern->IsSelectScroll() && scrollPattern->GetHasOptionWidth()) { - auto selectScrollWidth = scrollPattern->GetSelectScrollWidth(); - selfSize.SetWidth(selectScrollWidth); + if (scrollPattern->IsSelectScroll()) { + auto selectScrollWidth = scrollPattern->GetSelectScrollWidthOptional(); + if (selectScrollWidth.has_value()) { + selfSize.SetWidth(selectScrollWidth.value()); + } } auto lastViewSize = scrollPattern->GetViewSize(); auto lastViewPortExtent = scrollPattern->GetViewPortExtent(); diff --git a/frameworks/core/components_ng/pattern/scroll/scroll_pattern.cpp b/frameworks/core/components_ng/pattern/scroll/scroll_pattern.cpp index 40b2ed9204f..901d678d512 100644 --- a/frameworks/core/components_ng/pattern/scroll/scroll_pattern.cpp +++ b/frameworks/core/components_ng/pattern/scroll/scroll_pattern.cpp @@ -17,6 +17,7 @@ #include "base/log/dump_log.h" #include "core/components_ng/pattern/scrollable/scrollable_animation_consts.h" +#include "core/components_ng/pattern/menu/menu_pattern.h" #include "core/components_ng/property/measure_utils.h" namespace OHOS::Ace::NG { @@ -1271,6 +1272,15 @@ float ScrollPattern::GetSelectScrollWidth() return finalWidth; } +std::optional ScrollPattern::GetSelectScrollWidthOptional() +{ + auto menuNode = weakMenuNode_.Upgrade(); + CHECK_NULL_RETURN(menuNode, std::nullopt); + auto pattern = menuNode->GetPattern(); + CHECK_NULL_RETURN(pattern, std::nullopt); + return pattern->GetSelectMenuWidthOptional(); +} + float ScrollPattern::GetPagingOffset(float delta, float dragDistance, float velocity) const { // handle last page diff --git a/frameworks/core/components_ng/pattern/scroll/scroll_pattern.h b/frameworks/core/components_ng/pattern/scroll/scroll_pattern.h index 195821c3f51..1165f151e38 100644 --- a/frameworks/core/components_ng/pattern/scroll/scroll_pattern.h +++ b/frameworks/core/components_ng/pattern/scroll/scroll_pattern.h @@ -204,6 +204,7 @@ public: void CaleSnapOffsetsByPaginations(ScrollSnapAlign scrollSnapAlign); float GetSelectScrollWidth(); + std::optional GetSelectScrollWidthOptional(); bool IsSnapToInterval() const { @@ -305,6 +306,11 @@ public: isSelectScroll_ = isSelect; } + void BindSelectMenu(WeakPtr weakMenuNode) + { + weakMenuNode_ = weakMenuNode; + } + bool IsSelectScroll() const { return isSelectScroll_; @@ -522,6 +528,7 @@ private: // dump info std::list scrollLayoutInfos_; std::list scrollMeasureInfos_; + WeakPtr weakMenuNode_ = nullptr; #ifdef SUPPORT_DIGITAL_CROWN int32_t crownEventNum_ = 0; diff --git a/frameworks/core/components_ng/pattern/select/select_layout_property.h b/frameworks/core/components_ng/pattern/select/select_layout_property.h index 530a7f76135..8d7f25ddcc2 100644 --- a/frameworks/core/components_ng/pattern/select/select_layout_property.h +++ b/frameworks/core/components_ng/pattern/select/select_layout_property.h @@ -55,6 +55,8 @@ public: ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ShowInSubWindow, bool, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ShowDefaultSelectedIcon, bool, PROPERTY_UPDATE_MEASURE); + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(OptionWidth, Dimension, PROPERTY_UPDATE_NORMAL); + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(OptionWidthMode, OptionWidthMode, PROPERTY_UPDATE_NORMAL); void ToJsonValue(std::unique_ptr& json, const InspectorFilter& filter) const override { diff --git a/frameworks/core/components_ng/pattern/select/select_model.h b/frameworks/core/components_ng/pattern/select/select_model.h index 0aed7056ae2..d3f53ad9353 100644 --- a/frameworks/core/components_ng/pattern/select/select_model.h +++ b/frameworks/core/components_ng/pattern/select/select_model.h @@ -57,6 +57,11 @@ enum class MenuAlignType { END, }; +enum class OptionWidthMode { + FIT_CONTENT = 0, + FIT_TRIGGER +} + struct MenuAlign { MenuAlignType alignType = MenuAlignType::START; DimensionOffset offset = DimensionOffset(Dimension(0, DimensionUnit::VP), Dimension(0, DimensionUnit::VP)); @@ -155,6 +160,7 @@ public: virtual void SetSelectedOptionFontColorByUser(bool isValidValue = true) {}; virtual void SetOptionBgColorByUser(bool isValidValue = true) {}; virtual void SetSelectedOptionBgColorByUser(bool isValidValue = true) {}; + virtual void SetOptionWidthMode(const OptionWidthMode& optionWidthMode) {}; private: static std::unique_ptr instance_; 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 d20dc7179c5..fa7b82aee91 100644 --- a/frameworks/core/components_ng/pattern/select/select_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/select/select_model_ng.cpp @@ -407,6 +407,20 @@ void SelectModelNG::SetOptionWidth(const Dimension& value) pattern->SetOptionWidth(value); } +void SelectModelNG::SetOptionWidthMode(const OptionWidthMode& optionWidthMode) +{ + auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); + CHECK_NULL_VOID(pattern); + pattern->SetOptionWidthMode(optionWidthMode); +} + +void SelectModelNG::SetOptionWidthMode(FrameNode* frameNode, const OptionWidthMode& optionWidthMode) +{ + auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(frameNode); + CHECK_NULL_VOID(pattern); + pattern->SetOptionWidthMode(optionWidthMode); +} + void SelectModelNG::SetOptionHeight(const Dimension& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); 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 1d97523394c..410c689df1b 100644 --- a/frameworks/core/components_ng/pattern/select/select_model_ng.h +++ b/frameworks/core/components_ng/pattern/select/select_model_ng.h @@ -114,6 +114,7 @@ public: void SetShowDefaultSelectedIcon(bool show) override; void ResetShowDefaultSelectedIcon() override; void SetMenuOutline(const MenuParam& menuParam) override; + void SetOptionWidthMode(const OptionWidthMode& optionWidthMode) override; static RefPtr CreateFrameNode(int32_t nodeId); static void InitSelect(FrameNode* frameNode, const std::vector& params); @@ -170,6 +171,7 @@ public: static void SetOptionBgColorByUser(FrameNode* frameNode, bool isValidValue = true); void SetSelectedOptionBgColorByUser(bool isValidValue = true) override; static void SetSelectedOptionBgColorByUser(FrameNode* frameNode, bool isValidValue = true); + static void SetOptionWidthMode(FrameNode* frameNode, const OptionWidthMode& optionWidthMode); private: void AddResObjWithCallBack( diff --git a/frameworks/core/components_ng/pattern/select/select_pattern.cpp b/frameworks/core/components_ng/pattern/select/select_pattern.cpp index 2bc6b3d40a8..b69fa9f7828 100644 --- a/frameworks/core/components_ng/pattern/select/select_pattern.cpp +++ b/frameworks/core/components_ng/pattern/select/select_pattern.cpp @@ -2096,6 +2096,12 @@ Dimension SelectPattern::GetFontSize() void SelectPattern::SetOptionWidth(const Dimension& value) { isFitTrigger_ = false; + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto layoutProps = host->GetLayoutProperty(); + CHECK_NULL_VOID(layoutProps); + layoutProps->ResetOptionWidthMode(); + layoutProps->UpdateOptionWidth(value); auto menu = GetMenuNode(); CHECK_NULL_VOID(menu); auto menuPattern = menu->GetPattern(); @@ -2103,6 +2109,8 @@ void SelectPattern::SetOptionWidth(const Dimension& value) menuPattern->SetIsWidthModifiedBySelect(true); auto menuLayoutProps = menu->GetLayoutProperty(); CHECK_NULL_VOID(menuLayoutProps); + menuLayoutProps->ResetOptionWidthMode(); + menuLayoutProps->UpdateOptionWidth(value); menuLayoutProps->UpdateSelectMenuModifiedWidth(value.ConvertToPx() + OPTION_MARGIN.ConvertToPx()); auto scroll = DynamicCast(menu->GetFirstChild()); @@ -2603,4 +2611,20 @@ void SelectPattern::SetModifierByUser(const RefPtr& theme, const Re SetSelectedOptionTextModifierByUser(theme, props); SetArrowModifierByUser(theme, props); } + +void SelectPattern::SetOptionWidthMode(const OptionWidthMode& optionWidthMode) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto layoutProps = host->GetLayoutProperty(); + CHECK_NULL_VOID(layoutProps); + layoutProps->UpdateOptionWidthMode(optionWidthMode); + auto menu = GetMenuNode(); + CHECK_NULL_VOID(menu); + auto menuPattern = menu->GetPattern(); + CHECK_NULL_VOID(menuPattern); + auto menuLayoutProps = menu->GetLayoutProperty(); + CHECK_NULL_VOID(menuLayoutProps); + menuLayoutProps->UpdateOptionWidthMode(optionWidthMode); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/select/select_pattern.h b/frameworks/core/components_ng/pattern/select/select_pattern.h index 52927a9dbb3..ba5502bd816 100644 --- a/frameworks/core/components_ng/pattern/select/select_pattern.h +++ b/frameworks/core/components_ng/pattern/select/select_pattern.h @@ -260,6 +260,7 @@ public: void SetMenuBackgroundColorByUser(const Color& color, const RefPtr& props); void SetModifierByUser(const RefPtr& theme, const RefPtr& props); void SetOptionBgColorByUser(const Color& color, const RefPtr& props); + void SetOptionWidthMode(const OptionWidthMode& optionWidthMode); private: void OnAttachToFrameNode() override; diff --git a/frameworks/core/interfaces/native/implementation/select_modifier.cpp b/frameworks/core/interfaces/native/implementation/select_modifier.cpp index 02fedbf17d0..8dcbe2bb258 100644 --- a/frameworks/core/interfaces/native/implementation/select_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/select_modifier.cpp @@ -379,6 +379,11 @@ void OptionWidth1Impl(Ark_NativePointer node, auto fit = Converter::OptConvert(value); SelectModelNG::SetHasOptionWidth(frameNode, true); SelectModelStatic::SetOptionWidthFitTrigger(frameNode, fit.value_or(true)); + if (fit.value_or(true)) { + SelectModelNG::SetOptionWidthMode(frameNode, OptionWidthMode::FIT_TRIGGER); + } else { + SelectModelNG::SetOptionWidthMode(frameNode, OptionWidthMode::FIT_CONTENT); + } }, []() {} ); diff --git a/frameworks/core/interfaces/native/node/select_modifier.cpp b/frameworks/core/interfaces/native/node/select_modifier.cpp index 9b7811310b3..6cc7c31b1fa 100644 --- a/frameworks/core/interfaces/native/node/select_modifier.cpp +++ b/frameworks/core/interfaces/native/node/select_modifier.cpp @@ -526,6 +526,11 @@ void SetSelectOptionWidthFitTrigger(ArkUINodeHandle node, ArkUI_Bool trigger) auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); SelectModelNG::SetOptionWidthFitTrigger(frameNode, trigger); + if (trigger) { + SelectModelNG::SetOptionWidthMode(frameNode, OptionWidthMode::FIT_TRIGGER); + } else { + SelectModelNG::SetOptionWidthMode(frameNode, OptionWidthMode::FIT_CONTENT); + } } void SetSelectOptionWidth(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 unit) -- Gitee