mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 07:01:24 +00:00
!38675 修复了使用GridLayoutOptions场景下,长距离跳转可能回到底部的bug
Merge pull request !38675 from tomkl123/20240724_grid_skip
This commit is contained in:
commit
276f69430c
@ -401,7 +401,7 @@ float GridLayoutInfo::GetIrregularHeight(float mainGap) const
|
|||||||
|
|
||||||
void GridLayoutInfo::SkipStartIndexByOffset(const GridLayoutOptions& options, float mainGap)
|
void GridLayoutInfo::SkipStartIndexByOffset(const GridLayoutOptions& options, float mainGap)
|
||||||
{
|
{
|
||||||
auto targetContent = currentHeight_ - (currentOffset_ - prevOffset_);
|
float targetContent = currentHeight_ - (currentOffset_ - prevOffset_);
|
||||||
if (LessOrEqual(targetContent, 0.0)) {
|
if (LessOrEqual(targetContent, 0.0)) {
|
||||||
currentOffset_ = 0.0f;
|
currentOffset_ = 0.0f;
|
||||||
startIndex_ = 0;
|
startIndex_ = 0;
|
||||||
@ -422,12 +422,12 @@ void GridLayoutInfo::SkipStartIndexByOffset(const GridLayoutOptions& options, fl
|
|||||||
lastRegularMainSize_ = regularHeight;
|
lastRegularMainSize_ = regularHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto firstIrregularIndex = *(options.irregularIndexes.begin());
|
int32_t firstIrregularIndex = *(options.irregularIndexes.begin());
|
||||||
float totalHeight = AddLinesInBetween(-1, firstIrregularIndex, crossCount_, regularHeight);
|
float totalHeight = AddLinesInBetween(-1, firstIrregularIndex, crossCount_, regularHeight);
|
||||||
auto lastIndex = firstIrregularIndex;
|
int32_t lastIndex = GreatNotEqual(totalHeight, targetContent) ? 0 : firstIrregularIndex;
|
||||||
auto lastHeight = 0.0f;
|
float lastHeight = 0.0f;
|
||||||
|
|
||||||
for (auto idx : options.irregularIndexes) {
|
for (int32_t idx : options.irregularIndexes) {
|
||||||
if (GreatOrEqual(totalHeight, targetContent)) {
|
if (GreatOrEqual(totalHeight, targetContent)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -436,9 +436,9 @@ void GridLayoutInfo::SkipStartIndexByOffset(const GridLayoutOptions& options, fl
|
|||||||
totalHeight += AddLinesInBetween(lastIndex, idx, crossCount_, regularHeight);
|
totalHeight += AddLinesInBetween(lastIndex, idx, crossCount_, regularHeight);
|
||||||
lastIndex = idx;
|
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;
|
currentOffset_ = lastHeight + lines * regularHeight - targetContent;
|
||||||
auto startIdx = lines * crossCount_ + lastIndex;
|
int32_t startIdx = lines * crossCount_ + lastIndex;
|
||||||
startIndex_ = std::min(startIdx, childrenCount_ - 1);
|
startIndex_ = std::min(startIdx, childrenCount_ - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -796,4 +796,28 @@ HWTEST_F(GridOptionLayoutTestNg, OutOfBounds001, TestSize.Level1)
|
|||||||
EXPECT_GT(GetChildRect(frameNode_, 29).Bottom(), GRID_HEIGHT);
|
EXPECT_GT(GetChildRect(frameNode_, 29).Bottom(), GRID_HEIGHT);
|
||||||
EXPECT_FALSE(pattern_->IsOutOfBoundary(true));
|
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
|
} // namespace OHOS::Ace::NG
|
||||||
|
Loading…
Reference in New Issue
Block a user