Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
[Issue(IssueTracker.Github, 13203, "[Bug] [iOS] CollectionView does not bind to items if `IsVisible=False`", PlatformAffected.iOS)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.CollectionView)]
#endif
public class Issue13203 : TestContentPage
{
const string Success = "Success";

protected override void Init()
{
var cv = new CollectionView
{
IsVisible = false,

ItemTemplate = new DataTemplate(() =>
{
var label = new Label();
label.SetBinding(Label.TextProperty, new Binding(nameof(Item.Text)));
return label;
})
};

var source = new List<Item> { new Item { Text = Success } };
cv.ItemsSource = source;
Content = cv;

Appearing += (sender, args) => { cv.IsVisible = true; };
}

class Item
{
public string Text { get; set; }
}

#if UITEST
[Test]
public void SettingGroupedCollectionViewItemSourceNullShouldNotCrash()
{
RunningApp.WaitForElement(Success);
}
#endif
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue12246.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8613.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13203.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue9137.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8691.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue7606.cs" />
Expand Down
16 changes: 16 additions & 0 deletions Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using CoreGraphics;
using Foundation;
using UIKit;
Expand Down Expand Up @@ -27,6 +28,8 @@ protected ItemsViewController(TItemsView itemsView, ItemsViewLayout layout) : ba
{
ItemsView = itemsView;
ItemsViewLayout = layout;

ItemsView.PropertyChanged += ItemsViewPropertyChanged;
}

public void UpdateLayout(ItemsViewLayout newLayout)
Expand Down Expand Up @@ -56,6 +59,8 @@ protected override void Dispose(bool disposing)

if (disposing)
{
ItemsView.PropertyChanged -= ItemsViewPropertyChanged;

ItemsSource?.Dispose();
CollectionView.Delegate = null;
Delegator?.Dispose();
Expand Down Expand Up @@ -457,5 +462,16 @@ public TemplatedCell CreateMeasurementCell(NSIndexPath indexPath)

return templatedCell;
}

void ItemsViewPropertyChanged(object sender, PropertyChangedEventArgs changedProperty)
{
if (changedProperty.Is(VisualElement.IsVisibleProperty))
{
if (ItemsView.IsVisible)
{
Layout.InvalidateLayout();
}
}
}
}
}