// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using SkiaSharp;
using System.Collections;
using Microsoft.Maui.Graphics;
namespace Microsoft.Maui.Platform;
///
/// Selection mode for collection views.
///
public enum SkiaSelectionMode
{
None,
Single,
Multiple
}
///
/// Layout orientation for items.
///
public enum ItemsLayoutOrientation
{
Vertical,
Horizontal
}
///
/// Skia-rendered CollectionView with selection, headers, and flexible layouts.
///
public class SkiaCollectionView : SkiaItemsView
{
#region BindableProperties
///
/// Bindable property for SelectionMode.
///
public static readonly BindableProperty SelectionModeProperty =
BindableProperty.Create(
nameof(SelectionMode),
typeof(SkiaSelectionMode),
typeof(SkiaCollectionView),
SkiaSelectionMode.Single,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).OnSelectionModeChanged());
///
/// Bindable property for SelectedItem.
///
public static readonly BindableProperty SelectedItemProperty =
BindableProperty.Create(
nameof(SelectedItem),
typeof(object),
typeof(SkiaCollectionView),
null,
BindingMode.TwoWay,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).OnSelectedItemChanged(n));
///
/// Bindable property for Orientation.
///
public static readonly BindableProperty OrientationProperty =
BindableProperty.Create(
nameof(Orientation),
typeof(ItemsLayoutOrientation),
typeof(SkiaCollectionView),
ItemsLayoutOrientation.Vertical,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).Invalidate());
///
/// Bindable property for SpanCount.
///
public static readonly BindableProperty SpanCountProperty =
BindableProperty.Create(
nameof(SpanCount),
typeof(int),
typeof(SkiaCollectionView),
1,
coerceValue: (b, v) => Math.Max(1, (int)v),
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).Invalidate());
///
/// Bindable property for GridItemWidth.
///
public static readonly BindableProperty GridItemWidthProperty =
BindableProperty.Create(
nameof(GridItemWidth),
typeof(float),
typeof(SkiaCollectionView),
100f,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).Invalidate());
///
/// Bindable property for Header.
///
public static readonly BindableProperty HeaderProperty =
BindableProperty.Create(
nameof(Header),
typeof(object),
typeof(SkiaCollectionView),
null,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).OnHeaderChanged(n));
///
/// Bindable property for Footer.
///
public static readonly BindableProperty FooterProperty =
BindableProperty.Create(
nameof(Footer),
typeof(object),
typeof(SkiaCollectionView),
null,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).OnFooterChanged(n));
///
/// Bindable property for HeaderHeight.
///
public static readonly BindableProperty HeaderHeightProperty =
BindableProperty.Create(
nameof(HeaderHeight),
typeof(float),
typeof(SkiaCollectionView),
0f,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).Invalidate());
///
/// Bindable property for FooterHeight.
///
public static readonly BindableProperty FooterHeightProperty =
BindableProperty.Create(
nameof(FooterHeight),
typeof(float),
typeof(SkiaCollectionView),
0f,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).Invalidate());
///
/// Bindable property for SelectionColor.
///
public static readonly BindableProperty SelectionColorProperty =
BindableProperty.Create(
nameof(SelectionColor),
typeof(SKColor),
typeof(SkiaCollectionView),
new SKColor(0x21, 0x96, 0xF3, 0x59),
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).Invalidate());
///
/// Bindable property for HeaderBackgroundColor.
///
public static readonly BindableProperty HeaderBackgroundColorProperty =
BindableProperty.Create(
nameof(HeaderBackgroundColor),
typeof(SKColor),
typeof(SkiaCollectionView),
new SKColor(0xF5, 0xF5, 0xF5),
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).Invalidate());
///
/// Bindable property for FooterBackgroundColor.
///
public static readonly BindableProperty FooterBackgroundColorProperty =
BindableProperty.Create(
nameof(FooterBackgroundColor),
typeof(SKColor),
typeof(SkiaCollectionView),
new SKColor(0xF5, 0xF5, 0xF5),
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).Invalidate());
#endregion
private List