diff --git a/frameworks/core/components_ng/pattern/toast/toast_pattern.cpp b/frameworks/core/components_ng/pattern/toast/toast_pattern.cpp index 0b70cb4364f..9e58dc9bba6 100644 --- a/frameworks/core/components_ng/pattern/toast/toast_pattern.cpp +++ b/frameworks/core/components_ng/pattern/toast/toast_pattern.cpp @@ -183,7 +183,6 @@ void ToastPattern::BeforeCreateLayoutWrapper() TAG_LOGD(AceLogTag::ACE_OVERLAY, "toast get pipelineContext failed"); return; } - UpdateToastSize(toastNode); UpdateToastFontSize(); auto textNode = DynamicCast(toastNode->GetFirstChild()); diff --git a/frameworks/core/components_ng/pattern/toast/toast_view.cpp b/frameworks/core/components_ng/pattern/toast/toast_view.cpp index cb0897972df..19072f3be78 100644 --- a/frameworks/core/components_ng/pattern/toast/toast_view.cpp +++ b/frameworks/core/components_ng/pattern/toast/toast_view.cpp @@ -19,6 +19,7 @@ #include "base/utils/utils.h" #include "core/components/common/properties/shadow_config.h" #include "core/components/toast/toast_theme.h" +#include "core/components/theme/shadow_theme.h" #include "core/components_ng/pattern/text/text_layout_property.h" #include "core/components_ng/pattern/text/text_pattern.h" #include "core/components_ng/pattern/toast/toast_layout_property.h" @@ -60,7 +61,7 @@ RefPtr ToastView::CreateToastNode(const ToastInfo& toastInfo) pattern->SetToastInfo(toastInfo); pattern->SetTextNode(textNode); UpdateTextLayoutProperty(textNode, toastInfo.message, toastInfo.isRightToLeft); - UpdateTextContext(textNode); + UpdateToastContext(toastNode); textNode->MountToParent(toastNode); auto align = Alignment::ParseAlignment(toastInfo.alignment); if (align.has_value()) { @@ -108,16 +109,36 @@ void ToastView::UpdateTextLayoutProperty( textLayoutProperty->UpdatePadding(paddings); textLayoutProperty->UpdateTextColor(textColor); textLayoutProperty->UpdateFontWeight(fontWeight); + auto textContext = textNode->GetRenderContext(); + CHECK_NULL_VOID(textContext); + textContext->UpdateClipEdge(false); if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { textLayoutProperty->UpdateTextOverflow(TextOverflow::ELLIPSIS); textLayoutProperty->UpdateEllipsisMode(EllipsisMode::TAIL); } } -void ToastView::UpdateTextContext(const RefPtr& textNode) + +bool ToastView::GetShadowFromTheme(ShadowStyle shadowStyle, Shadow& shadow) { - auto textContext = textNode->GetRenderContext(); - CHECK_NULL_VOID(textContext); + auto colorMode = SystemProperties::GetColorMode(); + if (shadowStyle == ShadowStyle::None) { + return true; + } + auto pipelineContext = PipelineContext::GetCurrentContext(); + CHECK_NULL_RETURN(pipelineContext, false); + auto shadowTheme = pipelineContext->GetTheme(); + if (!shadowTheme) { + return false; + } + shadow = shadowTheme->GetShadow(shadowStyle, colorMode); + return true; +} + +void ToastView::UpdateToastContext(const RefPtr& toastNode) +{ + auto toastContext = toastNode->GetRenderContext(); + CHECK_NULL_VOID(toastContext); auto pipelineContext = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); auto toastTheme = pipelineContext->GetTheme(); @@ -125,36 +146,37 @@ void ToastView::UpdateTextContext(const RefPtr& textNode) auto radius = toastTheme->GetRadius(); BorderRadiusProperty borderRadius; borderRadius.SetRadius(Dimension(radius.GetX().ConvertToPx())); - textContext->UpdateBorderRadius(borderRadius); + toastContext->UpdateBorderRadius(borderRadius); if (toastTheme->GetToastDoubleBorderEnable()) { - textContext->UpdateOuterBorderRadius(borderRadius); + toastContext->UpdateOuterBorderRadius(borderRadius); BorderWidthProperty innerWidthProp; innerWidthProp.SetBorderWidth(Dimension(toastTheme->GetToastInnerBorderWidth())); - textContext->UpdateBorderWidth(innerWidthProp); + toastContext->UpdateBorderWidth(innerWidthProp); BorderColorProperty innerColorProp; innerColorProp.SetColor(toastTheme->GetToastInnerBorderColor()); - textContext->UpdateBorderColor(innerColorProp); + toastContext->UpdateBorderColor(innerColorProp); BorderWidthProperty outerWidthProp; outerWidthProp.SetBorderWidth(Dimension(toastTheme->GetToastOuterBorderWidth())); - textContext->UpdateOuterBorderWidth(outerWidthProp); + toastContext->UpdateOuterBorderWidth(outerWidthProp); BorderColorProperty outerColorProp; outerColorProp.SetColor(toastTheme->GetToastOuterBorderColor()); - textContext->UpdateOuterBorderColor(outerColorProp); + toastContext->UpdateOuterBorderColor(outerColorProp); + } + Shadow shadow; + if (GetShadowFromTheme(ShadowStyle::OuterDefaultMD, shadow)) { + toastContext->UpdateBackShadow(shadow); } - textContext->UpdateBackShadow(ShadowConfig::DefaultShadowL); - textContext->UpdateClipEdge(false); - if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { - textContext->UpdateBackgroundColor(Color::TRANSPARENT); + toastContext->UpdateBackgroundColor(Color::TRANSPARENT); BlurStyleOption styleOption; styleOption.blurStyle = BlurStyle::COMPONENT_ULTRA_THICK; styleOption.policy = BlurStyleActivePolicy::ALWAYS_ACTIVE; - textContext->UpdateBackBlurStyle(styleOption); + toastContext->UpdateBackBlurStyle(styleOption); } else { auto toastBackgroundColor = toastTheme->GetBackgroundColor(); - textContext->UpdateBackgroundColor(toastBackgroundColor); + toastContext->UpdateBackgroundColor(toastBackgroundColor); } } } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/toast/toast_view.h b/frameworks/core/components_ng/pattern/toast/toast_view.h index 8fc0d188047..c0db4152f14 100644 --- a/frameworks/core/components_ng/pattern/toast/toast_view.h +++ b/frameworks/core/components_ng/pattern/toast/toast_view.h @@ -31,7 +31,8 @@ public: private: static void UpdateTextLayoutProperty( const RefPtr& textNode, const std::string& message, bool isRightToLeft); - static void UpdateTextContext(const RefPtr& textNode); + static void UpdateToastContext(const RefPtr& toastContext); + static bool GetShadowFromTheme(ShadowStyle shadowStyle, Shadow& shadow); }; } // namespace OHOS::Ace::NG diff --git a/test/unittest/core/pattern/overlay/overlay_test_update.cpp b/test/unittest/core/pattern/overlay/overlay_test_update.cpp index 67b2c39d3e0..3fcf0c7119e 100644 --- a/test/unittest/core/pattern/overlay/overlay_test_update.cpp +++ b/test/unittest/core/pattern/overlay/overlay_test_update.cpp @@ -460,12 +460,14 @@ HWTEST_F(OverlayTestUpdate, ToastTest005, TestSize.Level1) /** * @tc.steps: step3. text textContext. */ - ToastView::UpdateTextContext(textNode); + ToastView::UpdateToastContext(toastNode); + auto toastContext = toastNode->GetRenderContext(); + ASSERT_NE(toastContext, nullptr); /** * @tc.steps: step4. GetBackBlurStyle GetBackgroundColorValue. */ - auto styleOption = textContext->GetBackBlurStyle(); - auto testval1 = textContext->GetBackgroundColorValue(); + auto styleOption = toastContext->GetBackBlurStyle(); + auto testval1 = toastContext->GetBackgroundColorValue(); EXPECT_EQ(testval1, Color::TRANSPARENT); EXPECT_EQ(styleOption->blurStyle, BlurStyle::COMPONENT_ULTRA_THICK); MockContainer::Current()->SetApiTargetVersion(backupApiVersion); @@ -506,14 +508,16 @@ HWTEST_F(OverlayTestUpdate, ToastTest006, TestSize.Level1) int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();; MockContainer::Current()->SetApiTargetVersion(settingApiVersion); /** - * @tc.steps: step3. test UpdateTextContext. + * @tc.steps: step3. test UpdateToastContext. */ - ToastView::UpdateTextContext(textNode); + ToastView::UpdateToastContext(toastNode); + auto toastContext = toastNode->GetRenderContext(); + ASSERT_NE(toastContext, nullptr); /** * @tc.steps: step4. GetBackBlurStyle GetBackgroundColorValue. */ - auto styleOption = textContext->GetBackBlurStyle(); - auto testval1 = textContext->GetBackgroundColorValue(); + auto styleOption = toastContext->GetBackBlurStyle(); + auto testval1 = toastContext->GetBackgroundColorValue(); EXPECT_EQ(testval1, Color::TRANSPARENT); EXPECT_EQ(styleOption->blurStyle, BlurStyle::COMPONENT_ULTRA_THICK); MockContainer::Current()->SetApiTargetVersion(backupApiVersion); @@ -554,14 +558,16 @@ HWTEST_F(OverlayTestUpdate, ToastTest007, TestSize.Level1) int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();; MockContainer::Current()->SetApiTargetVersion(settingApiVersion); /** - * @tc.steps: step5. Test UpdateTextContext. + * @tc.steps: step5. Test UpdateToastContext. */ - ToastView::UpdateTextContext(textNode); + ToastView::UpdateToastContext(toastNode); + auto toastContext = toastNode->GetRenderContext(); + ASSERT_NE(toastContext, nullptr); /** * @tc.steps: step6. GetBackBlurStyle and GetBackgroundColorValue. */ - auto styleOption = textContext->GetBackBlurStyle(); - auto testval1 = textContext->GetBackgroundColorValue(); + auto styleOption = toastContext->GetBackBlurStyle(); + auto testval1 = toastContext->GetBackgroundColorValue(); EXPECT_EQ(testval1, Color::TRANSPARENT); EXPECT_EQ(styleOption->blurStyle, BlurStyle::COMPONENT_ULTRA_THICK); MockContainer::Current()->SetApiTargetVersion(backupApiVersion); @@ -598,12 +604,14 @@ HWTEST_F(OverlayTestUpdate, ToastTest008, TestSize.Level1) int32_t settingApiVersion = VERSION_TWELVE; int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();; MockContainer::Current()->SetApiTargetVersion(settingApiVersion); - ToastView::UpdateTextContext(textNode); + ToastView::UpdateToastContext(toastNode); + auto toastContext = toastNode->GetRenderContext(); + ASSERT_NE(toastContext, nullptr); /** * @tc.steps: step4. text textContext. */ - auto styleOption = textContext->GetBackBlurStyle(); - auto testval1 = textContext->GetBackgroundColorValue(); + auto styleOption = toastContext->GetBackBlurStyle(); + auto testval1 = toastContext->GetBackgroundColorValue(); EXPECT_EQ(testval1, Color::TRANSPARENT); EXPECT_EQ(styleOption->blurStyle, BlurStyle::COMPONENT_ULTRA_THICK); MockContainer::Current()->SetApiTargetVersion(backupApiVersion); @@ -611,7 +619,7 @@ HWTEST_F(OverlayTestUpdate, ToastTest008, TestSize.Level1) /** * @tc.name: ToastTest009 - * @tc.desc: Test UpdateTextContext Low version change ToastView. + * @tc.desc: Test UpdateToastContext Low version change ToastView. * @tc.type: FUNC */ HWTEST_F(OverlayTestUpdate, ToastTest009, TestSize.Level1) @@ -649,22 +657,24 @@ HWTEST_F(OverlayTestUpdate, ToastTest009, TestSize.Level1) auto textLayoutProperty = textNode->GetLayoutProperty(); CHECK_NULL_VOID(textLayoutProperty); /** - * @tc.steps: step6. Change low version UpdateTextContext and Save. + * @tc.steps: step6. Change low version UpdateToastContext and Save. */ int32_t settingApiVersion = VERSION_ELEVEN; int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();; MockContainer::Current()->SetApiTargetVersion(settingApiVersion); /** - * @tc.steps: step7. text low version UpdateTextContext. + * @tc.steps: step7. text low version UpdateToastContext. */ - ToastView::UpdateTextContext(textNode); - EXPECT_EQ(textContext->GetBackgroundColorValue(), toastBackgroundColor); + ToastView::UpdateToastContext(toastNode); + auto toastContext = toastNode->GetRenderContext(); + ASSERT_NE(toastContext, nullptr); + EXPECT_EQ(toastContext->GetBackgroundColorValue(), toastBackgroundColor); MockContainer::Current()->SetApiTargetVersion(backupApiVersion); } /** * @tc.name: ToastTest010 - * @tc.desc: Test UpdateTextContext Low version change ToastView. + * @tc.desc: Test UpdateToastContext Low version change ToastView. * @tc.type: FUNC */ HWTEST_F(OverlayTestUpdate, ToastTest010, TestSize.Level1) @@ -704,22 +714,24 @@ HWTEST_F(OverlayTestUpdate, ToastTest010, TestSize.Level1) auto textLayoutProperty = textNode->GetLayoutProperty(); CHECK_NULL_VOID(textLayoutProperty); /** - * @tc.steps: step6. Change low version UpdateTextContext and Save. + * @tc.steps: step6. Change low version UpdateToastContext and Save. */ int32_t settingApiVersion = VERSION_ELEVEN; int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();; MockContainer::Current()->SetApiTargetVersion(settingApiVersion); /** - * @tc.steps: step7. text low version UpdateTextContext. + * @tc.steps: step7. text low version UpdateToastContext. */ - ToastView::UpdateTextContext(textNode); - EXPECT_EQ(textContext->GetBackgroundColorValue(), toastBackgroundColor); + ToastView::UpdateToastContext(toastNode); + auto toastContext = toastNode->GetRenderContext(); + ASSERT_NE(toastContext, nullptr); + EXPECT_EQ(toastContext->GetBackgroundColorValue(), toastBackgroundColor); MockContainer::Current()->SetApiTargetVersion(backupApiVersion); } /** * @tc.name: ToastTest011 - * @tc.desc: Test UpdateTextContext Low version change ToastView. + * @tc.desc: Test UpdateToastContext Low version change ToastView. * @tc.type: FUNC */ HWTEST_F(OverlayTestUpdate, ToastTest011, TestSize.Level1) @@ -759,22 +771,24 @@ HWTEST_F(OverlayTestUpdate, ToastTest011, TestSize.Level1) auto textLayoutProperty = textNode->GetLayoutProperty(); CHECK_NULL_VOID(textLayoutProperty); /** - * @tc.steps: step6. Change low version UpdateTextContext and Save. + * @tc.steps: step6. Change low version UpdateToastContext and Save. */ int32_t settingApiVersion = VERSION_ELEVEN; int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();; MockContainer::Current()->SetApiTargetVersion(settingApiVersion); /** - * @tc.steps: step7. text low version UpdateTextContext. + * @tc.steps: step7. text low version UpdateToastContext. */ - ToastView::UpdateTextContext(textNode); - EXPECT_EQ(textContext->GetBackgroundColorValue(), toastBackgroundColor); + ToastView::UpdateToastContext(toastNode); + auto toastContext = toastNode->GetRenderContext(); + ASSERT_NE(toastContext, nullptr); + EXPECT_EQ(toastContext->GetBackgroundColorValue(), toastBackgroundColor); MockContainer::Current()->SetApiTargetVersion(backupApiVersion); } /** * @tc.name: ToastTest012 - * @tc.desc: Test UpdateTextContext Low version change ToastView. + * @tc.desc: Test UpdateToastContext Low version change ToastView. * @tc.type: FUNC */ HWTEST_F(OverlayTestUpdate, ToastTest012, TestSize.Level1) @@ -814,16 +828,18 @@ HWTEST_F(OverlayTestUpdate, ToastTest012, TestSize.Level1) auto textLayoutProperty = textNode->GetLayoutProperty(); CHECK_NULL_VOID(textLayoutProperty); /** - * @tc.steps: step6. Change low version UpdateTextContext and Save. + * @tc.steps: step6. Change low version UpdateToastContext and Save. */ int32_t settingApiVersion = VERSION_ELEVEN; int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();; MockContainer::Current()->SetApiTargetVersion(settingApiVersion); /** - * @tc.steps: step7. text low version UpdateTextContext. + * @tc.steps: step7. text low version UpdateToastContext. */ - ToastView::UpdateTextContext(textNode); - EXPECT_EQ(textContext->GetBackgroundColorValue(), toastBackgroundColor); + ToastView::UpdateToastContext(toastNode); + auto toastContext = toastNode->GetRenderContext(); + ASSERT_NE(toastContext, nullptr); + EXPECT_EQ(toastContext->GetBackgroundColorValue(), toastBackgroundColor); MockContainer::Current()->SetApiTargetVersion(backupApiVersion); } @@ -1034,7 +1050,7 @@ HWTEST_F(OverlayTestUpdate, ToastTest017, TestSize.Level1) textProperty->UpdateAdaptMinFontSize(ADAPT_TOAST_MIN_FONT_SIZE); auto toastMaxFontSize = toastTheme->GetTextStyle().GetFontSize(); /** - * @tc.steps: step5. text VERSION_TWELVE version UpdateTextContext . + * @tc.steps: step5. text VERSION_TWELVE version UpdateToastContext . */ Dimension text1 = 0.0_fp; toastPattern1->UpdateTextSizeConstraint(textNode); @@ -1086,7 +1102,7 @@ HWTEST_F(OverlayTestUpdate, ToastTest018, TestSize.Level1) MockContainer::Current()->SetApiTargetVersion(settingApiVersion); auto toastMaxFontSize = toastTheme->GetTextStyle().GetFontSize(); /** - * @tc.steps: step5. text VERSION_TWELVE version UpdateTextContext . + * @tc.steps: step5. text VERSION_TWELVE version UpdateToastContext . */ toastPattern1->UpdateTextSizeConstraint(textNode); textProperty->UpdateAdaptMinFontSize(ADAPT_TOAST_MAX_FONT_SIZE); @@ -1139,7 +1155,7 @@ HWTEST_F(OverlayTestUpdate, ToastTest019, TestSize.Level1) MockContainer::Current()->SetApiTargetVersion(settingApiVersion); auto toastMaxFontSize = toastTheme->GetTextStyle().GetFontSize(); /** - * @tc.steps: step5. text VERSION_TWELVE version UpdateTextContext . + * @tc.steps: step5. text VERSION_TWELVE version UpdateToastContext . */ toastPattern1->UpdateTextSizeConstraint(textNode); textProperty->UpdateAdaptMinFontSize(ADAPT_TOAST_NORMAL_FONT_SIZE); @@ -1191,7 +1207,7 @@ HWTEST_F(OverlayTestUpdate, ToastTest020, TestSize.Level1) MockContainer::Current()->SetApiTargetVersion(settingApiVersion); auto toastMaxFontSize = toastTheme->GetTextStyle().GetFontSize(); /** - * @tc.steps: step5. text VERSION_TWELVE version UpdateTextContext . + * @tc.steps: step5. text VERSION_TWELVE version UpdateToastContext . */ toastPattern1->UpdateTextSizeConstraint(textNode); textProperty->UpdateAdaptMinFontSize(ADAPT_TOAST_ZERO_FONT_SIZE); @@ -1243,7 +1259,7 @@ HWTEST_F(OverlayTestUpdate, ToastTest021, TestSize.Level1) MockContainer::Current()->SetApiTargetVersion(settingApiVersion); auto toastMaxFontSize = toastTheme->GetTextStyle().GetFontSize(); /** - * @tc.steps: step5. text VERSION_TWELVE version UpdateTextContext . + * @tc.steps: step5. text VERSION_TWELVE version UpdateToastContext . */ toastPattern1->UpdateTextSizeConstraint(textNode); textProperty->UpdateAdaptMinFontSize(ADAPT_TOAST_NEG_FONT_SIZE); @@ -1294,7 +1310,7 @@ HWTEST_F(OverlayTestUpdate, ToastTest022, TestSize.Level1) int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();; MockContainer::Current()->SetApiTargetVersion(settingApiVersion); /** - * @tc.steps: step5. text VERSION_TWELVE version UpdateTextContext . + * @tc.steps: step5. text VERSION_TWELVE version UpdateToastContext . */ toastPattern1->UpdateTextSizeConstraint(textNode); textProperty->UpdateAdaptMinFontSize(ADAPT_TOAST_MIN_FONT_SIZE); @@ -1346,7 +1362,7 @@ HWTEST_F(OverlayTestUpdate, ToastTest023, TestSize.Level1) int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();; MockContainer::Current()->SetApiTargetVersion(settingApiVersion); /** - * @tc.steps: step5. text VERSION_TWELVE version UpdateTextContext . + * @tc.steps: step5. text VERSION_TWELVE version UpdateToastContext . */ toastPattern1->UpdateTextSizeConstraint(textNode); textProperty->UpdateAdaptMinFontSize(ADAPT_TOAST_MAX_FONT_SIZE); @@ -1398,7 +1414,7 @@ HWTEST_F(OverlayTestUpdate, ToastTest024, TestSize.Level1) int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();; MockContainer::Current()->SetApiTargetVersion(settingApiVersion); /** - * @tc.steps: step5. text VERSION_TWELVE version UpdateTextContext . + * @tc.steps: step5. text VERSION_TWELVE version UpdateToastContext . */ toastPattern1->UpdateTextSizeConstraint(textNode); textProperty->UpdateAdaptMinFontSize(ADAPT_TOAST_NORMAL_FONT_SIZE); @@ -1450,7 +1466,7 @@ HWTEST_F(OverlayTestUpdate, ToastTest025, TestSize.Level1) int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();; MockContainer::Current()->SetApiTargetVersion(settingApiVersion); /** - * @tc.steps: step5. text VERSION_TWELVE version UpdateTextContext . + * @tc.steps: step5. text VERSION_TWELVE version UpdateToastContext . */ toastPattern1->UpdateTextSizeConstraint(textNode); textProperty->UpdateAdaptMinFontSize(ADAPT_TOAST_ZERO_FONT_SIZE); @@ -1502,7 +1518,7 @@ HWTEST_F(OverlayTestUpdate, ToastTest026, TestSize.Level1) int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();; MockContainer::Current()->SetApiTargetVersion(settingApiVersion); /** - * @tc.steps: step5. text VERSION_TWELVE version UpdateTextContext . + * @tc.steps: step5. text VERSION_TWELVE version UpdateToastContext . */ toastPattern1->UpdateTextSizeConstraint(textNode); textProperty->UpdateAdaptMinFontSize(ADAPT_TOAST_NEG_FONT_SIZE); @@ -1554,7 +1570,7 @@ HWTEST_F(OverlayTestUpdate, ToastTest027, TestSize.Level1) int32_t backupApiVersion = MockContainer::Current()->GetApiTargetVersion();; MockContainer::Current()->SetApiTargetVersion(settingApiVersion); /** - * @tc.steps: step5. text VERSION_TWELVE version UpdateTextContext . + * @tc.steps: step5. text VERSION_TWELVE version UpdateToastContext . */ toastPattern1->UpdateTextSizeConstraint(textNode); textProperty->UpdateAdaptMinFontSize(ADAPT_TOAST_MIN_FONT_SIZE);