--- /dev/null
+using System;
+using System.Collections.Generic;
+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, 7338, "[Bug] CollectionView crash if source is empty in XF 4.2.0.709249",
+ PlatformAffected.iOS)]
+ class Issue7338 : TestNavigationPage
+ {
+ const string Success = "success";
+
+ protected override void Init()
+ {
+ FlagTestHelpers.SetCollectionViewTestFlag();
+ PushAsync(CreateRoot());
+ }
+
+ Page CreateRoot()
+ {
+ var page = new ContentPage() { Title = "Issue7338" };
+
+ var instructions = new Label { AutomationId = Success, Text = "If you can see this label, the test has passed." };
+
+ var layout = new StackLayout();
+
+ var cv = new CollectionView
+ {
+ ItemsLayout = new GridItemsLayout(orientation: ItemsLayoutOrientation.Horizontal),
+ ItemTemplate = new DataTemplate(() =>
+ {
+ return Template();
+ })
+ };
+
+ layout.Children.Add(instructions);
+ layout.Children.Add(cv);
+
+ page.Content = layout;
+
+ return page;
+ }
+
+ View Template()
+ {
+ var label1 = new Label { Text = "Text", HeightRequest = 100 };
+ return label1;
+ }
+
+#if UITEST
+ [Test]
+ public void EmptyHorizontalCollectionShouldNotCrash()
+ {
+ // If the instructions are visible at all, then this has succeeded
+ RunningApp.WaitForElement(Success);
+ }
+#endif
+ }
+}
<Compile Include="$(MSBuildThisFileDirectory)Issue7049.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue7061.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue7111.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Issue7338.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ScrollToGroup.cs" />
<Compile Include="$(MSBuildThisFileDirectory)NestedCollectionViews.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ShellFlyoutBehavior.cs" />
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
-</Project>
+</Project>
\ No newline at end of file