diff --git a/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs b/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs index 18162b663c67..6cd52b808535 100644 --- a/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs +++ b/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs @@ -15,6 +15,8 @@ public abstract class ItemsViewController : UICollectionViewControll where TItemsView : ItemsView { public const int EmptyTag = 333; + const int HeaderTag = 111; + const int FooterTag = 222; readonly WeakReference _itemsView; public IItemsViewSource ItemsSource { get; protected set; } @@ -277,7 +279,37 @@ void InvalidateMeasureIfContentSizeChanged() return _emptyUIView.Frame.Size.ToSize(); } - return CollectionView.CollectionViewLayout.CollectionViewContentSize.ToSize(); + CGSize contentSize = CollectionView.CollectionViewLayout.CollectionViewContentSize; + CGSize headerSize = GetHeaderSize(); + CGSize footerSize = GetFooterSize(); + + nfloat totalWidth = contentSize.Width; + nfloat totalHeight = contentSize.Height; + + // Ensure calculating the total width or height, consider the boundary conditions to ensure it does not exceed the boundaries of the view. + // If it exceeds, the content becomes non-scrollable and is constrained to the view's screen size. + if (IsHorizontal) + { + totalWidth += headerSize.Width + footerSize.Width; + totalWidth = (nfloat)Math.Min(totalWidth, CollectionView.Bounds.Width); + } + else + { + totalHeight += headerSize.Height + footerSize.Height; + totalHeight = (nfloat)Math.Min(totalHeight, CollectionView.Bounds.Height); + } + + return new Size(totalWidth, totalHeight); + } + + CGSize GetHeaderSize() + { + return CollectionView.ViewWithTag(HeaderTag)?.Frame.Size ?? CGSize.Empty; + } + + CGSize GetFooterSize() + { + return CollectionView.ViewWithTag(FooterTag)?.Frame.Size ?? CGSize.Empty; } void ConstrainItemsToBounds() diff --git a/src/Controls/tests/TestCases.HostApp/Elements/CollectionView/HeaderFooterGalleries/HeaderFooterGrid.xaml b/src/Controls/tests/TestCases.HostApp/Elements/CollectionView/HeaderFooterGalleries/HeaderFooterGrid.xaml index d201367a3d12..a79002c15a42 100644 --- a/src/Controls/tests/TestCases.HostApp/Elements/CollectionView/HeaderFooterGalleries/HeaderFooterGrid.xaml +++ b/src/Controls/tests/TestCases.HostApp/Elements/CollectionView/HeaderFooterGalleries/HeaderFooterGrid.xaml @@ -16,27 +16,27 @@ - - + + - - + + - - + + - - + + \ No newline at end of file diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/HeaderFooterGridWorks.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/HeaderFooterGridWorks.png index b66279a9679e..09d7ce826222 100644 Binary files a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/HeaderFooterGridWorks.png and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/HeaderFooterGridWorks.png differ