|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.ComponentModel; |
| 3 | +using System.Linq; |
| 4 | +using System.Runtime.CompilerServices; |
| 5 | +using System.Windows.Input; |
| 6 | +using NUnit.Framework; |
| 7 | +using Xamarin.Forms.CustomAttributes; |
| 8 | +using Xamarin.Forms.Markup; |
| 9 | + |
| 10 | +namespace Xamarin.Forms.Controls.Issues |
| 11 | +{ |
| 12 | + [Issue(IssueTracker.None, 11311, "[Regression] CollectionView NSRangeException", PlatformAffected.iOS)] |
| 13 | + public class Issue11311 : TestTabbedPage |
| 14 | + { |
| 15 | + const string Success = "Success"; |
| 16 | + |
| 17 | + protected override void Init() |
| 18 | + { |
| 19 | + Device.SetFlags(new[] { "Markup_Experimental" }); |
| 20 | + |
| 21 | + Children.Add(FirstPage()); |
| 22 | + Children.Add(CollectionViewPage()); |
| 23 | + } |
| 24 | + |
| 25 | + ContentPage FirstPage() |
| 26 | + { |
| 27 | + var firstPage = new ContentPage |
| 28 | + { |
| 29 | + Title = "The first page", |
| 30 | + Content = new Label { Text = Success } |
| 31 | + }; |
| 32 | + |
| 33 | + firstPage.Appearing += (sender, args) => { |
| 34 | + if (firstPage.Parent is TabbedPage tabbedPage |
| 35 | + && tabbedPage.Children[1] is ContentPage collectionViewPage |
| 36 | + && collectionViewPage.Content is RefreshView refreshView) |
| 37 | + { |
| 38 | + refreshView.IsRefreshing = true; |
| 39 | + } |
| 40 | + }; |
| 41 | + |
| 42 | + return firstPage; |
| 43 | + } |
| 44 | + |
| 45 | + ContentPage CollectionViewPage() |
| 46 | + { |
| 47 | + BindingContext = new _11311ViewModel(); |
| 48 | + |
| 49 | + var refreshView = new RefreshView |
| 50 | + { |
| 51 | + Content = new CollectionView |
| 52 | + { |
| 53 | + Footer = new BoxView { BackgroundColor = Color.Red, HeightRequest = 53 } |
| 54 | + }.Bind(ItemsView.ItemsSourceProperty, nameof(_11311ViewModel.ScoreCollectionList)) |
| 55 | + |
| 56 | + }.Bind(RefreshView.CommandProperty, nameof(_11311ViewModel.PopulateCollectionCommand)) |
| 57 | + .Bind(RefreshView.IsRefreshingProperty, nameof(_11311ViewModel.IsRefreshing)); |
| 58 | + |
| 59 | + var page = new ContentPage |
| 60 | + { |
| 61 | + Title = "CollectionView Page", |
| 62 | + Content = refreshView |
| 63 | + }; |
| 64 | + |
| 65 | + return page; |
| 66 | + } |
| 67 | + |
| 68 | + class _11311ViewModel : INotifyPropertyChanged |
| 69 | + { |
| 70 | + bool _isRefreshing; |
| 71 | + IEnumerable<int> _scoreCollectionList; |
| 72 | + |
| 73 | + public _11311ViewModel() |
| 74 | + { |
| 75 | + PopulateCollectionCommand = new Command(ExecuteRefreshCommand); |
| 76 | + _scoreCollectionList = Enumerable.Empty<int>(); |
| 77 | + } |
| 78 | + |
| 79 | + public event PropertyChangedEventHandler PropertyChanged; |
| 80 | + |
| 81 | + public ICommand PopulateCollectionCommand { get; } |
| 82 | + |
| 83 | + public IEnumerable<int> ScoreCollectionList |
| 84 | + { |
| 85 | + get => _scoreCollectionList; |
| 86 | + set |
| 87 | + { |
| 88 | + _scoreCollectionList = value; |
| 89 | + OnPropertyChanged(); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + public bool IsRefreshing |
| 94 | + { |
| 95 | + get => _isRefreshing; |
| 96 | + set |
| 97 | + { |
| 98 | + if (IsRefreshing != value) |
| 99 | + { |
| 100 | + _isRefreshing = value; |
| 101 | + OnPropertyChanged(); |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + void ExecuteRefreshCommand() |
| 107 | + { |
| 108 | + ScoreCollectionList = Enumerable.Range(0, 100); |
| 109 | + IsRefreshing = false; |
| 110 | + } |
| 111 | + |
| 112 | + void OnPropertyChanged([CallerMemberName] string propertyName = "") => |
| 113 | + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
| 114 | + } |
| 115 | + |
| 116 | +#if UITEST |
| 117 | + [Test] |
| 118 | + public void CollectionViewWithFooterShouldNotCrashOnDisplay() |
| 119 | + { |
| 120 | + // If this hasn't already crashed, the test is passing |
| 121 | + RunningApp.WaitForElement(Success); |
| 122 | + } |
| 123 | +#endif |
| 124 | + } |
| 125 | +} |
0 commit comments