From 0b375dbc930779ba5547adefcc43ca32fcb71503 Mon Sep 17 00:00:00 2001 From: Hu_ZeQi Date: Fri, 8 Aug 2025 21:31:45 +0800 Subject: [PATCH] =?UTF-8?q?Swiper:=20SwipeToWithoutAnimation=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu_ZeQi Change-Id: Iee0b9261d16f15dc30ecb637f651f241cece8e05 --- .../components_ng/pattern/swiper/swiper_pattern.cpp | 12 +++++++----- .../components_ng/pattern/swiper/swiper_pattern.h | 2 +- .../core/pattern/swiper/swiper_pattern_test_ng.cpp | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp index 35734911e55..487748c3295 100644 --- a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp +++ b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp @@ -1917,7 +1917,7 @@ void SwiperPattern::OnSwiperCustomAnimationFinish( taskExecutor->PostDelayedTask(task, TaskExecutor::TaskType::UI, timeout, "ArkUISwiperDelayedCustomAnimation"); } -void SwiperPattern::SwipeToWithoutAnimation(int32_t index, bool byUser) +void SwiperPattern::SwipeToWithoutAnimation(int32_t index, std::optional rawIndex) { if (currentIndex_ != index) { FireWillShowEvent(index); @@ -1936,8 +1936,10 @@ void SwiperPattern::SwipeToWithoutAnimation(int32_t index, bool byUser) StopSpringAnimationImmediately(); StopIndicatorAnimation(true); jumpIndex_ = index; - if (byUser) { - jumpIndexByUser_ = index; + if (rawIndex.has_value()) { + auto tempIndex = CheckIndexRange(rawIndex.value()); + tempIndex = IsSwipeByGroup() ? SwiperUtils::ComputePageIndex(tempIndex, GetDisplayCount()) : tempIndex; + jumpIndexByUser_ = CheckTargetIndex(tempIndex); } AceAsyncTraceBeginCommercial(0, hasTabsAncestor_ ? APP_TABS_NO_ANIMATION_SWITCH : APP_SWIPER_NO_ANIMATION_SWITCH); uiCastJumpIndex_ = index; @@ -2241,7 +2243,7 @@ void SwiperPattern::ChangeIndex(int32_t index, SwiperAnimationMode mode) SetIndicatorChangeIndexStatus(false); } - SwipeToWithoutAnimation(CheckIndexRange(CheckTargetIndex(index)), true); + SwipeToWithoutAnimation(GetLoopIndex(targetIndex), index); } else if (mode == SwiperAnimationMode::DEFAULT_ANIMATION) { if (GetMaxDisplayCount() > 0) { SetIndicatorChangeIndexStatus(true); @@ -2306,7 +2308,7 @@ void SwiperPattern::ChangeIndex(int32_t index, bool useAnimation) SetIndicatorChangeIndexStatus(false); } - SwipeToWithoutAnimation(CheckIndexRange(CheckTargetIndex(index)), true); + SwipeToWithoutAnimation(GetLoopIndex(targetIndex), index); } } diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.h b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.h index 37edf00ceb4..5ecdb91c85d 100644 --- a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.h +++ b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.h @@ -532,7 +532,7 @@ public: std::string ProvideRestoreInfo() override; void OnRestoreInfo(const std::string& restoreInfo) override; bool IsAutoFill() const; - void SwipeToWithoutAnimation(int32_t index, bool byUser = false); + void SwipeToWithoutAnimation(int32_t index, std::optional rawIndex = std::nullopt); void StopAutoPlay(); void StartAutoPlay(); void StopTranslateAnimation(); diff --git a/test/unittest/core/pattern/swiper/swiper_pattern_test_ng.cpp b/test/unittest/core/pattern/swiper/swiper_pattern_test_ng.cpp index 0990850c14e..fc18ffc0354 100644 --- a/test/unittest/core/pattern/swiper/swiper_pattern_test_ng.cpp +++ b/test/unittest/core/pattern/swiper/swiper_pattern_test_ng.cpp @@ -1745,7 +1745,7 @@ HWTEST_F(SwiperPatternTestNg, SwipeToWithoutAnimation001, TestSize.Level1) by the user using the changindex interface. * @tc.expected: jumpIndexByUser_ is not changed. */ - pattern_->SwipeToWithoutAnimation(1, false); + pattern_->SwipeToWithoutAnimation(1); EXPECT_EQ(pattern_->jumpIndexByUser_, std::nullopt); /** @@ -1753,7 +1753,7 @@ HWTEST_F(SwiperPatternTestNg, SwipeToWithoutAnimation001, TestSize.Level1) by the user using the changindex interface. * @tc.expected: jumpIndexByUser_ is changed. */ - pattern_->SwipeToWithoutAnimation(1, true); + pattern_->SwipeToWithoutAnimation(1, 1); EXPECT_EQ(pattern_->jumpIndexByUser_, 1); /** -- Gitee