Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 68c1777

Browse files
authored
Prevent overeager cache invalidation when the CollectionView height changes by very small amounts (#13738)
Fixes #13719
1 parent d1af641 commit 68c1777

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewLayout.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public abstract class ItemsViewLayout : UICollectionViewFlowLayout
1717
CGSize _adjustmentSize1;
1818
CGSize _currentSize;
1919

20+
const double ConstraintSizeTolerance = 0.00001;
21+
2022
Dictionary<object, CGSize> _cellSizeCache = new Dictionary<object, CGSize>();
2123

2224
public ItemsUpdatingScrollMode ItemsUpdatingScrollMode { get; set; }
@@ -88,7 +90,7 @@ protected virtual void HandlePropertyChanged(PropertyChangedEventArgs propertyCh
8890

8991
internal virtual void UpdateConstraints(CGSize size)
9092
{
91-
if (size == _currentSize)
93+
if (!RequiresConstraintUpdate(size, _currentSize))
9294
{
9395
return;
9496
}
@@ -588,5 +590,20 @@ internal void ClearCellSizeCache()
588590
{
589591
_cellSizeCache.Clear();
590592
}
593+
594+
bool RequiresConstraintUpdate(CGSize newSize, CGSize current)
595+
{
596+
if (Math.Abs(newSize.Width - current.Width) > ConstraintSizeTolerance)
597+
{
598+
return true;
599+
}
600+
601+
if (Math.Abs(newSize.Height - current.Height) > ConstraintSizeTolerance)
602+
{
603+
return true;
604+
}
605+
606+
return false;
607+
}
591608
}
592609
}

0 commit comments

Comments
 (0)