From 3017bc1c1be04e5472e42f8137a999979fefce02 Mon Sep 17 00:00:00 2001 From: lijianing Date: Mon, 30 Jun 2025 22:02:14 +0800 Subject: [PATCH] =?UTF-8?q?list=E5=A4=A7=E8=B7=9D=E7=A6=BB=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E5=87=BD=E6=95=B0=E5=8A=A0=E5=88=A4=E7=A9=BA=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E5=90=8E=E7=BB=AD=E8=A2=AB=E5=A4=8D=E7=94=A8=E6=97=A0?= =?UTF-8?q?=E5=89=8D=E7=BD=AE=E5=88=A4=E7=A9=BA=E5=AF=BC=E8=87=B4=E5=B4=A9?= =?UTF-8?q?=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lijianing Change-Id: Ibf112087e5642fa6df608ca44b56052fc470b289 --- .../pattern/list/list_layout_algorithm.cpp | 2 +- .../core/pattern/list/list_algorithm_test_ng.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/pattern/list/list_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/list/list_layout_algorithm.cpp index db27195dd82..7427ce97ead 100644 --- a/frameworks/core/components_ng/pattern/list/list_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/list/list_layout_algorithm.cpp @@ -728,7 +728,7 @@ std::pair ListLayoutAlgorithm::FindIndexAndDeltaInPosMap(float d // The delta and index in the return value satisfies the following constraints: // 1) delta >= -spaceWidth_; // 2) delta < posMap[index].mainSize. - if (!posMap_) { + if (!posMap_ || itemPosition_.empty()) { return { -1, 0.f }; } // itemPosition_ has been checked nonNull before the func is called. diff --git a/test/unittest/core/pattern/list/list_algorithm_test_ng.cpp b/test/unittest/core/pattern/list/list_algorithm_test_ng.cpp index 7374d3e1b64..8bf6c0afc16 100644 --- a/test/unittest/core/pattern/list/list_algorithm_test_ng.cpp +++ b/test/unittest/core/pattern/list/list_algorithm_test_ng.cpp @@ -1647,6 +1647,22 @@ HWTEST_F(ListAlgorithmTestNg, PredictBuildItem002, TestSize.Level1) EXPECT_TRUE(result); } +/** + * @tc.name: FindIndexAndDeltaInPosMap001 + * @tc.desc: Test ListItemLayoutAlgorithm FindIndexAndDeltaInPosMap + * @tc.type: FUNC + */ +HWTEST_F(ListAlgorithmTestNg, FindIndexAndDeltaInPosMap001, TestSize.Level1) +{ + RefPtr listPattern = AceType::MakeRefPtr(); + ASSERT_NE(listPattern, nullptr); + auto layoutAlgorithm = listPattern->CreateLayoutAlgorithm(); + ASSERT_NE(layoutAlgorithm, nullptr); + auto [index, delta] = layoutAlgorithm->FindIndexAndDeltaInPosMap(0.0f); + ASSERT_EQ(index, -1); + ASSERT_EQ(delta, 0.0f); +} + /** * @tc.name: CheckAndUpdateCurOffset001 * @tc.desc: Test ListItemLayoutAlgorithm CheckAndUpdateCurOffset -- Gitee