!42540 Swiper: current index need to be adjusted when itemcount change

Merge pull request !42540 from Hu_zq/0904_master4
This commit is contained in:
openharmony_ci 2024-09-05 02:43:45 +00:00 committed by Gitee
commit f9cc996583
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -181,7 +181,7 @@ RefPtr<LayoutAlgorithm> 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<LayoutWrapper>& dirty,
contentMainSize_ = algo->GetContentMainSize();
crossMatchChild_ = algo->IsCrossMatchChild();
oldIndex_ = currentIndex_;
oldChildrenSize_ = RealTotalCount();
oldChildrenSize_ = TotalCount();
needFireCustomAnimationEvent_ = true;
if (windowSizeChangeReason_ == WindowSizeChangeReason::ROTATION) {