maui icon indicating copy to clipboard operation
maui copied to clipboard

Fix CV1 GridItemsLayout centering single item AND Fix Empty view not resizing when bounds change

Open albyrock87 opened this issue 7 months ago • 4 comments

Description of Change

GridViewLayout has a special positioning override when there's only one item.

if (ScrollDirection == UICollectionViewScrollDirection.Vertical && NeedsSingleItemHorizontalAlignmentAdjustment(layoutAttributesForRectElements))
{
	// If there's exactly one item in a vertically scrolling grid, for some reason UICollectionViewFlowLayout
	// tries to center it. This corrects that issue.
	var currentFrame = layoutAttributesForRectElements[0].Frame;
	var newFrame = new CGRect(CollectionView.Frame.Left + CollectionView.ContentInset.Right,
	currentFrame.Top, currentFrame.Width, currentFrame.Height);
	layoutAttributesForRectElements[0].Frame = newFrame;
}

So we have to invalidate the layout entirely to trigger that special case, instead of just simply invalidate single cells.

Issues Fixed

Fixes #29595 Fixes #29634

albyrock87 avatar May 23 '25 11:05 albyrock87

@albyrock87 seems theres still a slight difference, I wonder if we should change the threshold of the comparison .

VisualTestUtils.VisualTestFailedException :
Snapshot different than baseline: VerifyGridItemsLayoutSingleAndEmptyViewResize.png (0.50% difference)
If the correct baseline has changed (this isn't a a bug), then update the baseline image.
See test attachment or download the build artifacts to get the new snapshot file.

rmarinho avatar May 27 '25 18:05 rmarinho

@mattleibow I should have addressed all your concerns in the last force-push

  • I've simplified/separated the UITests (they were initially done based on user reports while now they focus on the single issues)
  • CV2 is not affected by those bugs because:
    • Supplementary views are handled differently (not hacky)
    • It uses the compositional layout so the grid layout left-align on single item is not hacky
  • This time the UITests should not be flacky

albyrock87 avatar Jun 05 '25 11:06 albyrock87

/azp run

PureWeen avatar Jun 05 '25 11:06 PureWeen

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Jun 05 '25 11:06 azure-pipelines[bot]

/azp run

PureWeen avatar Jun 19 '25 20:06 PureWeen

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Jun 19 '25 20:06 azure-pipelines[bot]

/azp run MAUI-UITests-public

PureWeen avatar Jun 20 '25 16:06 PureWeen

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jun 20 '25 16:06 azure-pipelines[bot]

/backport to release/9.0.1xx-sr8

PureWeen avatar Jun 21 '25 12:06 PureWeen

Started backporting to release/9.0.1xx-sr8: https://github.com/dotnet/maui/actions/runs/15795546965

github-actions[bot] avatar Jun 21 '25 12:06 github-actions[bot]