Skip to content

Commit

Permalink
Update layout logic a bit on ios
Browse files Browse the repository at this point in the history
  • Loading branch information
Redth committed May 8, 2024
1 parent e4c9b0d commit e81f73a
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions VirtualListView/Apple/CvLayout.ios.maccatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public override UICollectionViewLayoutAttributes LayoutAttributesForItem(NSIndex
var width = GetLayoutFullWidth(sectionInset);
NFloat gridItemInset = 0f;

if (columns > 1 && info is not null && info.Kind != PositionKind.Header && info.Kind != PositionKind.Footer)
if (columns > 1 && info is not null && info.Kind == PositionKind.Item)
{
width = width / columns;

// Index 0 is first item in grid's row, so 0 additional inset
// for every next item, we need to add width of previous item
gridItemInset = width * info.ItemIndex;
gridItemInset = width * (info.ItemIndex % columns);
}

layoutAttributes.Frame = new CGRect(sectionInset.Left + gridItemInset, layoutAttributes.Frame.Y, width, layoutAttributes.Frame.Height);
Expand All @@ -69,7 +69,7 @@ public override UICollectionViewLayoutAttributes LayoutAttributesForItem(NSIndex
var height = GetLayoutFullHeight(sectionInset);
NFloat gridItemInset = 0f;

if (columns > 1 && info is not null && info.Kind != PositionKind.Header && info.Kind != PositionKind.Footer)
if (columns > 1 && info is not null && info.Kind == PositionKind.Item)
{
height = height / columns;

Expand All @@ -84,10 +84,26 @@ public override UICollectionViewLayoutAttributes LayoutAttributesForItem(NSIndex
return layoutAttributes;
}

// public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CGRect rect)
// {
// var layoutAttributesObjects = base.LayoutAttributesForElementsInRect(rect);
//
// foreach (var layoutAttributes in layoutAttributesObjects)
// {
// if (layoutAttributes.RepresentedElementCategory == UICollectionElementCategory.Cell)
// {
// var newFrame = LayoutAttributesForItem(layoutAttributes.IndexPath).Frame;
// layoutAttributes.Frame = newFrame;
// }
// }
//
// return layoutAttributesObjects;
// }

public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CGRect rect)
{
var layoutAttributesObjects = base.LayoutAttributesForElementsInRect(rect);

foreach (var layoutAttributes in layoutAttributesObjects)
{
if (layoutAttributes.RepresentedElementCategory == UICollectionElementCategory.Cell)
Expand Down

0 comments on commit e81f73a

Please sign in to comment.