Skip to content

Commit

Permalink
mac performance gain
Browse files Browse the repository at this point in the history
Only reset layout when column count actually changes. This should be a big performance gain when resizing app height on Mac. More often than not on iOS, column count does change.
  • Loading branch information
williambohrmann3 committed Jul 17, 2024
1 parent 08d7e06 commit e9f12ec
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/MAUI/Maui.Samples/Views/CategoryPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ private void Initialize()
{
var numberOfColumns = (int)Math.Floor(Width / _viewModel.SampleImageWidth);
#if IOS || MACCATALYST
SamplesCollection.ItemsLayout = new GridItemsLayout(numberOfColumns, ItemsLayoutOrientation.Vertical)
// Don't update the layout when column count is the same, for example, when app height changes on Mac.
if (numberOfColumns != (SamplesCollection.ItemsLayout as GridItemsLayout)?.Span)
{
HorizontalItemSpacing = 5,
VerticalItemSpacing = 5
};
SamplesCollection.ItemsLayout = new GridItemsLayout(numberOfColumns, ItemsLayoutOrientation.Vertical)
{
HorizontalItemSpacing = 5,
VerticalItemSpacing = 5
};
}
#elif WINDOWS
SamplesGridItemsLayout.Span = numberOfColumns;
#endif
Expand Down

0 comments on commit e9f12ec

Please sign in to comment.