!49254 List组件空指针告警整改

Merge pull request !49254 from yeyinglong/listtest5
This commit is contained in:
openharmony_ci 2024-11-23 03:16:12 +00:00 committed by Gitee
commit 76aa265179
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 17 additions and 17 deletions

View File

@ -27,10 +27,8 @@ constexpr uint32_t GRID_COUNTS_6 = 6;
constexpr uint32_t GRID_COUNTS_8 = 8;
constexpr uint32_t GRID_COUNTS_12 = 12;
uint32_t GetMaxGridCounts(const RefPtr<GridColumnInfo>& columnInfo)
uint32_t GetMaxGridCounts(int32_t currentColumns)
{
CHECK_NULL_RETURN(columnInfo, GRID_COUNTS_8);
auto currentColumns = columnInfo->GetParent()->GetColumns();
auto maxGridCounts = GRID_COUNTS_8;
switch (currentColumns) {
case GRID_COUNTS_4:
@ -72,9 +70,7 @@ void ListItemGroupLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper)
childLayoutConstraint_ = layoutProperty->CreateChildConstraint();
isCardStyle_ = IsCardStyleForListItemGroup(layoutWrapper);
if (isCardStyle_) {
auto maxWidth = GetListItemGroupMaxWidth(contentConstraint.parentIdealSize, layoutProperty) -
layoutProperty->CreatePaddingAndBorder().Width();
contentIdealSize.SetCrossSize(maxWidth, axis_);
UpdateListItemGroupMaxWidth(contentConstraint.parentIdealSize, layoutProperty, contentIdealSize);
listLayoutProperty_->UpdateListItemAlign(V2::ListItemAlign::CENTER);
}
UpdateListItemConstraint(contentIdealSize, childLayoutConstraint_);
@ -134,22 +130,25 @@ void ListItemGroupLayoutAlgorithm::UpdateCachedItemPosition(int32_t cacheCount)
}
}
float ListItemGroupLayoutAlgorithm::GetListItemGroupMaxWidth(
const OptionalSizeF& parentIdealSize, RefPtr<LayoutProperty> layoutProperty)
void ListItemGroupLayoutAlgorithm::UpdateListItemGroupMaxWidth(
const OptionalSizeF& parentIdealSize, RefPtr<LayoutProperty> layoutProperty, OptionalSizeF& contentIdealSize)
{
RefPtr<GridColumnInfo> columnInfo;
columnInfo = GridSystemManager::GetInstance().GetInfoByType(GridColumnType::LIST_CARD);
columnInfo->GetParent()->BuildColumnWidth();
auto maxGridWidth = static_cast<float>(columnInfo->GetWidth(GetMaxGridCounts(columnInfo)));
auto parentWidth = parentIdealSize.CrossSize(axis_).value() + layoutProperty->CreatePaddingAndBorder().Width();
RefPtr<GridColumnInfo> columnInfo = GridSystemManager::GetInstance().GetInfoByType(GridColumnType::LIST_CARD);
CHECK_NULL_VOID(columnInfo);
auto columnParent = columnInfo->GetParent();
CHECK_NULL_VOID(columnParent);
columnParent->BuildColumnWidth();
auto maxGridWidth = static_cast<float>(columnInfo->GetWidth(GetMaxGridCounts(columnParent->GetColumns())));
float paddingWidth = layoutProperty->CreatePaddingAndBorder().Width();
auto parentWidth = parentIdealSize.CrossSize(axis_).value() + paddingWidth;
auto maxWidth = std::min(parentWidth, maxGridWidth);
if (LessNotEqual(maxGridWidth, layoutProperty->CreatePaddingAndBorder().Width())) {
if (LessNotEqual(maxGridWidth, paddingWidth)) {
TAG_LOGI(AceLogTag::ACE_LIST,
"ListItemGroup reset to parentWidth since grid_col width:%{public}f, border:%{public}f",
maxGridWidth, layoutProperty->CreatePaddingAndBorder().Width());
maxGridWidth, paddingWidth);
maxWidth = parentWidth;
}
return maxWidth;
contentIdealSize.SetCrossSize(maxWidth - paddingWidth, axis_);
}
void ListItemGroupLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper)

View File

@ -430,7 +430,8 @@ private:
static void SetListItemIndex(const LayoutWrapper* groupLayoutWrapper,
const RefPtr<LayoutWrapper>& itemLayoutWrapper, int32_t indexInGroup);
bool IsCardStyleForListItemGroup(const LayoutWrapper* groupLayoutWrapper);
float GetListItemGroupMaxWidth(const OptionalSizeF& parentIdealSize, RefPtr<LayoutProperty> layoutProperty);
void UpdateListItemGroupMaxWidth(const OptionalSizeF& parentIdealSize, RefPtr<LayoutProperty> layoutProperty,
OptionalSizeF& contentIdealSize);
void AdjustItemPosition();
bool CheckNeedMeasure(const RefPtr<LayoutWrapper>& layoutWrapper) const;
void MeasureCacheItem(LayoutWrapper* layoutWrapper);