diff --git a/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs b/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs index 3d9ef7689442..9cd6050eb2e3 100644 --- a/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs +++ b/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs @@ -101,24 +101,21 @@ protected override CGRect DetermineEmptyViewFrame() public override void ViewWillLayoutSubviews() { base.ViewWillLayoutSubviews(); + // This updates the positions of the header view and footer view as their sizes change dynamically + var emptyView = CollectionView.ViewWithTag(EmptyTag); - // This update is only relevant if you have a footer view because it's used to place the footer view - // based on the ContentSize so we just update the positions if the ContentSize has changed - if (_footerUIView != null) + if (IsHorizontal) { - var emptyView = CollectionView.ViewWithTag(EmptyTag); - - if (IsHorizontal) + if ((_headerUIView is not null && (_headerUIView.Frame.X != ItemsViewLayout.CollectionViewContentSize.Width || _headerUIView.Frame.X < emptyView?.Frame.X)) || (_footerUIView is not null && (_footerUIView.Frame.X != ItemsViewLayout.CollectionViewContentSize.Width || _footerUIView.Frame.X != _footerUIView.Frame.Width || _footerUIView.Frame.X < emptyView?.Frame.X))) { - if (_footerUIView.Frame.X != ItemsViewLayout.CollectionViewContentSize.Width || - _footerUIView.Frame.X < emptyView?.Frame.X) - UpdateHeaderFooterPosition(); + UpdateHeaderFooterPosition(); } - else + } + else + { + if ((_headerUIView is not null && (_headerUIView.Frame.Y != ItemsViewLayout.CollectionViewContentSize.Height || _headerUIView.Frame.Y < (emptyView?.Frame.Y + emptyView?.Frame.Height))) || (_footerUIView is not null && (_footerUIView.Frame.Y != ItemsViewLayout.CollectionViewContentSize.Height || _footerUIView.Frame.Y != _footerUIView.Frame.Height || _footerUIView.Frame.Y < (emptyView?.Frame.Y + emptyView?.Frame.Height)))) { - if (_footerUIView.Frame.Y != ItemsViewLayout.CollectionViewContentSize.Height || - _footerUIView.Frame.Y < (emptyView?.Frame.Y + emptyView?.Frame.Height)) - UpdateHeaderFooterPosition(); + UpdateHeaderFooterPosition(); } } } @@ -209,7 +206,9 @@ void UpdateHeaderFooterPosition() _headerUIView.Frame = new CoreGraphics.CGRect(-headerWidth, 0, headerWidth, CollectionView.Frame.Height); } - if (_footerUIView != null && (_footerUIView.Frame.X != ItemsViewLayout.CollectionViewContentSize.Width || emptyWidth > 0)) + // The FooterView frame is updated when the CollectionView does not contain any items. + // Previously, the FooterView frame was updated only for a CollectionView with an ItemSource. + if (_footerUIView != null && (_footerUIView.Frame.X != ItemsViewLayout.CollectionViewContentSize.Width || _footerUIView.Frame.X != footerWidth || emptyWidth > 0)) _footerUIView.Frame = new CoreGraphics.CGRect(ItemsViewLayout.CollectionViewContentSize.Width + emptyWidth, 0, footerWidth, CollectionView.Frame.Height); if (CollectionView.ContentInset.Left != headerWidth || CollectionView.ContentInset.Right != footerWidth) @@ -262,7 +261,9 @@ void UpdateHeaderFooterPosition() height = ItemsViewLayout.CollectionViewContentSize.Height; } - if (_footerUIView != null && (_footerUIView.Frame.Y != height || emptyHeight > 0)) + // The FooterView frame is updated when the CollectionView does not contain any items. + // Previously, the FooterView frame was updated only for a CollectionView with an ItemSource. + if (_footerUIView != null && (_footerUIView.Frame.Y != height || _footerUIView.Frame.Y != footerHeight || emptyHeight > 0)) { _footerUIView.Frame = new CoreGraphics.CGRect(0, height + emptyHeight, CollectionView.Frame.Width, footerHeight); } diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldHeaderFooterUpdateWithoutCroppingOnResizing.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldHeaderFooterUpdateWithoutCroppingOnResizing.png new file mode 100644 index 000000000000..912dd65b0b3b Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldHeaderFooterUpdateWithoutCroppingOnResizing.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue26186.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue26186.xaml new file mode 100644 index 000000000000..03e4274a882c --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue26186.xaml @@ -0,0 +1,92 @@ + + + +