Children =
{
descriptionLabel,
+ GalleryBuilder.NavButton("EmptyView (null ItemsSource)", () =>
+ new EmptyViewNullGallery(), Navigation),
GalleryBuilder.NavButton("EmptyView (String)", () =>
new EmptyViewStringGallery(), Navigation),
GalleryBuilder.NavButton("EmptyView (View)", () =>
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
+<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+ x:Class="Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.EmptyViewGalleries.EmptyViewNullGallery">
+ <ContentPage.Content>
+ <CollectionView x:Name="CollectionView">
+ <CollectionView.ItemsLayout>
+ <GridItemsLayout Span="3" Orientation="Vertical"></GridItemsLayout>
+ </CollectionView.ItemsLayout>
+ <CollectionView.EmptyView>
+ Nothing to display.
+ </CollectionView.EmptyView>
+ </CollectionView>
+ </ContentPage.Content>
+</ContentPage>
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using Xamarin.Forms;
+using Xamarin.Forms.Xaml;
+
+namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.EmptyViewGalleries
+{
+ [XamlCompilation(XamlCompilationOptions.Compile)]
+ public partial class EmptyViewNullGallery : ContentPage
+ {
+ public EmptyViewNullGallery()
+ {
+ InitializeComponent();
+ }
+ }
+}
\ No newline at end of file
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="Xam.Plugin.DeviceInfo" Version="3.0.2" />
</ItemGroup>
-
+
<Target Name="CreateControllGalleryConfig" BeforeTargets="Build">
<CreateItem Include="blank.config">
<Output TaskParameter="Include" ItemName="ConfigFile" />
--- /dev/null
+using System;
+
+namespace Xamarin.Forms.Platform.Android
+{
+ internal class EmptySource : IItemsViewSource
+ {
+ public int Count => 0;
+
+ public object this[int index] => throw new IndexOutOfRangeException("IItemsViewSource is empty");
+ }
+}
\ No newline at end of file
{
public static IItemsViewSource Create(IEnumerable itemsSource, RecyclerView.Adapter adapter)
{
+ if (itemsSource == null)
+ {
+ return new EmptySource();
+ }
+
switch (itemsSource)
{
case IList _ when itemsSource is INotifyCollectionChanged:
<Compile Include="BorderBackgroundManager.cs" />
<Compile Include="CollectionView\CarouselViewRenderer.cs" />
<Compile Include="CollectionView\DataChangeObserver.cs" />
+ <Compile Include="CollectionView\EmptySource.cs" />
<Compile Include="CollectionView\EmptyViewAdapter.cs" />
<Compile Include="CollectionView\ItemsViewAdapter.cs" />
<Compile Include="CollectionView\EdgeSnapHelper.cs" />
UICollectionViewCell GetPrototype()
{
+ if (_itemsSource.Count == 0)
+ {
+ return null;
+ }
+
// TODO hartez assuming this works, we'll need to evaluate using this nsindexpath (what about groups?)
- // TODO hartez Also, what about situations where there is no data which matches the path?
var indexPath = NSIndexPath.Create(0, 0);
return GetCell(CollectionView, indexPath);
}
}
}
- // TODO hartez 2018/05/30 08:58:42 This follows the same basic scheme as RecyclerView.Adapter; you should be able to reuse the same wrapper class for the IEnumerable
//// TODO hartez 2018/05/30 09:05:38 Think about whether this Controller and/or the new Adapter should be internal or public
public class CollectionViewRenderer : ViewRenderer<CollectionView, UIView>
{
--- /dev/null
+using System;
+
+namespace Xamarin.Forms.Platform.iOS
+{
+ internal class EmptySource : IItemsViewSource
+ {
+ public int Count => 0;
+
+ public object this[int index] => throw new IndexOutOfRangeException("IItemsViewSource is empty");
+ }
+}
\ No newline at end of file
{
public static IItemsViewSource Create(IEnumerable itemsSource, UICollectionView collectionView)
{
+ if (itemsSource == null)
+ {
+ return new EmptySource();
+ }
+
switch (itemsSource)
{
case IList _ when itemsSource is INotifyCollectionChanged:
<Compile Include="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\CellExtensions.cs" />
<Compile Include="CADisplayLinkTicker.cs" />
+ <Compile Include="CollectionView\EmptySource.cs" />
<Compile Include="CollectionView\IItemsViewSource.cs" />
<Compile Include="CollectionView\ItemsSourceFactory.cs" />
<Compile Include="CollectionView\ItemsViewCell.cs" />