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

Prevent overeager cache invalidation when the CollectionView height changes by very small amounts #13738

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}