!48684 优化缓存节点Layout、补充用例

Merge pull request !48684 from 周沺耳/wa
This commit is contained in:
openharmony_ci 2024-11-20 03:24:10 +00:00 committed by Gitee
commit 9b68b989f8
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 46 additions and 8 deletions

View File

@ -145,6 +145,9 @@ public:
virtual RefPtr<LayoutWrapper> GetOrCreateChildByIndex(
uint32_t index, bool addToRenderTree = true, bool isCache = false) = 0;
/**
* @param isCache if false, child is added to render tree and AttachToMainTree is called.
*/
virtual RefPtr<LayoutWrapper> GetChildByIndex(uint32_t index, bool isCache = false) = 0;
virtual ChildrenListWithGuard GetAllChildrenWithBuild(bool addToRenderTree = true) = 0;
virtual void RemoveChildInRenderTree(uint32_t index) = 0;

View File

@ -671,6 +671,10 @@ float WaterFlowLayoutSW::MeasureChild(int32_t idx, size_t lane) const
}
child->Measure(WaterFlowLayoutUtils::CreateChildConstraint(
{ itemsCrossSize_[info_->GetSegment(idx)][lane], mainLen_, axis_ }, props_, child));
if (cacheDeadline_) {
child->Layout();
child->SetActive(false);
}
const float res = child->GetGeometryNode()->GetMarginFrameSize().MainSize(info_->axis_);
info_->CacheItemHeight(idx, res);
return res;
@ -699,7 +703,8 @@ void WaterFlowLayoutSW::LayoutSection(
const auto& lane = info_->lanes_[idx][i];
float mainPos = lane.startPos;
for (const auto& item : lane.items_) {
const bool isCache = item.idx < info_->startIndex_ || item.idx > info_->endIndex_;
const bool isCache = !props_->GetShowCachedItemsValue(false) &&
(item.idx < info_->startIndex_ || item.idx > info_->endIndex_);
auto child = wrapper_->GetChildByIndex(nodeIdx(item.idx), isCache);
if (!child) {
mainPos += item.mainSize + mainGaps_[idx];
@ -712,12 +717,15 @@ void WaterFlowLayoutSW::LayoutSection(
}
childNode->SetMarginFrameOffset(offset + paddingOffset);
mainPos += item.mainSize + mainGaps_[idx];
if (isCache) {
continue;
}
if (child->CheckNeedForceMeasureAndLayout()) {
child->Layout();
} else {
child->GetHostNode()->ForceSyncGeometryNode();
}
mainPos += item.mainSize + mainGaps_[idx];
}
if (!rtl) {
crossPos += itemsCrossSize_[idx][i] + crossGaps_[idx];

View File

@ -243,19 +243,28 @@ void WaterFlowLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper)
} else {
currentOffset += OffsetF(mainOffset, crossOffset);
}
const bool isCache = item.first < layoutInfo_->startIndex_ || item.first > layoutInfo_->endIndex_;
auto wrapper = layoutWrapper->GetChildByIndex(GetChildIndexWithFooter(item.first), isCache && !showCache);
const bool isCache =
!showCache && (item.first < layoutInfo_->startIndex_ || item.first > layoutInfo_->endIndex_);
auto wrapper = layoutWrapper->GetChildByIndex(GetChildIndexWithFooter(item.first), isCache);
if (!wrapper) {
continue;
}
wrapper->GetGeometryNode()->SetMarginFrameOffset(currentOffset);
wrapper->Layout();
if (isCache) {
continue;
}
if (wrapper->CheckNeedForceMeasureAndLayout()) {
wrapper->Layout();
} else {
wrapper->GetHostNode()->ForceSyncGeometryNode();
}
// recode restore info
if (item.first == layoutInfo_->startIndex_) {
layoutInfo_->storedOffset_ = mainOffset;
}
if (!isCache && NonNegative(mainOffset + item.second.second)) {
if (NonNegative(mainOffset + item.second.second)) {
firstIndex = std::min(firstIndex, item.first);
}
auto frameNode = AceType::DynamicCast<FrameNode>(wrapper);

View File

@ -434,6 +434,7 @@ HWTEST_F(WaterFlowTestNg, CacheScroll001, TestSize.Level1)
model.SetColumnsGap(Dimension(10));
CreateItemsInLazyForEach(100, [](int32_t) { return 100.0f; });
CreateDone();
frameNode_->AttachToMainTree(true, PipelineContext::GetCurrentContextPtrSafely());
UpdateCurrentOffset(-2000.0f);
EXPECT_EQ(pattern_->layoutInfo_->startIndex_, 18);
@ -448,9 +449,17 @@ HWTEST_F(WaterFlowTestNg, CacheScroll001, TestSize.Level1)
EXPECT_EQ(pattern_->layoutInfo_->endIndex_, 23);
EXPECT_FALSE(GetChildFrameNode(frameNode_, 7));
EXPECT_EQ(GetChildY(frameNode_, 18), 180.0f);
EXPECT_TRUE(GetItem(18)->IsOnMainTree());
PipelineContext::GetCurrentContext()->OnIdle(INT64_MAX);
EXPECT_TRUE(GetChildFrameNode(frameNode_, 7));
ASSERT_TRUE(GetItem(7, true));
EXPECT_FALSE(GetItem(7, true)->IsOnMainTree());
EXPECT_EQ(GetItem(7, true)->GetLayoutProperty()->GetPropertyChangeFlag() & PROPERTY_UPDATE_MEASURE,
PROPERTY_UPDATE_MEASURE);
UpdateCurrentOffset(5.0f);
EXPECT_FALSE(GetItem(7, true)->IsOnMainTree());
EXPECT_EQ(GetChildLayoutProperty<LayoutProperty>(frameNode_, 7)->GetPropertyChangeFlag() & PROPERTY_UPDATE_MEASURE,
PROPERTY_UPDATE_MEASURE);
}
/**
@ -491,9 +500,11 @@ HWTEST_F(WaterFlowTestNg, ShowCachedItems001, TestSize.Level1)
CreateDone();
EXPECT_EQ(pattern_->layoutInfo_->endIndex_, 10);
ASSERT_TRUE(GetChildFrameNode(frameNode_, 12));
EXPECT_FALSE(GetChildFrameNode(frameNode_, 0)->IsActive());
EXPECT_FALSE(GetChildFrameNode(frameNode_, 0)->IsActive()); // footer
EXPECT_TRUE(GetChildFrameNode(frameNode_, 12)->IsActive());
EXPECT_EQ(GetChildY(frameNode_, 12), 800.0f);
// check if ::Layout is called
EXPECT_EQ(GetChildLayoutProperty<LayoutProperty>(frameNode_, 12)->GetPropertyChangeFlag(), 0);
}
/**

View File

@ -1950,6 +1950,7 @@ HWTEST_F(WaterFlowTestNg, ShowCache003, TestSize.Level1)
UpdateCurrentOffset(-50.0f);
EXPECT_EQ(GetChildY(frameNode_, 0), -560.0f);
EXPECT_EQ(GetChildY(frameNode_, 10), 1040.0f);
EXPECT_EQ(GetChildLayoutProperty<LayoutProperty>(frameNode_, 0)->GetPropertyChangeFlag(), 0);
}
/**

View File

@ -314,6 +314,11 @@ RectF WaterFlowTestNg::GetLazyChildRect(int32_t itemIndex)
return waterFlowItem->GetGeometryNode()->GetFrameRect();
}
RefPtr<FrameNode> WaterFlowTestNg::GetItem(int32_t index, bool isCache)
{
return AceType::DynamicCast<FrameNode>(frameNode_->GetChildByIndex(index, isCache));
}
/**
* @tc.name: LazyForeachLayout001
* @tc.desc: Test LazyForeach Layout

View File

@ -62,6 +62,7 @@ protected:
AssertionResult IsEqualTotalOffset(float expectOffset);
void HandleDrag(float offset);
RectF GetLazyChildRect(int32_t itemIndex);
RefPtr<FrameNode> GetItem(int32_t index, bool isCache = false);
RefPtr<FrameNode> frameNode_;
RefPtr<WaterFlowPattern> pattern_;