diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp index 35734911e551c56dbd66258b2c45301b52d9aa06..487748c329542a7d1351abda3bea134665780c67 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 37edf00ceb4a008c9acc608c5baaad4c884ac5e3..5ecdb91c85d830062a650c1495667b7e8d34a84b 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 0990850c14e859874261be1b6c3ca790c61711ea..fc18ffc03549353c9d7c7a22cc018944b3c49652 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); /**