Skip to content

Commit fbe056e

Browse files
CopilotSuthiYuvaraj
andcommitted
Fix UICollectionViewFlowLayout compilation error by removing invalid GetSizeForItem override
Co-authored-by: SuthiYuvaraj <[email protected]>
1 parent 4a9f369 commit fbe056e

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -552,51 +552,40 @@ public override void PrepareLayout()
552552

553553
void MeasureFirstItem()
554554
{
555-
if (CollectionView?.DataSource == null) return;
555+
if (CollectionView?.NumberOfItemsInSection(0) == 0) return;
556556

557-
// Try to get the first visible cell
557+
// For MeasureFirstItem strategy, we need to measure a prototype cell and apply that size to all items
558+
// This is similar to the pattern used in ItemsViewLayout.DetermineCellSize()
559+
560+
// Try to get the first visible cell to measure
558561
var indexPath = NSIndexPath.FromItemSection(0, 0);
559562
var cell = CollectionView.CellForItem(indexPath);
560563

561-
if (cell != null)
564+
if (cell != null && cell.Frame.Size.Width > 0 && cell.Frame.Size.Height > 0)
562565
{
563-
// Measure the actual cell
564-
var cellSize = cell.Frame.Size;
565-
if (cellSize.Width > 0 && cellSize.Height > 0)
566-
{
567-
_measuredItemSize = cellSize;
568-
ItemSize = cellSize;
569-
EstimatedItemSize = CGSize.Empty; // Disable auto-sizing
570-
InvalidateLayout(); // Trigger layout update
571-
}
566+
// Use the size of the first visible cell
567+
_measuredItemSize = cell.Frame.Size;
568+
ItemSize = _measuredItemSize.Value;
569+
EstimatedItemSize = CGSize.Empty; // Disable auto-sizing for fixed size
570+
InvalidateLayout();
572571
}
573-
}
574-
575-
public override CGSize GetSizeForItem(UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath)
576-
{
577-
if (_measuredItemSize.HasValue)
578-
{
579-
return _measuredItemSize.Value;
580-
}
581-
582-
// If we haven't measured yet, try to measure now
583-
if (indexPath.Item == 0)
572+
else
584573
{
585-
// For the first item, we need to measure it
586-
// This is a simplified approach - in a full implementation you'd create a prototype cell
587-
var estimatedSize = EstimatedItemSize;
588-
if (estimatedSize.Width > 0 && estimatedSize.Height > 0)
574+
// If no visible cell is available, we'll use the estimated size and update later
575+
// This follows the pattern from ItemsViewLayout where EstimatedItemSize is set initially
576+
// and updated once a cell becomes available
577+
if (EstimatedItemSize.Width > 0 && EstimatedItemSize.Height > 0)
589578
{
590-
_measuredItemSize = estimatedSize;
591-
ItemSize = estimatedSize;
579+
_measuredItemSize = EstimatedItemSize;
580+
ItemSize = _measuredItemSize.Value;
592581
EstimatedItemSize = CGSize.Empty;
582+
InvalidateLayout();
593583
}
594-
return estimatedSize;
595584
}
596-
597-
return base.GetSizeForItem(collectionView, layout, indexPath);
598585
}
599586

587+
588+
600589
public override CGPoint TargetContentOffset(CGPoint proposedContentOffset, CGPoint scrollingVelocity)
601590
{
602591
var snapPointsType = _snapInfo.SnapType;

0 commit comments

Comments
 (0)