From 58adb1eadad8fa1281b7ec86fa544fa7d31fd3fd Mon Sep 17 00:00:00 2001 From: FredTT Date: Thu, 14 Aug 2025 15:41:29 +0800 Subject: [PATCH] =?UTF-8?q?optional=20=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: FredTT --- .../bridge/declarative_frontend/jsview/js_radio.cpp | 3 ++- .../components_ng/pattern/button/button_model_ng.cpp | 2 +- .../components_ng/pattern/button/button_pattern.cpp | 1 + .../pattern/button/toggle_button_pattern.cpp | 4 ++-- .../components_ng/pattern/dialog/dialog_pattern.cpp | 4 ++-- .../menu/menu_item/menu_item_layout_algorithm.cpp | 4 ++-- .../pattern/menu/menu_item/menu_item_pattern.cpp | 4 ++-- .../pattern/menu/menu_layout_algorithm.cpp | 4 ++-- .../core/components_ng/pattern/menu/menu_pattern.cpp | 2 +- .../pattern/menu/multi_menu_layout_algorithm.cpp | 4 ++-- .../pattern/overlay/overlay_manager.cpp | 8 ++++---- .../pattern/radio/radio_layout_algorithm.cpp | 4 ++-- .../components_ng/pattern/radio/radio_pattern.cpp | 2 +- .../components_ng/pattern/rating/rating_pattern.cpp | 8 ++++---- .../pattern/toggle/switch_layout_algorithm.cpp | 4 ++-- .../components_ng/pattern/toggle/switch_pattern.cpp | 12 ++++++------ 16 files changed, 36 insertions(+), 34 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_radio.cpp b/frameworks/bridge/declarative_frontend/jsview/js_radio.cpp index f985aa872a9..32225fb50d5 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_radio.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_radio.cpp @@ -93,7 +93,8 @@ void JSRadio::Create(const JSCallbackInfo& info) void JSRadio::ParseIndicator(const JSCallbackInfo& info, std::optional& indicator, std::function& customBuilderFunc, JSRef& builderObject) { - if (indicator.value() == static_cast(RadioIndicatorType::CUSTOM)) { + if (indicator.value_or(static_cast(RadioIndicatorType::TICK)) == + static_cast(RadioIndicatorType::CUSTOM)) { if (builderObject->IsFunction()) { auto builderFunc = AceType::MakeRefPtr(info.This(), JSRef::Cast(builderObject)); CHECK_NULL_VOID(builderFunc); diff --git a/frameworks/core/components_ng/pattern/button/button_model_ng.cpp b/frameworks/core/components_ng/pattern/button/button_model_ng.cpp index 73ea8a69454..53aefdf6a6b 100644 --- a/frameworks/core/components_ng/pattern/button/button_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/button/button_model_ng.cpp @@ -513,7 +513,7 @@ void ButtonModelNG::SetControlSize(FrameNode* frameNode, const std::optional>& buttonChildren) { - CreateWithLabel(para.label.value()); + CreateWithLabel(para.label.value_or("")); SetTypeAndStateEffect(para.type, para.stateEffect); SetButtonStyle(para.buttonStyleMode); SetControlSize(para.controlSize); diff --git a/frameworks/core/components_ng/pattern/button/button_pattern.cpp b/frameworks/core/components_ng/pattern/button/button_pattern.cpp index 50b8104c86a..14e5f440ce9 100644 --- a/frameworks/core/components_ng/pattern/button/button_pattern.cpp +++ b/frameworks/core/components_ng/pattern/button/button_pattern.cpp @@ -1223,6 +1223,7 @@ void ButtonPattern::FireBuilder() RefPtr ButtonPattern::BuildContentModifierNode() { + CHECK_NULL_RETURN(makeFunc_, nullptr); auto host = GetHost(); CHECK_NULL_RETURN(host, nullptr); auto layoutProperty = GetLayoutProperty(); diff --git a/frameworks/core/components_ng/pattern/button/toggle_button_pattern.cpp b/frameworks/core/components_ng/pattern/button/toggle_button_pattern.cpp index 8bc907a0567..f594cdc2b3f 100644 --- a/frameworks/core/components_ng/pattern/button/toggle_button_pattern.cpp +++ b/frameworks/core/components_ng/pattern/button/toggle_button_pattern.cpp @@ -299,12 +299,12 @@ void ToggleButtonPattern::SetBlurButtonStyle(RefPtr& textNode, { CHECK_NULL_VOID(toggleTheme_); CHECK_NULL_VOID(renderContext); - if (isCheckedShadow_ && isOn_.value()) { + if (isCheckedShadow_ && isOn_.value_or(false)) { isCheckedShadow_ = false; ShadowStyle shadowStyle = static_cast(toggleTheme_->GetShadowNormal()); renderContext->UpdateBackShadow(Shadow::CreateShadow(shadowStyle)); } - if (isShadow_ && !isOn_.value()) { + if (isShadow_ && !isOn_.value_or(false)) { isShadow_ = false; renderContext->UpdateBackShadow(Shadow::CreateShadow(ShadowStyle::None)); } diff --git a/frameworks/core/components_ng/pattern/dialog/dialog_pattern.cpp b/frameworks/core/components_ng/pattern/dialog/dialog_pattern.cpp index 59197a2d696..6369d684445 100644 --- a/frameworks/core/components_ng/pattern/dialog/dialog_pattern.cpp +++ b/frameworks/core/components_ng/pattern/dialog/dialog_pattern.cpp @@ -901,7 +901,7 @@ RefPtr DialogPattern::CreateButton( // update background color auto renderContext = buttonNode->GetRenderContext(); CHECK_NULL_RETURN(renderContext, nullptr); - renderContext->UpdateBackgroundColor(bgColor.value()); + renderContext->UpdateBackgroundColor(bgColor.value_or(Color::TRANSPARENT)); // set button default height auto layoutProps = buttonNode->GetLayoutProperty(); @@ -1530,7 +1530,7 @@ void DialogPattern::UpdateButtonsPropertyForEachButton(RefPtr buttonF // update background color auto renderContext = buttonFrameNode->GetRenderContext(); CHECK_NULL_VOID(renderContext); - renderContext->UpdateBackgroundColor(bgColor.value()); + renderContext->UpdateBackgroundColor(bgColor.value_or(Color::TRANSPARENT)); auto buttonTextNode = DynamicCast(buttonFrameNode->GetFirstChild()); CHECK_NULL_VOID(buttonTextNode); auto buttonTextLayoutProperty = buttonTextNode->GetLayoutProperty(); 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 1e4a79d286e..a9216f20f2a 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 @@ -546,8 +546,8 @@ void MenuItemLayoutAlgorithm::MeasureOption(LayoutWrapper* layoutWrapper, const auto optionPattern = optionNode->GetPattern(); CHECK_NULL_VOID(optionPattern); - auto idealSize = CreateIdealSize( - layoutConstraint.value(), Axis::HORIZONTAL, props->GetMeasureType(MeasureType::MATCH_CONTENT), true); + auto idealSize = CreateIdealSize(layoutConstraint.value_or(LayoutConstraintF()), Axis::HORIZONTAL, + props->GetMeasureType(MeasureType::MATCH_CONTENT), true); float maxChildWidth = layoutConstraint->maxSize.Width() - horInterval_ * 2.0f; // measure child auto childConstraint = props->CreateChildConstraint(); diff --git a/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_pattern.cpp b/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_pattern.cpp index be1784d3bd0..13d037566d8 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_pattern.cpp +++ b/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_pattern.cpp @@ -2915,7 +2915,7 @@ float MenuItemPattern::GetSelectOptionWidth() auto optionPatintProperty = optionNode->GetPaintProperty(); CHECK_NULL_RETURN(optionPatintProperty, MIN_OPTION_WIDTH.ConvertToPx()); auto selectmodifiedwidth = optionPatintProperty->GetSelectModifiedWidth(); - finalWidth = selectmodifiedwidth.value(); + finalWidth = selectmodifiedwidth.value_or(0.0f); } else { finalWidth = defaultWidth; } @@ -2950,7 +2950,7 @@ std::string MenuItemPattern::GetText() CHECK_NULL_RETURN(text_, std::string()); auto textProps = text_->GetLayoutProperty(); CHECK_NULL_RETURN(textProps, std::string()); - return UtfUtils::Str16ToStr8(textProps->GetContentValue()); + return UtfUtils::Str16ToStr8(textProps->GetContentValue(u"")); } std::string MenuItemPattern::InspectorGetFont() 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 6a59d53558c..3bb976e9f79 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.cpp @@ -2581,7 +2581,7 @@ void MenuLayoutAlgorithm::UpdateConstraintHeight(LayoutWrapper* layoutWrapper, L if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_ELEVEN)) { if (menuPattern->IsHeightModifiedBySelect()) { auto menuLayoutProps = AceType::DynamicCast(layoutWrapper->GetLayoutProperty()); - auto selectModifiedHeight = menuLayoutProps->GetSelectModifiedHeight().value(); + auto selectModifiedHeight = menuLayoutProps->GetSelectModifiedHeight().value_or(0.0f); if (LessNotEqual(selectModifiedHeight, maxSpaceHeight)) { maxSpaceHeight = selectModifiedHeight; } @@ -2629,7 +2629,7 @@ void MenuLayoutAlgorithm::UpdateConstraintSelectHeight(LayoutWrapper* layoutWrap if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_ELEVEN)) { if (menuPattern->IsHeightModifiedBySelect()) { auto menuLayoutProps = AceType::DynamicCast(layoutWrapper->GetLayoutProperty()); - auto selectModifiedHeight = menuLayoutProps->GetSelectModifiedHeight().value(); + auto selectModifiedHeight = menuLayoutProps->GetSelectModifiedHeight().value_or(0.0f); if (LessNotEqual(selectModifiedHeight, maxSpaceHeight)) { maxSpaceHeight = selectModifiedHeight; } diff --git a/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp b/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp index f5b4ba0e63b..bd59fe31213 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp +++ b/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp @@ -2488,7 +2488,7 @@ float MenuPattern::GetSelectMenuWidth() if (IsWidthModifiedBySelect()) { auto menuLayoutProperty = GetLayoutProperty(); auto selectmodifiedwidth = menuLayoutProperty->GetSelectMenuModifiedWidth(); - finalWidth = selectmodifiedwidth.value(); + finalWidth = selectmodifiedwidth.value_or(0.0f); } else { finalWidth = defaultWidth; } diff --git a/frameworks/core/components_ng/pattern/menu/multi_menu_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/menu/multi_menu_layout_algorithm.cpp index 317ddecad32..2c4d10b528a 100644 --- a/frameworks/core/components_ng/pattern/menu/multi_menu_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/menu/multi_menu_layout_algorithm.cpp @@ -49,7 +49,7 @@ struct SelectOverlayRightClickMenuLayoutHelper { } childLayoutProperty->UpdateUserDefinedIdealSize( { CalcLength(1.0, DimensionUnit::PERCENT), CalcLength(0.0, DimensionUnit::AUTO) }); - constrainMinWidth.percentReference.SetWidth(constrainMinWidth.selfIdealSize.Width().value()); + constrainMinWidth.percentReference.SetWidth(constrainMinWidth.selfIdealSize.Width().value_or(0.0f)); auto row = child->GetChildByIndex(0); CHECK_NULL_VOID(row); auto layoutProperty = row->GetLayoutProperty(); @@ -400,7 +400,7 @@ void MultiMenuLayoutAlgorithm::UpdateSelfSize(LayoutWrapper* layoutWrapper, Layo CHECK_NULL_VOID(pattern); float contentHeight = 0.0f; - float contentWidth = childConstraint.selfIdealSize.Width().value(); + float contentWidth = childConstraint.selfIdealSize.Width().value_or(0.0f); for (const auto& child : layoutWrapper->GetAllChildrenWithBuild()) { if (!child) { TAG_LOGW(AceLogTag::ACE_MENU, "child is null in MultiMenu"); diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp index 0f0e3b8f45c..22148927924 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp @@ -5111,8 +5111,8 @@ void OverlayManager::HandleModalShow(std::function&& c // create modal page auto modalNode = FrameNode::CreateFrameNode(V2::MODAL_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), - AceType::MakeRefPtr( - targetId, static_cast(modalTransition.value()), std::move(callback))); + AceType::MakeRefPtr(targetId, + static_cast(modalTransition.value_or(ModalTransition::DEFAULT)), std::move(callback))); CHECK_NULL_VOID(modalNode); auto modalPagePattern = modalNode->GetPattern(); CHECK_NULL_VOID(modalPagePattern); @@ -6009,7 +6009,7 @@ SheetStyle OverlayManager::UpdateSheetStyle( { auto layoutProperty = sheetNode->GetLayoutProperty(); CHECK_NULL_RETURN(layoutProperty, sheetStyle); - auto currentStyle = layoutProperty->GetSheetStyleValue(); + auto currentStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); if (isPartialUpdate) { currentStyle.PartialUpdate(sheetStyle); } else { @@ -8938,7 +8938,7 @@ void OverlayManager::FireNavigationLifecycle(const RefPtr& node, int32_t } } else if (node->GetTag() == V2::SHEET_PAGE_TAG) { auto layoutProperty = frameNode->GetLayoutProperty(); - if (layoutProperty && layoutProperty->GetSheetStyleValue().showInPage.value_or(false)) { + if (layoutProperty && layoutProperty->GetSheetStyleValue(SheetStyle()).showInPage.value_or(false)) { return; } } diff --git a/frameworks/core/components_ng/pattern/radio/radio_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/radio/radio_layout_algorithm.cpp index f27e40612f4..444fa7a27de 100644 --- a/frameworks/core/components_ng/pattern/radio/radio_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/radio/radio_layout_algorithm.cpp @@ -50,8 +50,8 @@ std::optional RadioLayoutAlgorithm::MeasureContent( // Case 1: Width and height are set in the front end. if (contentConstraint.selfIdealSize.IsValid() && contentConstraint.selfIdealSize.IsNonNegative()) { - auto height = contentConstraint.selfIdealSize.Height().value(); - auto width = contentConstraint.selfIdealSize.Width().value(); + auto height = contentConstraint.selfIdealSize.Height().value_or(0.0f); + auto width = contentConstraint.selfIdealSize.Width().value_or(0.0f); auto length = std::min(width, height); return SizeF(length, length); } diff --git a/frameworks/core/components_ng/pattern/radio/radio_pattern.cpp b/frameworks/core/components_ng/pattern/radio/radio_pattern.cpp index a8aab8a748e..2166be469b5 100644 --- a/frameworks/core/components_ng/pattern/radio/radio_pattern.cpp +++ b/frameworks/core/components_ng/pattern/radio/radio_pattern.cpp @@ -99,7 +99,7 @@ void RadioPattern::UpdateIndicatorType() CHECK_NULL_VOID(renderContext); renderContext->UpdateTransformScale({ INDICATOR_MAX_SCALE, INDICATOR_MAX_SCALE }); renderContext->UpdateOpacity(1); - if (!radioPaintProperty->GetRadioCheckValue()) { + if (!radioPaintProperty->GetRadioCheckValue(false)) { SetBuilderState(); } } diff --git a/frameworks/core/components_ng/pattern/rating/rating_pattern.cpp b/frameworks/core/components_ng/pattern/rating/rating_pattern.cpp index 9073f2ca895..a15ac847e30 100644 --- a/frameworks/core/components_ng/pattern/rating/rating_pattern.cpp +++ b/frameworks/core/components_ng/pattern/rating/rating_pattern.cpp @@ -360,7 +360,7 @@ void RatingPattern::RecalculatedRatingScoreBasedOnEventPoint(double eventPointX, ratingScore = (ratingScore < 0.0) ? 0.0 : ratingScore; const double newDrawScore = fmin(ceil(ratingScore / stepSize) * stepSize, starNum); // step3.2: Determine whether the old and new ratingScores are same or not. - const double oldRatingScore = ratingRenderProperty->GetRatingScoreValue(); + const double oldRatingScore = ratingRenderProperty->GetRatingScoreValue(0.0); const double oldDrawScore = fmin(Round(oldRatingScore / stepSize) * stepSize, static_cast(starNum)); CHECK_NULL_VOID(!NearEqual(newDrawScore, oldDrawScore)); @@ -400,9 +400,9 @@ void RatingPattern::FireChangeEvent() auto ratingRenderProperty = GetPaintProperty(); CHECK_NULL_VOID(ratingRenderProperty); std::stringstream ss; - ss << std::setprecision(2) << ratingRenderProperty->GetRatingScoreValue(); + ss << std::setprecision(2) << ratingRenderProperty->GetRatingScoreValue(0.0); ratingEventHub->FireChangeEvent(ss.str()); - lastRatingScore_ = ratingRenderProperty->GetRatingScoreValue(); + lastRatingScore_ = ratingRenderProperty->GetRatingScoreValue(0.0); if (!Recorder::EventRecorder::Get().IsComponentRecordEnable()) { return; @@ -717,7 +717,7 @@ void RatingPattern::OnBlurEvent() RemoveIsFocusActiveUpdateEvent(); auto ratingRenderProperty = GetPaintProperty(); CHECK_NULL_VOID(ratingRenderProperty); - focusRatingScore_ = ratingRenderProperty->GetRatingScoreValue(); + focusRatingScore_ = ratingRenderProperty->GetRatingScoreValue(0.0); MarkDirtyNode(PROPERTY_UPDATE_RENDER); } diff --git a/frameworks/core/components_ng/pattern/toggle/switch_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/toggle/switch_layout_algorithm.cpp index 49498720375..3ffb09b13b0 100644 --- a/frameworks/core/components_ng/pattern/toggle/switch_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/toggle/switch_layout_algorithm.cpp @@ -46,7 +46,7 @@ std::optional SwitchLayoutAlgorithm::MeasureContent( frameWidth = contentConstraint.selfIdealSize.Width().value(); } else { auto width = (switchTheme->GetWidth() - switchTheme->GetHotZoneHorizontalPadding() * 2).ConvertToPx(); - frameWidth = static_cast(width) - padding.left.value() - padding.right.value(); + frameWidth = static_cast(width) - padding.left.value_or(0.0f) - padding.right.value_or(0.0f); if (frameWidth > contentConstraint.maxSize.Width()) { frameWidth = contentConstraint.maxSize.Width(); } @@ -55,7 +55,7 @@ std::optional SwitchLayoutAlgorithm::MeasureContent( frameHeight = contentConstraint.selfIdealSize.Height().value(); } else { auto height = (switchTheme->GetHeight() - switchTheme->GetHotZoneVerticalPadding() * 2).ConvertToPx(); - frameHeight = static_cast(height) - padding.top.value() - padding.bottom.value(); + frameHeight = static_cast(height) - padding.top.value_or(0.0f) - padding.bottom.value_or(0.0f); if (frameHeight > contentConstraint.maxSize.Height()) { frameHeight = contentConstraint.maxSize.Height(); } diff --git a/frameworks/core/components_ng/pattern/toggle/switch_pattern.cpp b/frameworks/core/components_ng/pattern/toggle/switch_pattern.cpp index 90ad7c9dcf7..78113825b07 100644 --- a/frameworks/core/components_ng/pattern/toggle/switch_pattern.cpp +++ b/frameworks/core/components_ng/pattern/toggle/switch_pattern.cpp @@ -357,7 +357,7 @@ void SwitchPattern::OnChange() CHECK_NULL_VOID(paintMethod_); auto switchModifier = paintMethod_->GetSwitchModifier(); CHECK_NULL_VOID(switchModifier); - switchModifier->SetIsOn(isOn_.value()); + switchModifier->SetIsOn(isOn_.value_or(false)); switchPaintProperty->UpdateIsOn(isOn_.value_or(false)); UpdateChangeEvent(); host->MarkDirtyNode(PROPERTY_UPDATE_RENDER); @@ -386,7 +386,7 @@ void SwitchPattern::UpdateChangeEvent() const { auto switchEventHub = GetOrCreateEventHub(); CHECK_NULL_VOID(switchEventHub); - switchEventHub->UpdateChangeEvent(isOn_.value()); + switchEventHub->UpdateChangeEvent(isOn_.value_or(false)); } void SwitchPattern::OnClick() @@ -687,11 +687,11 @@ void SwitchPattern::HandleDragEnd() auto mainSize = GetSwitchWidth(); auto contentOffset = GetSwitchContentOffsetX(); if ((direction_ == TextDirection::RTL && - ((isOn_.value() && dragOffsetX_ - contentOffset > mainSize / 2) || - (!isOn_.value() && dragOffsetX_ - contentOffset <= mainSize / 2))) || + ((isOn_.value_or(false) && dragOffsetX_ - contentOffset > mainSize / 2) || + (!isOn_.value_or(false) && dragOffsetX_ - contentOffset <= mainSize / 2))) || (direction_ != TextDirection::RTL && - ((isOn_.value() && dragOffsetX_ - contentOffset < mainSize / 2) || - (!isOn_.value() && dragOffsetX_ - contentOffset >= mainSize / 2)))) { + ((isOn_.value_or(false) && dragOffsetX_ - contentOffset < mainSize / 2) || + (!isOn_.value_or(false) && dragOffsetX_ - contentOffset >= mainSize / 2)))) { OnClick(); } isDragEvent_ = false; -- Gitee