diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp index 310f787e874..692ed82e16a 100644 --- a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp +++ b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp @@ -181,7 +181,7 @@ RefPtr SwiperPattern::CreateLayoutAlgorithm() void SwiperPattern::OnIndexChange() { - auto totalCount = RealTotalCount(); + auto totalCount = TotalCount(); if (NonPositive(totalCount)) { return; } @@ -472,11 +472,14 @@ void SwiperPattern::BeforeCreateLayoutWrapper() auto userSetCurrentIndex = CurrentIndex(); userSetCurrentIndex = CheckUserSetIndex(userSetCurrentIndex); auto oldIndex = GetLoopIndex(oldIndex_); - if (oldChildrenSize_.has_value() && oldChildrenSize_.value() != RealTotalCount()) { + if (oldChildrenSize_.has_value() && oldChildrenSize_.value() != TotalCount()) { oldIndex = GetLoopIndex(oldIndex_, oldChildrenSize_.value()); UpdateIndicatorOnChildChange(); StartAutoPlay(); InitArrow(); + if (IsLoop() && oldIndex != GetLoopIndex(currentIndex_)) { + currentIndex_ = oldIndex >= TotalCount() ? 0 : oldIndex; + } } auto index = CheckIndexRange(userSetCurrentIndex); if (index != userSetCurrentIndex) { @@ -1055,7 +1058,7 @@ bool SwiperPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, contentMainSize_ = algo->GetContentMainSize(); crossMatchChild_ = algo->IsCrossMatchChild(); oldIndex_ = currentIndex_; - oldChildrenSize_ = RealTotalCount(); + oldChildrenSize_ = TotalCount(); needFireCustomAnimationEvent_ = true; if (windowSizeChangeReason_ == WindowSizeChangeReason::ROTATION) {