Add missing null check on ItemsSource when IsGrouped is true; fixes #8269 (#8273)

This commit is contained in:
E.Z. Hart 2019-11-04 14:21:59 -07:00 коммит произвёл GitHub
Родитель 212ff1d4ca
Коммит dfc32f9205
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 53 добавлений и 1 удалений

Просмотреть файл

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.CollectionView)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 8269, "[Bug] CollectionView exception when IsGrouped=true and null ItemSource",
PlatformAffected.Android)]
public class Issue8269 : TestContentPage
{
const string Success = "Success";
protected override void Init()
{
var layout = new StackLayout();
var instructions = new Label { Text = "If this page has not crashed, the test is sucessful." };
var success = new Label { AutomationId = Success, Text = Success };
var cv = new CollectionView { ItemsSource = null, IsGrouped = true };
layout.Children.Add(success);
layout.Children.Add(instructions);
layout.Children.Add(cv);
Content = layout;
}
#if UITEST
[Test]
public void IsGroupedWithNullItemsSourceShouldNotCrash()
{
RunningApp.WaitForElement(Success);
}
#endif
}
}

Просмотреть файл

@ -96,6 +96,7 @@
<DependentUpon>Issue7803.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue8167.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8269.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RefreshViewTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue7338.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ScrollToGroup.cs" />

Просмотреть файл

@ -37,7 +37,9 @@ namespace Xamarin.Forms.Platform.Android
public static IGroupableItemsViewSource Create(GroupableItemsView itemsView, RecyclerView.Adapter adapter)
{
if (itemsView.IsGrouped)
var source = itemsView.ItemsSource;
if (itemsView.IsGrouped && source != null)
{
return new ObservableGroupedSource(itemsView, new AdapterNotifier(adapter));
}