!38675 修复了使用GridLayoutOptions场景下,长距离跳转可能回到底部的bug

Merge pull request !38675 from tomkl123/20240724_grid_skip
This commit is contained in:
openharmony_ci 2024-07-25 06:30:57 +00:00 committed by Gitee
commit 276f69430c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 31 additions and 7 deletions

View File

@ -401,7 +401,7 @@ float GridLayoutInfo::GetIrregularHeight(float mainGap) const
void GridLayoutInfo::SkipStartIndexByOffset(const GridLayoutOptions& options, float mainGap)
{
auto targetContent = currentHeight_ - (currentOffset_ - prevOffset_);
float targetContent = currentHeight_ - (currentOffset_ - prevOffset_);
if (LessOrEqual(targetContent, 0.0)) {
currentOffset_ = 0.0f;
startIndex_ = 0;
@ -422,12 +422,12 @@ void GridLayoutInfo::SkipStartIndexByOffset(const GridLayoutOptions& options, fl
lastRegularMainSize_ = regularHeight;
}
auto firstIrregularIndex = *(options.irregularIndexes.begin());
int32_t firstIrregularIndex = *(options.irregularIndexes.begin());
float totalHeight = AddLinesInBetween(-1, firstIrregularIndex, crossCount_, regularHeight);
auto lastIndex = firstIrregularIndex;
auto lastHeight = 0.0f;
int32_t lastIndex = GreatNotEqual(totalHeight, targetContent) ? 0 : firstIrregularIndex;
float lastHeight = 0.0f;
for (auto idx : options.irregularIndexes) {
for (int32_t idx : options.irregularIndexes) {
if (GreatOrEqual(totalHeight, targetContent)) {
break;
}
@ -436,9 +436,9 @@ void GridLayoutInfo::SkipStartIndexByOffset(const GridLayoutOptions& options, fl
totalHeight += AddLinesInBetween(lastIndex, idx, crossCount_, regularHeight);
lastIndex = idx;
}
auto lines = static_cast<int32_t>(std::floor((targetContent - lastHeight) / regularHeight));
int32_t lines = static_cast<int32_t>(std::floor((targetContent - lastHeight) / regularHeight));
currentOffset_ = lastHeight + lines * regularHeight - targetContent;
auto startIdx = lines * crossCount_ + lastIndex;
int32_t startIdx = lines * crossCount_ + lastIndex;
startIndex_ = std::min(startIdx, childrenCount_ - 1);
}

View File

@ -796,4 +796,28 @@ HWTEST_F(GridOptionLayoutTestNg, OutOfBounds001, TestSize.Level1)
EXPECT_GT(GetChildRect(frameNode_, 29).Bottom(), GRID_HEIGHT);
EXPECT_FALSE(pattern_->IsOutOfBoundary(true));
}
/**
* @tc.name: ScrollTo001
* @tc.desc: Test ScrollTo Function.
* @tc.type: FUNC
*/
HWTEST_F(GridOptionLayoutTestNg, ScrollTo001, TestSize.Level1)
{
GridLayoutOptions option;
option.irregularIndexes = { 45 };
GridModelNG model = CreateGrid();
model.SetLayoutOptions(option);
model.SetColumnsTemplate("1fr");
CreateFixedItems(50);
CreateDone(frameNode_);
pattern_->ScrollTo(ITEM_HEIGHT * 40);
FlushLayoutTask(frameNode_);
EXPECT_EQ(pattern_->GetGridLayoutInfo().startIndex_, 40);
pattern_->ScrollTo(ITEM_HEIGHT * 20);
FlushLayoutTask(frameNode_);
EXPECT_EQ(pattern_->GetGridLayoutInfo().startIndex_, 20);
}
} // namespace OHOS::Ace::NG