Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Global Header and Footer not being visible #43

Merged
merged 4 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions VirtualListView/Apple/CvCell.ios.maccatalyst.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using CoreGraphics;
using Foundation;
using Microsoft.Maui.Platform;
using Microsoft.VisualBasic;
using System.Diagnostics.CodeAnalysis;
using UIKit;

namespace Microsoft.Maui;
Expand Down
20 changes: 8 additions & 12 deletions VirtualListView/Apple/CvDataSource.ios.maccatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,19 @@ public override UICollectionViewCell GetCell(UICollectionView collectionView, NS
info.IsSelected = false;
else
info.IsSelected = Handler?.IsItemSelected(info.SectionIndex, info.ItemIndex) ?? false;
}

if (cell.NeedsView && info is not null && data is not null)
{
var view = Handler?.PositionalViewSelector?.ViewSelector?.CreateView(info, data);
if (view is not null)
cell.SetupView(view);
}

if (cell.NeedsView)
{
var view = Handler?.PositionalViewSelector?.ViewSelector?.CreateView(info, data);
if (view is not null)
cell.SetupView(view);
}

if (info is not null)
{
cell.UpdatePosition(info);

if (data is not null && (cell.VirtualView?.TryGetTarget(out var cellVirtualView) ?? false))
if (cell.VirtualView?.TryGetTarget(out var cellVirtualView) ?? false)
{
Handler?.PositionalViewSelector?.ViewSelector?.RecycleView(info, data, cellVirtualView);

Handler?.VirtualView?.ViewSelector?.ViewAttached(info, cellVirtualView);
}
}
Expand Down
51 changes: 26 additions & 25 deletions VirtualListView/Controls/VirtualListView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows.Input;
#nullable enable
using System.Windows.Input;
using Microsoft.Maui.Adapters;

namespace Microsoft.Maui.Controls;
Expand All @@ -21,7 +22,7 @@
BindableProperty.Create(nameof(Adapter), typeof(IVirtualListViewAdapter), typeof(VirtualListView), default);


public IView GlobalHeader
public IView? GlobalHeader
{
get => (IView)GetValue(GlobalHeaderProperty);
set => SetValue(GlobalHeaderProperty, value);
Expand All @@ -39,7 +40,7 @@
public static readonly BindableProperty IsHeaderVisibleProperty =
BindableProperty.Create(nameof(IsHeaderVisible), typeof(bool), typeof(VirtualListView), true);

public IView GlobalFooter
public IView? GlobalFooter
{
get => (IView)GetValue(GlobalFooterProperty);
set => SetValue(GlobalFooterProperty, value);
Expand All @@ -59,7 +60,7 @@
BindableProperty.Create(nameof(IsFooterVisible), typeof(bool), typeof(VirtualListView), true);


public DataTemplate ItemTemplate
public DataTemplate? ItemTemplate
{
get => (DataTemplate)GetValue(ItemTemplateProperty);
set => SetValue(ItemTemplateProperty, value);
Expand All @@ -68,7 +69,7 @@
public static readonly BindableProperty ItemTemplateProperty =
BindableProperty.Create(nameof(ItemTemplate), typeof(DataTemplate), typeof(VirtualListView), default);

public VirtualListViewItemTemplateSelector ItemTemplateSelector
public VirtualListViewItemTemplateSelector? ItemTemplateSelector
{
get => (VirtualListViewItemTemplateSelector)GetValue(ItemTemplateSelectorProperty);
set => SetValue(ItemTemplateSelectorProperty, value);
Expand Down Expand Up @@ -97,7 +98,7 @@
public static readonly BindableProperty HorizontalScrollbarVisibilityProperty =
BindableProperty.Create(nameof(HorizontalScrollbarVisibility), typeof(ScrollBarVisibility), typeof(VirtualListView), ScrollBarVisibility.Default);

public DataTemplate SectionHeaderTemplate
public DataTemplate? SectionHeaderTemplate
{
get => (DataTemplate)GetValue(SectionHeaderTemplateProperty);
set => SetValue(SectionHeaderTemplateProperty, value);
Expand All @@ -106,7 +107,7 @@
public static readonly BindableProperty SectionHeaderTemplateProperty =
BindableProperty.Create(nameof(SectionHeaderTemplate), typeof(DataTemplate), typeof(VirtualListView), default);

public VirtualListViewSectionTemplateSelector SectionHeaderTemplateSelector
public VirtualListViewSectionTemplateSelector? SectionHeaderTemplateSelector
{
get => (VirtualListViewSectionTemplateSelector)GetValue(SectionHeaderTemplateSelectorProperty);
set => SetValue(SectionHeaderTemplateSelectorProperty, value);
Expand All @@ -117,7 +118,7 @@



public DataTemplate SectionFooterTemplate
public DataTemplate? SectionFooterTemplate
{
get => (DataTemplate)GetValue(SectionFooterTemplateProperty);
set => SetValue(SectionFooterTemplateProperty, value);
Expand All @@ -126,7 +127,7 @@
public static readonly BindableProperty SectionFooterTemplateProperty =
BindableProperty.Create(nameof(SectionFooterTemplate), typeof(DataTemplate), typeof(VirtualListView), default);

public VirtualListViewSectionTemplateSelector SectionFooterTemplateSelector
public VirtualListViewSectionTemplateSelector? SectionFooterTemplateSelector
{
get => (VirtualListViewSectionTemplateSelector)GetValue(SectionFooterTemplateSelectorProperty);
set => SetValue(SectionFooterTemplateSelectorProperty, value);
Expand All @@ -145,9 +146,9 @@
public static readonly BindableProperty SelectionModeProperty =
BindableProperty.Create(nameof(SelectionMode), typeof(Maui.SelectionMode), typeof(VirtualListView), Maui.SelectionMode.None);

public event EventHandler<SelectedItemsChangedEventArgs> OnSelectedItemsChanged;

Check warning on line 149 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable event 'OnSelectedItemsChanged' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 149 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable event 'OnSelectedItemsChanged' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 149 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable event 'OnSelectedItemsChanged' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 149 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable event 'OnSelectedItemsChanged' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

public event EventHandler<RefreshEventArgs> OnRefresh;

Check warning on line 151 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable event 'OnRefresh' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 151 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable event 'OnRefresh' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 151 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable event 'OnRefresh' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 151 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable event 'OnRefresh' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

void IVirtualListView.Refresh(Action completionCallback)
{
Expand All @@ -159,7 +160,7 @@
OnRefresh?.Invoke(this, new RefreshEventArgs(completionCallback));
}

public ICommand RefreshCommand
public ICommand? RefreshCommand
{
get => (ICommand)GetValue(RefreshCommandProperty);
set => SetValue(RefreshCommandProperty, value);
Expand All @@ -168,9 +169,9 @@
public static readonly BindableProperty RefreshCommandProperty =
BindableProperty.Create(nameof(RefreshCommand), typeof(ICommand), typeof(VirtualListView), default);

public Color RefreshAccentColor
public Color? RefreshAccentColor
{
get => (Color)GetValue(RefreshAccentColorProperty);
get => (Color?)GetValue(RefreshAccentColorProperty);
set => SetValue(RefreshAccentColorProperty, value);
}

Expand All @@ -196,14 +197,14 @@
BindableProperty.Create(nameof(Orientation), typeof(ListOrientation), typeof(VirtualListView), ListOrientation.Vertical);


public View EmptyView
public IView? EmptyView
{
get => (View)GetValue(EmptyViewProperty);
get => (IView)GetValue(EmptyViewProperty);
set => SetValue(EmptyViewProperty, value);
}

public static readonly BindableProperty EmptyViewProperty =
BindableProperty.Create(nameof(EmptyView), typeof(View), typeof(VirtualListView), null,
BindableProperty.Create(nameof(EmptyView), typeof(IView), typeof(VirtualListView), null,
propertyChanged: (bobj, oldValue, newValue) =>
{
if (bobj is VirtualListView virtualListView)
Expand All @@ -216,15 +217,15 @@
}
});

IView IVirtualListView.EmptyView => EmptyView;
IView? IVirtualListView.EmptyView => EmptyView;


public IVirtualListViewSelector ViewSelector => this;

public IView Header => GlobalHeader;
public IView Footer => GlobalFooter;
public IView? Header => GlobalHeader;
public IView? Footer => GlobalFooter;

public event EventHandler<ScrolledEventArgs> OnScrolled;

Check warning on line 228 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable event 'OnScrolled' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 228 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable event 'OnScrolled' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 228 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable event 'OnScrolled' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 228 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable event 'OnScrolled' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

public void Scrolled(double x, double y)
{
Expand All @@ -239,7 +240,7 @@
public static readonly BindableProperty ScrolledCommandProperty =
BindableProperty.Create(nameof(ScrolledCommand), typeof(ICommand), typeof(VirtualListView), default);

public ICommand ScrolledCommand
public ICommand? ScrolledCommand
{
get => (ICommand)GetValue(ScrolledCommandProperty);
set => SetValue(ScrolledCommandProperty, value);
Expand All @@ -256,7 +257,7 @@
vlv.RaiseSelectedItemsChanged(oldSelection.ToArray(), newSelection.ToArray());
}
});
public IList<ItemPosition> SelectedItems
public IList<ItemPosition>? SelectedItems
{
get => (IList<ItemPosition>)GetValue(SelectedItemsProperty);
set => SetValue(SelectedItemsProperty, value ?? Array.Empty<ItemPosition>());
Expand Down Expand Up @@ -293,7 +294,7 @@
}
else if (SelectionMode == Maui.SelectionMode.Multiple)
{
var current = SelectedItems.ToList();

Check warning on line 297 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Possible null reference argument for parameter 'source' in 'List<ItemPosition> Enumerable.ToList<ItemPosition>(IEnumerable<ItemPosition> source)'.

Check warning on line 297 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Possible null reference argument for parameter 'source' in 'List<ItemPosition> Enumerable.ToList<ItemPosition>(IEnumerable<ItemPosition> source)'.

Check warning on line 297 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Possible null reference argument for parameter 'source' in 'List<ItemPosition> Enumerable.ToList<ItemPosition>(IEnumerable<ItemPosition> source)'.

Check warning on line 297 in VirtualListView/Controls/VirtualListView.cs

View workflow job for this annotation

GitHub Actions / Build

Possible null reference argument for parameter 'source' in 'List<ItemPosition> Enumerable.ToList<ItemPosition>(IEnumerable<ItemPosition> source)'.
if (current.Contains(itemPosition))
{
current.Remove(itemPosition);
Expand All @@ -314,9 +315,9 @@
else if (SelectionMode == Maui.SelectionMode.Multiple)
{
var current = SelectedItems;
if (!current.Contains(itemPosition))
if (current is null || !current.Contains(itemPosition))
{
SelectedItems = current.Append(itemPosition).ToArray();
SelectedItems = (current ?? []).Append(itemPosition).ToArray();
}
}
}
Expand All @@ -338,7 +339,7 @@
public bool SectionHasFooter(int sectionIndex)
=> SectionFooterTemplateSelector != null || SectionFooterTemplate != null;

public IView CreateView(PositionInfo position, object data)
public IView? CreateView(PositionInfo position, object? data)
=> position.Kind switch
{
PositionKind.Item =>
Expand All @@ -357,7 +358,7 @@
_ => default
};

public void RecycleView(PositionInfo position, object data, IView view)
public void RecycleView(PositionInfo position, object? data, IView view)
{
if (view is View controlsView)
{
Expand All @@ -370,7 +371,7 @@
}
}

public string GetReuseId(PositionInfo position, object data)
public string GetReuseId(PositionInfo position, object? data)
=> position.Kind switch
{
PositionKind.Item =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
namespace Microsoft.Maui.Controls;
#nullable enable

namespace Microsoft.Maui.Controls;

public abstract class VirtualListViewItemTemplateSelector
{
public abstract DataTemplate SelectTemplate(object item, int sectionIndex, int itemIndex);
public abstract DataTemplate SelectTemplate(object? item, int sectionIndex, int itemIndex);
}

public abstract class VirtualListViewSectionTemplateSelector
{
public abstract DataTemplate SelectTemplate(object section, int sectionIndex);
public abstract DataTemplate SelectTemplate(object? section, int sectionIndex);
}
9 changes: 5 additions & 4 deletions VirtualListView/IVirtualListViewSelector.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
namespace Microsoft.Maui;
#nullable enable
namespace Microsoft.Maui;

public interface IVirtualListViewSelector
{
bool SectionHasHeader(int sectionIndex);
bool SectionHasFooter(int sectionIndex);

IView CreateView(PositionInfo position, object data);
void RecycleView(PositionInfo position, object data, IView view);
string GetReuseId(PositionInfo position, object data);
IView? CreateView(PositionInfo position, object? data);
void RecycleView(PositionInfo position, object? data, IView view);
string GetReuseId(PositionInfo position, object? data);

void ViewDetached(PositionInfo position, IView view)
{ }
Expand Down
5 changes: 3 additions & 2 deletions VirtualListView/VirtualListViewExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Microsoft.Maui.Adapters;
#nullable enable
using Microsoft.Maui.Adapters;

namespace Microsoft.Maui;

internal static class VirtualListViewExtensions
{
public static object DataFor(this IVirtualListViewAdapter vlva, PositionKind kind, int sectionIndex, int itemIndex)
public static object? DataFor(this IVirtualListViewAdapter vlva, PositionKind kind, int sectionIndex, int itemIndex)
=> kind switch
{
PositionKind.Item => vlva.GetItem(sectionIndex, itemIndex),
Expand Down
Loading