Fix CV1 GridItemsLayout centering single item AND Fix Empty view not resizing when bounds change
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 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.
@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
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
/azp run MAUI-UITests-public
Azure Pipelines successfully started running 1 pipeline(s).
/backport to release/9.0.1xx-sr8
Started backporting to release/9.0.1xx-sr8: https://github.com/dotnet/maui/actions/runs/15795546965