mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 07:01:24 +00:00
commit
9b68b989f8
@ -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;
|
||||
|
@ -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];
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
@ -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_;
|
||||
|
Loading…
Reference in New Issue
Block a user