87 lines
2.6 KiB
C#
87 lines
2.6 KiB
C#
using Blahblah.FlowerApp.Controls;
|
|
using Foundation;
|
|
using UIKit;
|
|
|
|
namespace Blahblah.FlowerApp.Platforms.iOS.Controls;
|
|
|
|
public class MauiWaterfallLayout : UIView, IUICollectionViewDataSource, IUICollectionViewDelegate
|
|
{
|
|
WaterfallLayout? layout;
|
|
UICollectionView? collectionView;
|
|
|
|
public MauiWaterfallLayout(WaterfallLayout layout)
|
|
{
|
|
this.layout = layout;
|
|
|
|
var flow = new FlowLayout(layout.Columns)
|
|
{
|
|
//CalculateCellHeight =
|
|
MinimumInteritemSpacing = 12f,
|
|
SectionInset = new UIEdgeInsets(12f, 12f, 12f, 12f)
|
|
};
|
|
|
|
var refreshControl = new UIRefreshControl
|
|
{
|
|
TintColor = UIColor.SystemFill
|
|
};
|
|
refreshControl.ValueChanged += (sender, e) =>
|
|
{
|
|
if (sender is UIRefreshControl control)
|
|
{
|
|
control.EndRefreshing();
|
|
}
|
|
};
|
|
|
|
collectionView = new UICollectionView(Bounds, flow)
|
|
{
|
|
DataSource = this,
|
|
Delegate = this,
|
|
RefreshControl = refreshControl,
|
|
TranslatesAutoresizingMaskIntoConstraints = false
|
|
};
|
|
AddSubview(collectionView);
|
|
|
|
var safe = SafeAreaLayoutGuide;
|
|
AddConstraints(new[]
|
|
{
|
|
NSLayoutConstraint.Create(collectionView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, safe, NSLayoutAttribute.Leading, 1f, 0f),
|
|
NSLayoutConstraint.Create(collectionView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, safe, NSLayoutAttribute.Trailing, 1f, 0f),
|
|
NSLayoutConstraint.Create(collectionView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, safe, NSLayoutAttribute.Top, 1f, 0f),
|
|
NSLayoutConstraint.Create(collectionView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, safe, NSLayoutAttribute.Bottom, 1f, 0f),
|
|
});
|
|
}
|
|
|
|
public UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
|
|
{
|
|
return new UICollectionViewCell();
|
|
}
|
|
|
|
public nint GetItemsCount(UICollectionView collectionView, nint section)
|
|
{
|
|
return 5;
|
|
}
|
|
|
|
public void UpdateColumns()
|
|
{
|
|
if (layout != null && collectionView?.CollectionViewLayout is FlowLayout flow)
|
|
{
|
|
flow.SetCols(layout.Columns);
|
|
}
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
if (collectionView != null)
|
|
{
|
|
collectionView.Dispose();
|
|
collectionView = null;
|
|
}
|
|
layout = null;
|
|
}
|
|
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|