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

Commit

Permalink
Prevent overeager cache invalidation when the CollectionView height c…
Browse files Browse the repository at this point in the history
…hanges by very small amounts (#13738)

Fixes #13719
  • Loading branch information
hartez committed Feb 12, 2021
1 parent d1af641 commit 68c1777
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public abstract class ItemsViewLayout : UICollectionViewFlowLayout
CGSize _adjustmentSize1;
CGSize _currentSize;

const double ConstraintSizeTolerance = 0.00001;

Dictionary<object, CGSize> _cellSizeCache = new Dictionary<object, CGSize>();

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

internal virtual void UpdateConstraints(CGSize size)
{
if (size == _currentSize)
if (!RequiresConstraintUpdate(size, _currentSize))
{
return;
}
Expand Down Expand Up @@ -588,5 +590,20 @@ internal void ClearCellSizeCache()
{
_cellSizeCache.Clear();
}

bool RequiresConstraintUpdate(CGSize newSize, CGSize current)
{
if (Math.Abs(newSize.Width - current.Width) > ConstraintSizeTolerance)
{
return true;
}

if (Math.Abs(newSize.Height - current.Height) > ConstraintSizeTolerance)
{
return true;
}

return false;
}
}
}

0 comments on commit 68c1777

Please sign in to comment.