Add support for sticky group headers (iOS, Android)
This feature is available in the ListView control. E.g. On iOS using the built-in CollectionView it can be added this way:
public class CollectionViewPlatformHandler : CollectionViewHandler { /// <inheritdoc /> protected override ItemsViewLayout SelectLayout() { var layout = base.SelectLayout(); if (ItemsView.IsGrouped && layout is UICollectionViewFlowLayout flowLayout) { // Enable sticky section headers. flowLayout.SectionHeadersPinToVisibleBounds = true; } return layout; } }
Add support for scrollable index titles (iOS).
This feature is available in the ListView control. E.g. On iOS using the built-in CollectionView it can be added this way:
public class CollectionViewPlatformHandler : CollectionViewHandler
{
/// <inheritdoc />
protected override UIView CreatePlatformView()
{
var platformView = base.CreatePlatformView();
if (ItemsView.IsGrouped && ItemsView.ItemsSource is IEnumerable<IGrouping<string, object>> groups && platformView.Subviews[0] is UICollectionView collectionView)
{
// Enable index titles.
collectionView.DataSource = new GroupedCollectionViewDataSource(collectionView.DataSource, groups.Select(q => q.Key));
}
return platformView;
}
private class GroupedCollectionViewDataSource(IUICollectionViewDataSource datasource, IEnumerable<string> sections) : UICollectionViewDataSource
{
public override nint NumberOfSections(UICollectionView collectionView) => datasource.NumberOfSections(collectionView);
public override nint GetItemsCount(UICollectionView collectionView, nint section) => datasource.GetItemsCount(collectionView, section);
public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath) => datasource.GetCell(collectionView, indexPath);
public override UICollectionReusableView GetViewForSupplementaryElement(UICollectionView collectionView, NSString elementKind, NSIndexPath indexPath) => datasource.GetViewForSupplementaryElement(collectionView, elementKind, indexPath);
public override string[] GetIndexTitles(UICollectionView collectionView) => sections.ToArray();
}
}
Note: This is available out-of-the-box on iOS 14 and above for a native UICollectionView. See documentation.