!36707 tabBar懒加载

Merge pull request !36707 from yangcan/yc_0626
This commit is contained in:
openharmony_ci 2024-07-01 04:34:08 +00:00 committed by Gitee
commit 85f6db6bff
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 18 additions and 61 deletions

View File

@ -224,7 +224,6 @@ void TabBarLayoutAlgorithm::MeasureScrollableMode(LayoutWrapper* layoutWrapper,
CHECK_NULL_VOID(layoutProperty);
auto layoutStyle = layoutProperty->GetScrollableBarModeOptions().value_or(ScrollableBarModeOptions());
scrollMargin_ = layoutStyle.margin.ConvertToPx();
CheckMarqueeForScrollable(layoutWrapper);
MeasureVisibleItems(layoutWrapper, childLayoutConstraint);
useItemWidth_ = true;
@ -297,21 +296,6 @@ LayoutConstraintF TabBarLayoutAlgorithm::GetChildConstraint(LayoutWrapper* layou
return childLayoutConstraint;
}
void TabBarLayoutAlgorithm::CheckMarqueeForScrollable(LayoutWrapper* layoutWrapper) const
{
for (int32_t index = 0; index < childCount_; ++index) {
auto childWrapper = layoutWrapper->GetOrCreateChildByIndex(index);
CHECK_NULL_VOID(childWrapper);
auto textWrapper = childWrapper->GetOrCreateChildByIndex(1);
CHECK_NULL_VOID(textWrapper);
auto textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(textWrapper->GetLayoutProperty());
CHECK_NULL_VOID(textLayoutProperty);
if (textLayoutProperty->GetTextOverflow().value_or(TextOverflow::NONE) == TextOverflow::MARQUEE) {
textLayoutProperty->UpdateTextOverflow(TextOverflow::NONE);
}
}
}
void TabBarLayoutAlgorithm::MeasureVisibleItems(LayoutWrapper* layoutWrapper, LayoutConstraintF& childLayoutConstraint)
{
visibleItemLength_.clear();
@ -387,6 +371,9 @@ void TabBarLayoutAlgorithm::MeasureWithOffset(LayoutWrapper* layoutWrapper, Layo
auto startPos = scrollMargin_;
auto endIndex = 0;
auto endPos = scrollMargin_;
if (isRTL_ && axis_ == Axis::HORIZONTAL) {
currentDelta_ = -currentDelta_;
}
if (NonNegative(currentDelta_)) {
if (!visibleItemPosition_.empty()) {
endIndex = visibleItemPosition_.begin()->first;
@ -403,13 +390,8 @@ void TabBarLayoutAlgorithm::MeasureWithOffset(LayoutWrapper* layoutWrapper, Layo
endPos = startPos;
}
if (isRTL_ && axis_ == Axis::HORIZONTAL) {
startPos -= currentDelta_;
endPos -= currentDelta_;
} else {
startPos += currentDelta_;
endPos += currentDelta_;
}
startPos += currentDelta_;
endPos += currentDelta_;
visibleItemPosition_.clear();
LayoutForward(layoutWrapper, childLayoutConstraint, endIndex, endPos);
LayoutBackward(layoutWrapper, childLayoutConstraint, startIndex, startPos);
@ -484,6 +466,8 @@ void TabBarLayoutAlgorithm::MeasureItem(LayoutWrapper* layoutWrapper, LayoutCons
CHECK_NULL_VOID(tabBarPattern);
auto childWrapper = layoutWrapper->GetOrCreateChildByIndex(index);
CHECK_NULL_VOID (childWrapper);
auto layoutProperty = AceType::DynamicCast<TabBarLayoutProperty>(layoutWrapper->GetLayoutProperty());
CHECK_NULL_VOID(layoutProperty);
if (tabBarPattern->GetTabBarStyle(index) == TabBarStyle::BOTTOMTABBATSTYLE) {
auto iconWrapper = childWrapper->GetOrCreateChildByIndex(0);
CHECK_NULL_VOID(iconWrapper);
@ -502,6 +486,17 @@ void TabBarLayoutAlgorithm::MeasureItem(LayoutWrapper* layoutWrapper, LayoutCons
CHECK_NULL_VOID(textLayoutProperty);
textLayoutProperty->UpdateMargin({ CalcLength(0.0_vp), CalcLength(0.0_vp), {}, {} });
}
if (layoutProperty->GetTabBarMode().value_or(TabBarMode::FIXED) == TabBarMode::SCROLLABLE &&
axis_ == Axis::HORIZONTAL) {
auto textWrapper = childWrapper->GetOrCreateChildByIndex(1);
if (textWrapper) {
auto textLayoutProperty = AceType::DynamicCast<TextLayoutProperty>(textWrapper->GetLayoutProperty());
if (textLayoutProperty &&
textLayoutProperty->GetTextOverflow().value_or(TextOverflow::NONE) == TextOverflow::MARQUEE) {
textLayoutProperty->UpdateTextOverflow(TextOverflow::NONE);
}
}
}
childWrapper->Measure(childLayoutConstraint);
auto geometryNode = childWrapper->GetGeometryNode();

View File

@ -117,7 +117,6 @@ private:
const std::vector<float>& rightBuffer, float allocatedWidth);
void UpdateHorizontalPadding(LayoutWrapper* layoutWrapper, float horizontalPadding) const;
void MeasureMask(LayoutWrapper* layoutWrapper) const;
void CheckMarqueeForScrollable(LayoutWrapper* layoutWrapper) const;
void UpdateChildMarginProperty(float rightMargin, float leftMargin, const RefPtr<LayoutWrapper>& childWrapper);
bool isRTL_ = false;

View File

@ -971,43 +971,6 @@ HWTEST_F(TabBarLayoutTestNg, TabBarPatternOnDirtyLayoutWrapperSwap002, TestSize.
EXPECT_TRUE(tabBarPattern_->isTouchingSwiper_);
}
/**
* @tc.name: TabBarLayoutAlgorithmCheckMarqueeForScrollable001
* @tc.desc: Test the CheckMarqueeForScrollable function in the TabBarLayoutAlgorithm class.
* @tc.type: FUNC
*/
HWTEST_F(TabBarLayoutTestNg, TabBarLayoutAlgorithmCheckMarqueeForScrollable001, TestSize.Level1)
{
TabsModelNG model = CreateTabs();
CreateTabContents(TABCONTENT_NUMBER);
CreateTabsDone(model);
auto tabbarLayoutAlgorithm =
AceType::DynamicCast<TabBarLayoutAlgorithm>(tabBarPattern_->CreateLayoutAlgorithm());
RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
LayoutWrapperNode layoutWrapper = LayoutWrapperNode(tabBarNode_, geometryNode, tabBarNode_->GetLayoutProperty());
layoutWrapper.SetLayoutAlgorithm(AceType::MakeRefPtr<LayoutAlgorithmWrapper>(tabbarLayoutAlgorithm));
auto layoutProperty = AceType::DynamicCast<TabBarLayoutProperty>(layoutWrapper.GetLayoutProperty());
/**
* @tc.steps: steps2. Create different input parameters.
*/
layoutProperty->UpdateTabBarMode(TabBarMode::FIXED);
tabbarLayoutAlgorithm->childCount_ = 0;
BarGridColumnOptions option;
option.lg = 2;
tabBarLayoutProperty_->UpdateBarGridAlign(option);
/**
* @tc.steps: steps3. CheckMarqueeForScrollable.
* @tc.expected: steps3. Check the results of CheckMarqueeForScrollable under different conditions.
*/
tabbarLayoutAlgorithm->CheckMarqueeForScrollable(&layoutWrapper);
EXPECT_NE(tabbarLayoutAlgorithm, nullptr);
tabbarLayoutAlgorithm->childCount_ = 1;
tabbarLayoutAlgorithm->CheckMarqueeForScrollable(&layoutWrapper);
EXPECT_NE(tabbarLayoutAlgorithm, nullptr);
}
/**
* @tc.name: TabBarPatternBeforeCreateLayoutWrapper003
* @tc.desc: test Measure