!39174 修复AlphabetIndexer组件折叠模式选择未考虑padding的问题

Merge pull request !39174 from zhangDH/dev
This commit is contained in:
openharmony_ci 2024-07-30 03:35:30 +00:00 committed by Gitee
commit b10fd73785
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 46 additions and 46 deletions

View File

@ -61,21 +61,21 @@ void IndexerLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper)
auto adaptiveWidth = indexerLayoutProperty->GetAdaptiveWidthValue(false);
auto maxItemWidth = adaptiveWidth ? GetMaxItemWidth(layoutWrapper) : 0.0f;
auto contentWidth =
(adaptiveWidth ? (GreatOrEqual(maxItemWidth, itemSize_) ? maxItemWidth : itemSize_) : itemSize_) +
horizontalPadding;
auto contentWidth = adaptiveWidth ? (GreatOrEqual(maxItemWidth, itemSize_) ? maxItemWidth : itemSize_) : itemSize_;
auto frameWidth = selfIdealSize.Width().has_value()
? selfIdealSize.Width().value()
: std::clamp(contentWidth, 0.0f, layoutConstraint.maxSize.Width());
itemWidth_ = GreatOrEqual(frameWidth - horizontalPadding, 0.0f) ? frameWidth - horizontalPadding : 0.0f;
: std::clamp(contentWidth + horizontalPadding, 0.0f, layoutConstraint.maxSize.Width());
itemWidth_ = GreatNotEqual(frameWidth - horizontalPadding, 0.0f) ? frameWidth - horizontalPadding : 0.0f;
auto contentHeight = childCount * itemSize_ + verticalPadding;
maxFrameHeight_ = selfIdealSize.Height().has_value()
? selfIdealSize.Height().value() : layoutConstraint.maxSize.Height();
contentHeight = GreatNotEqual(contentHeight, maxFrameHeight_) ? maxFrameHeight_ : contentHeight;
itemHeight_ = GreatOrEqual(contentHeight - verticalPadding, 0.0f) && childCount > 0
? (contentHeight - verticalPadding) / childCount : 0.0f;
float frameHeight = selfIdealSize.Height().has_value() ? selfIdealSize.Height().value() : contentHeight;
auto contentHeight = childCount * itemSize_;
float maxFrameHeight =
selfIdealSize.Height().has_value() ? selfIdealSize.Height().value() : layoutConstraint.maxSize.Height();
maxContentHeight_ = GreatNotEqual(maxFrameHeight - verticalPadding, 0.0f) ? maxFrameHeight - verticalPadding : 0.0f;
contentHeight = GreatNotEqual(contentHeight, maxContentHeight_) ? maxContentHeight_ : contentHeight;
itemHeight_ = GreatNotEqual(contentHeight, 0.0f) && childCount > 0 ? contentHeight / childCount : 0.0f;
float frameHeight = selfIdealSize.Height().has_value()
? selfIdealSize.Height().value()
: std::clamp(contentHeight + verticalPadding, 0.0f, layoutConstraint.maxSize.Height());
auto childLayoutConstraint = indexerLayoutProperty->CreateChildConstraint();
for (int32_t index = 0; index < childCount; index++) {

View File

@ -36,9 +36,9 @@ public:
return itemHeight_;
}
float GetMaxFrameHeight() const
float GetMaxContentHeight() const
{
return maxFrameHeight_;
return maxContentHeight_;
}
void Measure(LayoutWrapper* layoutWrapper) override;
@ -56,7 +56,7 @@ private:
float itemSize_ = 0.0f;
float itemWidth_ = 0.0f;
float itemHeight_ = 0.0f;
float maxFrameHeight_ = 0.0f;
float maxContentHeight_ = 0.0f;
};
} // namespace OHOS::Ace::NG

View File

@ -185,9 +185,9 @@ bool IndexerPattern::OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty
auto indexerLayoutAlgorithm = DynamicCast<IndexerLayoutAlgorithm>(layoutAlgorithmWrapper->GetLayoutAlgorithm());
CHECK_NULL_RETURN(indexerLayoutAlgorithm, false);
itemHeight_ = indexerLayoutAlgorithm->GetItemHeight();
auto height = indexerLayoutAlgorithm->GetMaxFrameHeight();
if (maxFrameHeight_ != height && lastAutoCollapse_) {
maxFrameHeight_ = height;
auto height = indexerLayoutAlgorithm->GetMaxContentHeight();
if (maxContentHeight_ != height && lastAutoCollapse_) {
maxContentHeight_ = height;
isNewHeightCalculated_ = true;
auto hostNode = dirty->GetHostNode();
StartCollapseDelayTask(hostNode, INDEXER_COLLAPSE_WAIT_DURATION);
@ -245,7 +245,7 @@ void IndexerPattern::CollapseArrayValue()
auto itemSize =
layoutProperty->GetItemSize().value_or(Dimension(INDEXER_ITEM_SIZE, DimensionUnit::VP)).ConvertToVp();
int32_t maxItemsCount = 0;
auto height = Dimension(maxFrameHeight_, DimensionUnit::PX).ConvertToVp();
auto height = Dimension(maxContentHeight_, DimensionUnit::PX).ConvertToVp();
if (height > 0 && itemSize > 0) {
maxItemsCount = static_cast<int32_t>(height / itemSize);
}

View File

@ -226,7 +226,7 @@ private:
bool autoCollapse_ = true;
bool lastAutoCollapse_ = true;
bool enableHapticFeedback_ = true;
float maxFrameHeight_ = 0.0f;
float maxContentHeight_ = 0.0f;
bool isNewHeightCalculated_ = false;
bool selectedChangedForHaptic_ = false;
IndexerCollapsingMode lastCollapsingMode_ = IndexerCollapsingMode::INVALID;

View File

@ -152,7 +152,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone009, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 160.f;
indexerLayoutAlgorithm->maxContentHeight_ = 160.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -200,7 +200,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0010, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 160.f;
indexerLayoutAlgorithm->maxContentHeight_ = 160.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
dirtySwapConfig.skipMeasure = false;
@ -246,7 +246,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0011, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 160.f;
indexerLayoutAlgorithm->maxContentHeight_ = 160.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -293,7 +293,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0012, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 160.f;
indexerLayoutAlgorithm->maxContentHeight_ = 160.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -341,7 +341,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0013, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 95.f;
indexerLayoutAlgorithm->maxContentHeight_ = 95.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -389,7 +389,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0014, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 160.f;
indexerLayoutAlgorithm->maxContentHeight_ = 160.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -437,7 +437,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0015, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 160.f;
indexerLayoutAlgorithm->maxContentHeight_ = 160.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -485,7 +485,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0016, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 160.f;
indexerLayoutAlgorithm->maxContentHeight_ = 160.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -532,7 +532,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0017, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 160.f;
indexerLayoutAlgorithm->maxContentHeight_ = 160.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -579,7 +579,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0018, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 160.f;
indexerLayoutAlgorithm->maxContentHeight_ = 160.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
dirtySwapConfig.skipMeasure = false;
@ -625,7 +625,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0019, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 150.f;
indexerLayoutAlgorithm->maxContentHeight_ = 150.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -662,7 +662,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0020, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 150.f;
indexerLayoutAlgorithm->maxContentHeight_ = 150.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -699,7 +699,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0021, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 150.f;
indexerLayoutAlgorithm->maxContentHeight_ = 150.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -736,7 +736,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0022, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 150.f;
indexerLayoutAlgorithm->maxContentHeight_ = 150.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -773,7 +773,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0023, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 150.f;
indexerLayoutAlgorithm->maxContentHeight_ = 150.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -810,7 +810,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0024, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 150.f;
indexerLayoutAlgorithm->maxContentHeight_ = 150.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -847,7 +847,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0025, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 100.f;
indexerLayoutAlgorithm->maxContentHeight_ = 100.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -897,7 +897,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0026, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 100.f;
indexerLayoutAlgorithm->maxContentHeight_ = 100.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -947,7 +947,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0027, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 100.f;
indexerLayoutAlgorithm->maxContentHeight_ = 100.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -997,7 +997,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0028, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 100.f;
indexerLayoutAlgorithm->maxContentHeight_ = 100.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -1048,7 +1048,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0029, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 100.f;
indexerLayoutAlgorithm->maxContentHeight_ = 100.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -1098,7 +1098,7 @@ HWTEST_F(IndexerModelTestNg, OnModifyDone0030, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 100.f;
indexerLayoutAlgorithm->maxContentHeight_ = 100.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;

View File

@ -1292,7 +1292,7 @@ HWTEST_F(IndexerTestNg, OnModifyDone003, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 95.f;
indexerLayoutAlgorithm->maxContentHeight_ = 95.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -1340,7 +1340,7 @@ HWTEST_F(IndexerTestNg, OnModifyDone004, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 95.f;
indexerLayoutAlgorithm->maxContentHeight_ = 95.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -1443,7 +1443,7 @@ HWTEST_F(IndexerTestNg, OnModifyDone007, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 150.f;
indexerLayoutAlgorithm->maxContentHeight_ = 150.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;
@ -1480,7 +1480,7 @@ HWTEST_F(IndexerTestNg, OnModifyDone008, TestSize.Level1)
RefPtr<LayoutAlgorithmWrapper> layoutAlgorithmWrapper =
AceType::MakeRefPtr<LayoutAlgorithmWrapper>(indexerLayoutAlgorithm);
indexerLayoutAlgorithm->itemHeight_ = 24.f;
indexerLayoutAlgorithm->maxFrameHeight_ = 100.f;
indexerLayoutAlgorithm->maxContentHeight_ = 100.f;
layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
DirtySwapConfig dirtySwapConfig;