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 b76a1a1319f45fa2315caf4ac65bf47dea68790c..ac1f9a900540c85e724afc91c06031f1eb408fba 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 d83f94c35c3560f97b5aebd1275e11138e2b2927..48f7012f2362d7f842d91e31bd4b4c28a43b577f 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 2e3a36e3f814a657beca8a3385685aa2db433105..81f40c5991a7ec49aee3e83524cd9badeeabde46 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 f51c3edccaf3fe70d618c9ea78806f64808a4c42..77026b518e12c85c2082538c1bdaad9fa479efd9 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 da1185c51a2a5a66bec35b5642ba75d4f65f1f3f..4c56f104a31019dbab45f7396923713ce3604491 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 628b772f133f63848c0d5a37cb5159399157a4fc..8cb7a8de2707b7a968a03cb33ae346a3ff300780 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 a1b683259813d74a4b44471091aaefe7d5b1debe..f69b2d6797757a4cea26878ceca8c6eb87f10ae0 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 30bd01e52f27d60af39812bd419624b8a8484c82..b593c43252fc69d6d18168f14fa12103a7a7cdcd 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 80bb6403dfa02185ea73f59248989b4bcac135d4..314819d9631033dc5c352a05a563479f7703deb7 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 40b2ed9204ff93083c612b69c1dc0acbfa93f231..901d678d5122cc551284422d5fde99378389db28 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 195821c3f5116ac45cc70adc4824ed100b62b358..1165f151e389652cd8423f446293827e5f9e924d 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 530a7f76135aed4b389a2170a0110d4de85a9427..8d7f25ddcc2ffe81931cfe8d17a6e81aac17b41b 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 0aed7056ae20dc30014eb946a44df5d2f7551c71..d3f53ad9353f5f0d118d8831877beb9283121b02 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 d20dc7179c55df3106ade96e770e0599d1032327..fa7b82aee9191d98fb49bad83d382ea4efb9df46 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 1d97523394c5ff107883f0a57c1de4e34f34b7e8..410c689df1b0728b8d03e08e30aef0dff6e5d778 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 2bc6b3d40a88b2a8466ecc3dfe302ce63b11e24c..b69fa9f7828f27fc7ed648271416c3470fb344b9 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 52927a9dbb3311bf52816b8e65f4b0c66ce26a2f..ba5502bd816f06563ceac328d1ccf3414ac73ce1 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 02fedbf17d0f9ddc42ba87eb6e61d1f909eaaa1c..8dcbe2bb2586f01c760fa88b8def5b33b1ec4c94 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 9b7811310b3f451fa01f0393504f235c6f13094b..6cc7c31b1faf241544f38abc4681b676dd600abb 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)