From a2b7829fa378b84d9414e3879b2bc21971b5952e Mon Sep 17 00:00:00 2001 From: fuhanfeng Date: Sat, 9 Aug 2025 18:24:21 +0800 Subject: [PATCH] =?UTF-8?q?fix=20WaterFlow=20Segment=20+=20Lazyfoeach=20?= =?UTF-8?q?=E6=9C=89=E4=B8=80=E5=AE=9A=E6=A6=82=E7=8E=87=E5=9B=A0=E4=B8=BA?= =?UTF-8?q?=E6=97=B6=E5=BA=8F=E7=AB=9E=E4=BA=89=E5=AF=BC=E8=87=B4=E5=90=91?= =?UTF-8?q?=E7=88=B6=E7=BA=A7=E7=BB=84=E4=BB=B6=E6=A0=87=E8=84=8F=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fuhanfeng --- .../top_down/water_flow_segmented_layout.cpp | 1 + .../water_flow_segment_layout_test.cpp | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/frameworks/core/components_ng/pattern/waterflow/layout/top_down/water_flow_segmented_layout.cpp b/frameworks/core/components_ng/pattern/waterflow/layout/top_down/water_flow_segmented_layout.cpp index b9ea609305b..92eeb005717 100644 --- a/frameworks/core/components_ng/pattern/waterflow/layout/top_down/water_flow_segmented_layout.cpp +++ b/frameworks/core/components_ng/pattern/waterflow/layout/top_down/water_flow_segmented_layout.cpp @@ -59,6 +59,7 @@ void WaterFlowSegmentedLayout::Measure(LayoutWrapper* wrapper) sections_ = pattern->GetSections(); if (sections_ && !IsSectionValid(info_, info_->childrenCount_)) { info_->isDataValid_ = false; + WaterFlowLayoutUtils::PreMeasureSelf(wrapper_, axis_); return; } diff --git a/test/unittest/core/pattern/waterflow/water_flow_segment_layout_test.cpp b/test/unittest/core/pattern/waterflow/water_flow_segment_layout_test.cpp index 1a6632ff69d..cba977dad41 100644 --- a/test/unittest/core/pattern/waterflow/water_flow_segment_layout_test.cpp +++ b/test/unittest/core/pattern/waterflow/water_flow_segment_layout_test.cpp @@ -2128,4 +2128,46 @@ HWTEST_F(WaterFlowSegmentTest, WaterFlowRTLPaddingWithSections003, TestSize.Leve EXPECT_LE(multiColumnItem.Right(), WATER_FLOW_WIDTH - 30.0f + 1.0f); EXPECT_GE(multiColumnItem.Left(), 10.0f - 1.0f); } + +/** + * @tc.name: InvalidSectionWithDefaultSize + * @tc.desc: Verify WaterFlow maintains default size when both children count and segment tails are invalid + * @tc.type: FUNC + */ +HWTEST_F(WaterFlowSegmentTest, InvalidSectionWithDefaultSize, TestSize.Level1) +{ + // Initialize WaterFlow with default size + CreateWaterFlow(); + ViewAbstract::SetWidth(CalcLength(400.0f)); + ViewAbstract::SetHeight(CalcLength(800.0f)); + + CreateWaterFlowItems(5); + auto secObj = pattern_->GetOrCreateWaterFlowSections(); + secObj->ChangeData(0, 0, SECTION_13); + CreateDone(); + + // Verify initial indices + auto info = AceType::DynamicCast(pattern_->layoutInfo_); + EXPECT_EQ(info->startIndex_, 0); + EXPECT_EQ(info->endIndex_, 4); + + // Create mismatch by removing children + for (int i = 3; i <= 4; ++i) { + frameNode_->RemoveChildAtIndex(3); + } + frameNode_->ChildrenUpdatedFrom(3); + + // Ensure mismatch by modifying segment tails + if (!info->segmentTails_.empty()) { + info->segmentTails_.back() = 10; + } + + frameNode_->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); + FlushUITasks(); + + // WaterFlow should maintain default size + auto geometryNode = frameNode_->GetGeometryNode(); + EXPECT_EQ(geometryNode->GetFrameSize().Width(), 400.0f); + EXPECT_EQ(geometryNode->GetFrameSize().Height(), 800.0f); +} } // namespace OHOS::Ace::NG \ No newline at end of file -- Gitee