@@ -552,51 +552,40 @@ public override void PrepareLayout()
552
552
553
553
void MeasureFirstItem ( )
554
554
{
555
- if ( CollectionView ? . DataSource == null ) return ;
555
+ if ( CollectionView ? . NumberOfItemsInSection ( 0 ) == 0 ) return ;
556
556
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
558
561
var indexPath = NSIndexPath . FromItemSection ( 0 , 0 ) ;
559
562
var cell = CollectionView . CellForItem ( indexPath ) ;
560
563
561
- if ( cell != null )
564
+ if ( cell != null && cell . Frame . Size . Width > 0 && cell . Frame . Size . Height > 0 )
562
565
{
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 ( ) ;
572
571
}
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
584
573
{
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 )
589
578
{
590
- _measuredItemSize = estimatedSize ;
591
- ItemSize = estimatedSize ;
579
+ _measuredItemSize = EstimatedItemSize ;
580
+ ItemSize = _measuredItemSize . Value ;
592
581
EstimatedItemSize = CGSize . Empty ;
582
+ InvalidateLayout ( ) ;
593
583
}
594
- return estimatedSize ;
595
584
}
596
-
597
- return base . GetSizeForItem ( collectionView , layout , indexPath ) ;
598
585
}
599
586
587
+
588
+
600
589
public override CGPoint TargetContentOffset ( CGPoint proposedContentOffset , CGPoint scrollingVelocity )
601
590
{
602
591
var snapPointsType = _snapInfo . SnapType ;
0 commit comments