From 20f8212e119eca238a78dc41b37fa1deb3047c0b Mon Sep 17 00:00:00 2001 From: huiqiang Date: Thu, 14 Aug 2025 19:54:28 +0800 Subject: [PATCH] restore grid mainlength Signed-off-by: huiqiang Change-Id: Iebe96dbf2ed0fba5ec62d7096768ae0ef218858b --- .../grid_scroll_layout_algorithm.cpp | 15 +---- .../grid_scroll_layout_algorithm.h | 4 +- .../grid/grid_scroll_layout_test_ng.cpp | 59 ------------------- 3 files changed, 3 insertions(+), 75 deletions(-) diff --git a/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp index 6fbc12836ae..5e0ec3b602a 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp @@ -1161,8 +1161,7 @@ inline void UpdateStartIndexByStartLine(GridLayoutInfo& info_) } } // namespace -bool GridScrollLayoutAlgorithm::MeasureExistingLine( - int32_t line, float& mainLength, int32_t& endIdx, bool isScrollableSpringMotionRunning) +bool GridScrollLayoutAlgorithm::MeasureExistingLine(int32_t line, float& mainLength, int32_t& endIdx) { auto it = info_.gridMatrix_.find(line); if (it == info_.gridMatrix_.end() || info_.lineHeightMap_.find(line) == info_.lineHeightMap_.end()) { @@ -1198,11 +1197,6 @@ bool GridScrollLayoutAlgorithm::MeasureExistingLine( } if (NonNegative(cellAveLength_)) { // Means at least one item has been measured - auto deltaHeight = info_.lineHeightMap_[line] - cellAveLength_; - if (Positive(deltaHeight) && isScrollableSpringMotionRunning) { - mainLength += deltaHeight; - info_.currentOffset_ = mainLength; - } info_.lineHeightMap_[line] = cellAveLength_; mainLength += cellAveLength_ + mainGap_; } @@ -1222,13 +1216,8 @@ bool GridScrollLayoutAlgorithm::UseCurrentLines( bool runOutOfRecord = false; // Measure grid items row by row int32_t tempEndIndex = -1; - auto host = layoutWrapper->GetHostNode(); - CHECK_NULL_RETURN(host, runOutOfRecord); - auto pattern = host->GetPattern(); - CHECK_NULL_RETURN(pattern, runOutOfRecord); - auto isScrollableSpringMotionRunning = pattern->IsScrollableSpringMotionRunning(); while (LessNotEqual(mainLength, mainSize)) { - if (!MeasureExistingLine(++currentMainLineIndex_, mainLength, tempEndIndex, isScrollableSpringMotionRunning)) { + if (!MeasureExistingLine(++currentMainLineIndex_, mainLength, tempEndIndex)) { runOutOfRecord = true; break; } diff --git a/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.h b/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.h index ef71965ee2e..799af9fe57c 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.h @@ -253,11 +253,9 @@ private: * @param line index of line to measure * updates @param mainLength by adding this line's measured height * updates @param endIdx with max item index in this line - * updates @param isScrollableSpringMotionRunning spring effect is runnning * @return false if line isn't recorded. */ - bool MeasureExistingLine( - int32_t line, float& mainLength, int32_t& endIdx, bool isScrollableSpringMotionRunning = false); + bool MeasureExistingLine(int32_t line, float& mainLength, int32_t& endIdx); LayoutWrapper* wrapper_; SizeF frameSize_; diff --git a/test/unittest/core/pattern/grid/grid_scroll_layout_test_ng.cpp b/test/unittest/core/pattern/grid/grid_scroll_layout_test_ng.cpp index a0e895767cd..f208d6c8e14 100644 --- a/test/unittest/core/pattern/grid/grid_scroll_layout_test_ng.cpp +++ b/test/unittest/core/pattern/grid/grid_scroll_layout_test_ng.cpp @@ -1822,65 +1822,6 @@ HWTEST_F(GridScrollLayoutTestNg, SpringAnimationTest008, TestSize.Level1) EXPECT_FLOAT_EQ(pattern_->info_.currentOffset_, 0); } -/** - * @tc.name: SpringAnimationTest011 - * @tc.desc: Test GridItem change height during spring animation. - * @tc.type: FUNC - */ -HWTEST_F(GridScrollLayoutTestNg, SpringAnimationTest011, TestSize.Level1) -{ - MockAnimationManager::GetInstance().Reset(); - MockAnimationManager::GetInstance().SetTicks(2); - GridModelNG model = CreateGrid(); - model.SetColumnsTemplate("1fr"); - GridLayoutOptions option; - option.irregularIndexes = { 0, 3 }; - model.SetLayoutOptions(option); - model.SetEdgeEffect(EdgeEffect::SPRING, true); - CreateFixedHeightItems(1, 100); - CreateFixedHeightItems(1, 50); - CreateFixedHeightItems(1, 80); - CreateFixedHeightItems(1, 800); - CreateFixedHeightItems(1, 30); - CreateDone(); - - ScrollToEdge(ScrollEdgeType::SCROLL_BOTTOM, false); - EXPECT_TRUE(pattern_->IsAtBottom()); - /** - * @tc.steps: step1. Simulate a scrolling gesture. - * @tc.expected: Grid trigger spring animation. - */ - GestureEvent info; - info.SetMainVelocity(-200.f); - info.SetMainDelta(-200.f); - auto scrollable = pattern_->GetScrollableEvent()->GetScrollable(); - scrollable->HandleTouchDown(); - scrollable->HandleDragStart(info); - scrollable->HandleDragUpdate(info); - FlushUITasks(); - - EXPECT_TRUE(pattern_->OutBoundaryCallback()); - scrollable->HandleTouchUp(); - scrollable->HandleDragEnd(info); - FlushUITasks(); - EXPECT_FLOAT_EQ(pattern_->info_.currentOffset_, -646.41699); - - /** - * @tc.steps: step2. play spring animation frame by frame, and decrease gridItem height during animation - * @tc.expected: currentOffset will not change with the gridItem height - */ - MockAnimationManager::GetInstance().Tick(); - GetChildLayoutProperty(frameNode_, 3) - ->UpdateUserDefinedIdealSize(CalcSize(std::nullopt, CalcLength(500))); - FlushUITasks(); - EXPECT_FLOAT_EQ(pattern_->info_.currentOffset_, -238.2085); - - MockAnimationManager::GetInstance().Tick(); - FlushUITasks(); - EXPECT_FLOAT_EQ(pattern_->info_.currentOffset_, -130); - EXPECT_TRUE(MockAnimationManager::GetInstance().AllFinished()); -} - /** * @tc.name: TestOffsetAfterSpring001 * @tc.desc: Test Grid prevOffset_ equals currentOffset_ after spring -- Gitee