修复List组件ScrollTOIndex跳变问题

Signed-off-by: yeyinglong_admin <yeyinglong@hisilicon.com>
This commit is contained in:
yeyinglong_admin 2024-09-25 23:11:22 +08:00
parent e3a3485f69
commit 86f275badd
3 changed files with 41 additions and 3 deletions

View File

@ -1309,6 +1309,7 @@ void ListPattern::OnAnimateStop()
MarkDirtyNodeSelf();
isScrollEnd_ = true;
}
scrollTarget_.reset();
}
void ListPattern::ScrollTo(float position)
@ -1552,9 +1553,10 @@ bool ListPattern::AnimateToTarget(int32_t index, std::optional<int32_t> indexInG
}
GetListItemAnimatePos(iter->second.startPos, iter->second.endPos, align, targetPos);
}
auto extraOffset = GetExtraOffset();
if (extraOffset.has_value()) {
targetPos += extraOffset.value();
float extraOffset = 0.0f;
if (GetExtraOffset().has_value()) {
extraOffset = GetExtraOffset().value();
targetPos += extraOffset;
ResetExtraOffset();
}
if (!NearZero(targetPos)) {
@ -1564,6 +1566,9 @@ bool ListPattern::AnimateToTarget(int32_t index, std::optional<int32_t> indexInG
predictSnapOffset_.reset();
snapTrigOnScrollStart_ = false;
}
if (!indexInGroup.has_value()) {
scrollTarget_ = { index, extraOffset, align, targetPos + currentOffset_ };
}
}
return true;
}
@ -1692,6 +1697,22 @@ float ListPattern::UpdateTotalOffset(const RefPtr<ListLayoutAlgorithm>& listLayo
}
CalculateCurrentOffset(relativeOffset, listLayoutAlgorithm->GetRecycledItemPosition());
}
if (scrollTarget_) {
auto& target = scrollTarget_.value();
auto posInfo = posMap_->GetPositionInfo(target.index);
if (!Negative(posInfo.mainPos)) {
float startPos = posInfo.mainPos - currentOffset_;
float targetPos = 0.0f;
GetListItemAnimatePos(startPos, startPos + posInfo.mainSize, target.align, targetPos);
targetPos += currentOffset_ + target.extraOffset;
const float epsilon = 0.1f;
if (!NearEqual(relativeOffset + prevOffset, currentOffset_, epsilon) ||
!NearEqual(target.targetOffset, targetPos, epsilon)) {
target.targetOffset = targetPos;
AnimateTo(targetPos, -1, nullptr, true);
}
}
}
return currentOffset_ - prevOffset;
}

View File

@ -43,6 +43,13 @@ struct ListItemGroupPara {
int32_t displayEndIndex = -1;
};
struct ListScrollTarget {
int32_t index = -1;
float extraOffset = 0.0f;
ScrollAlign align = ScrollAlign::START;
float targetOffset;
};
class ListPattern : public ScrollablePattern {
DECLARE_ACE_TYPE(ListPattern, ScrollablePattern);
@ -413,6 +420,7 @@ private:
std::optional<int32_t> jumpIndexInGroup_;
std::optional<int32_t> targetIndex_;
std::optional<int32_t> targetIndexInGroup_;
std::optional<ListScrollTarget> scrollTarget_;
std::optional<float> predictSnapOffset_;
std::optional<float> predictSnapEndPos_;
ScrollAlign scrollAlign_ = ScrollAlign::START;

View File

@ -407,6 +407,15 @@ public:
return posMap_[startIndex].mainPos - startPos;
}
PositionInfo GetPositionInfo(int32_t index) const
{
auto it = posMap_.find(index);
if (it == posMap_.end()) {
return { -1.0f, -1.0f };
}
return it->second;
}
std::pair<int32_t, float> GetStartIndexAndPos() const
{
if (posMap_.empty()) {