diff --git a/frameworks/core/components_ng/pattern/progress/progress_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/progress/progress_layout_algorithm.cpp index 6dfc4124d647ef4220e2e192552d7017d8e62165..d876e06619163e40846e5fb4b18e6ee8df11df6a 100644 --- a/frameworks/core/components_ng/pattern/progress/progress_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/progress/progress_layout_algorithm.cpp @@ -80,17 +80,17 @@ std::optional ProgressLayoutAlgorithm::MeasureContent( progressTheme ? progressTheme->GetRingDiameter().ConvertToPx() : DEFALT_RING_DIAMETER.ConvertToPx(); auto selfIdealWidth = contentConstraint.selfIdealSize.Width(); auto selfIdealHeight = contentConstraint.selfIdealSize.Height(); + if (layoutPolicy.has_value()) { + if (layoutPolicy->IsWidthMatch()) { + selfIdealWidth = contentConstraint.parentIdealSize.Width(); + } + if (layoutPolicy->IsHeightMatch()) { + selfIdealHeight = contentConstraint.parentIdealSize.Height(); + } + } float width_ = selfIdealWidth.value_or(contentConstraint.percentReference.Width()); float height_ = selfIdealHeight.value_or(strokeWidth_); if (type_ == ProgressType::RING || type_ == ProgressType::SCALE || type_ == ProgressType::MOON) { - if (layoutPolicy.has_value()) { - if (layoutPolicy->IsWidthMatch()) { - selfIdealWidth = contentConstraint.parentIdealSize.Width(); - } - if (layoutPolicy->IsHeightMatch()) { - selfIdealHeight = contentConstraint.parentIdealSize.Height(); - } - } if (!selfIdealHeight) { if (!selfIdealWidth) { width_ = diameter; diff --git a/test/unittest/core/pattern/progress/progress_builder_test_ng.cpp b/test/unittest/core/pattern/progress/progress_builder_test_ng.cpp index 814f6a6de7e140bcfde37d5a6bbd822fa0c16a68..7d0a6f4687c8fc5a9664086842b5c258a550e498 100644 --- a/test/unittest/core/pattern/progress/progress_builder_test_ng.cpp +++ b/test/unittest/core/pattern/progress/progress_builder_test_ng.cpp @@ -59,9 +59,12 @@ constexpr double NEG_VALUE_OF_PROGRESS = -100.0; constexpr double MAX_VALUE_OF_PROGRESS = 100000.0; constexpr double MAX_VALUE_OF_PROGRESS2 = 10000.0; constexpr double MAX_NEG_VALUE_OF_PROGRESS = -100000.0; +constexpr float PROGRESS_COMPONENT_MAXSIZE_WIDTH = 720.0f; +constexpr float PROGRESS_COMPONENT_MAXSIZE_HEIGHT = 1400.0f; constexpr ProgressType PROGRESS_TYPE_LINEAR = ProgressType::LINEAR; constexpr ProgressType PROGRESS_TYPE_SCALE = ProgressType::SCALE; constexpr ProgressType PROGRESS_TYPE_MOON = ProgressType::MOON; +constexpr ProgressType PROGRESS_TYPE_RING = ProgressType::RING; constexpr int32_t SCALE_COUNT = 120; constexpr Color FRONT_COLOR = Color(0xff0000ff); constexpr Color BG_COLOR = Color(0xffc0c0c0); @@ -1224,6 +1227,53 @@ HWTEST_F(ProgressBuilderTestNg, ProgressSafeAreaSetTest001, TestSize.Level1) EXPECT_TRUE(progressPattern->IsEnableFix()); } +/** + * @tc.name: ProgressSafeAreaSetTest002 + * @tc.desc: Test LayoutPolicy of Progress. + * @tc.type: FUNC + */ +HWTEST_F(ProgressBuilderTestNg, ProgressSafeAreaSetTest002, TestSize.Level1) +{ + /** + * @tc.steps: step1. create progress. + * @tc.expected: step1. create progress. + */ + CreateProgress(VALUE_OF_PROGRESS, MAX_VALUE_OF_PROGRESS2, PROGRESS_TYPE_RING); + CreateDone(); + + /** + * @tc.steps: step2. set layoutPolicyProperty match_parent. + * @tc.expected: step2. set layoutPolicyProperty match_parent. + */ + auto layoutProperty = frameNode_->GetLayoutProperty(); + ASSERT_NE(layoutProperty, nullptr); + LayoutPolicyProperty layoutPolicyProperty; + layoutPolicyProperty.widthLayoutPolicy_ = LayoutCalPolicy::MATCH_PARENT; + layoutPolicyProperty.heightLayoutPolicy_ = LayoutCalPolicy::MATCH_PARENT; + layoutProperty->layoutPolicy_ = layoutPolicyProperty; + + LayoutConstraintF contentConstraint; + contentConstraint.percentReference.SetWidth(PROGRESS_COMPONENT_MAXSIZE_WIDTH); + contentConstraint.percentReference.SetHeight(PROGRESS_COMPONENT_MAXSIZE_HEIGHT); + LayoutWrapperNode layoutWrapper(frameNode_, nullptr, layoutProperty_); + auto progressLayoutAlgorithm = AceType::MakeRefPtr(); + + /** + * @tc.steps: step3. Call the function MeasureContent. + * @tc.expected: step3. Check the result of MeasureContent. + */ + auto textNode = AceType::DynamicCast(frameNode_->GetChildAtIndex(0)); + RefPtr geometryNode = AceType::MakeRefPtr(); + geometryNode->SetContentSize(SizeF(100, 50)); + RefPtr textWrapper = + AceType::MakeRefPtr(textNode, geometryNode, textNode->GetLayoutProperty()); + layoutWrapper.AppendChild(textWrapper); + contentConstraint.selfIdealSize.SetWidth(PROGRESS_COMPONENT_WIDTH); + contentConstraint.parentIdealSize.SetWidth(PROGRESS_COMPONENT_WIDTH); + auto size = progressLayoutAlgorithm->MeasureContent(contentConstraint, &layoutWrapper); + EXPECT_EQ(size->Width(), PROGRESS_COMPONENT_WIDTH); +} + /** * @tc.name: ProgressSafeAreaTest001 * @tc.desc: Test LayoutPolicy of ProgressSafeAreaTest001.