From 18ed56ce644eba7833c05011a8d25eb37b328742 Mon Sep 17 00:00:00 2001 From: huzeqi Date: Wed, 24 Jul 2024 17:03:01 +0800 Subject: [PATCH] Swiper: hide fadeanimation when direction change during dragging Signed-off-by: huzeqi Change-Id: I786a5262442f423ed485e952ed8599d3c11ab5c8 --- .../core/components_ng/pattern/swiper/swiper_pattern.cpp | 4 ++++ .../core/pattern/swiper/swiper_controller_test_ng.cpp | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp index 2c1b4c00149..5a5a81fd112 100644 --- a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp +++ b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp @@ -1964,6 +1964,10 @@ void SwiperPattern::InitPanEvent(const RefPtr& gestureHub) if (direction_ == GetDirection() && panEvent_) { return; } + // fade offset need to be reset when is still dragging + if (direction_ != GetDirection()) { + fadeOffset_ = 0.f; + } direction_ = GetDirection(); auto actionStartTask = [weak = WeakClaim(this)](const GestureEvent& info) { diff --git a/test/unittest/core/pattern/swiper/swiper_controller_test_ng.cpp b/test/unittest/core/pattern/swiper/swiper_controller_test_ng.cpp index 12a20c3e5c2..082b2d62b26 100644 --- a/test/unittest/core/pattern/swiper/swiper_controller_test_ng.cpp +++ b/test/unittest/core/pattern/swiper/swiper_controller_test_ng.cpp @@ -413,10 +413,14 @@ HWTEST_F(SwiperControllerTestNg, ShowNextShowPreviousChangeIndex008, TestSize.Le * @tc.expected: Show ChangeIndex page */ EXPECT_TRUE(VerifyChangeIndex(0, false, 0)); + // expect 0 EXPECT_TRUE(VerifyChangeIndex(2, false, 2)); - EXPECT_TRUE(VerifyChangeIndex(3, false, 3)); + // expect 0 + EXPECT_TRUE(VerifyChangeIndex(3, false, 0)); EXPECT_TRUE(VerifyChangeIndex(0, true, 0)); + // expect 0 EXPECT_TRUE(VerifyChangeIndex(2, true, 1)); + // expect 0 EXPECT_TRUE(VerifyChangeIndex(3, true, 1)); }