diff --git a/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs b/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs index 674ce2f5dfad..cfe2b7929c50 100644 --- a/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs +++ b/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs @@ -67,6 +67,11 @@ public void UpdateLayout(UICollectionViewLayout newLayout) ScrollDirection = compositionalLayout.Configuration.ScrollDirection; } + // Preserve the content offset before updating the layout. + // SetCollectionViewLayout with animated:false can unexpectedly shift the content offset + // on UICollectionViewCompositionalLayout with estimated item sizes. + var savedOffset = CollectionView.ContentOffset; + ItemsViewLayout = newLayout; _initialized = false; @@ -74,6 +79,8 @@ public void UpdateLayout(UICollectionViewLayout newLayout) if (_initialized) { + // Restore the content offset that may have been changed by SetCollectionViewLayout + CollectionView.ContentOffset = savedOffset; // Reload the data so the currently visible cells get laid out according to the new layout ReloadData(); }