// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;
using SkiaSharp;
namespace Microsoft.Maui.Platform;
///
/// Skia-rendered CollectionView with selection, headers, and flexible layouts.
///
public class SkiaCollectionView : SkiaItemsView
{
#region BindableProperties
public static readonly BindableProperty SelectionModeProperty = BindableProperty.Create(
nameof(SelectionMode),
typeof(SkiaSelectionMode),
typeof(SkiaCollectionView),
SkiaSelectionMode.Single,
BindingMode.TwoWay,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).OnSelectionModeChanged());
public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create(
nameof(SelectedItem),
typeof(object),
typeof(SkiaCollectionView),
null,
BindingMode.OneWay,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).OnSelectedItemChanged(n));
public static readonly BindableProperty OrientationProperty = BindableProperty.Create(
nameof(Orientation),
typeof(ItemsLayoutOrientation),
typeof(SkiaCollectionView),
ItemsLayoutOrientation.Vertical,
BindingMode.TwoWay,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).Invalidate());
public static readonly BindableProperty SpanCountProperty = BindableProperty.Create(
nameof(SpanCount),
typeof(int),
typeof(SkiaCollectionView),
1,
BindingMode.TwoWay,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).Invalidate(),
coerceValue: (b, v) => Math.Max(1, (int)v));
public static readonly BindableProperty GridItemWidthProperty = BindableProperty.Create(
nameof(GridItemWidth),
typeof(float),
typeof(SkiaCollectionView),
100f,
BindingMode.TwoWay,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).Invalidate());
public static readonly BindableProperty HeaderProperty = BindableProperty.Create(
nameof(Header),
typeof(object),
typeof(SkiaCollectionView),
null,
BindingMode.TwoWay,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).OnHeaderChanged(n));
public static readonly BindableProperty FooterProperty = BindableProperty.Create(
nameof(Footer),
typeof(object),
typeof(SkiaCollectionView),
null,
BindingMode.TwoWay,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).OnFooterChanged(n));
public static readonly BindableProperty HeaderHeightProperty = BindableProperty.Create(
nameof(HeaderHeight),
typeof(float),
typeof(SkiaCollectionView),
0f,
BindingMode.TwoWay,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).Invalidate());
public static readonly BindableProperty FooterHeightProperty = BindableProperty.Create(
nameof(FooterHeight),
typeof(float),
typeof(SkiaCollectionView),
0f,
BindingMode.TwoWay,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).Invalidate());
public static readonly BindableProperty SelectionColorProperty = BindableProperty.Create(
nameof(SelectionColor),
typeof(Color),
typeof(SkiaCollectionView),
Color.FromRgba(33, 150, 243, 89),
BindingMode.TwoWay,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).OnSelectionColorChanged((Color?)n));
public static readonly BindableProperty HeaderBackgroundColorProperty = BindableProperty.Create(
nameof(HeaderBackgroundColor),
typeof(Color),
typeof(SkiaCollectionView),
Color.FromRgb(245, 245, 245),
BindingMode.TwoWay,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).OnHeaderBackgroundColorChanged((Color?)n));
public static readonly BindableProperty FooterBackgroundColorProperty = BindableProperty.Create(
nameof(FooterBackgroundColor),
typeof(Color),
typeof(SkiaCollectionView),
Color.FromRgb(245, 245, 245),
BindingMode.TwoWay,
propertyChanged: (b, o, n) => ((SkiaCollectionView)b).OnFooterBackgroundColorChanged((Color?)n));
#endregion
private List