summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla33561.cs
blob: ec55d370098012eec764c330bb663bc2e1c0c31b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;

using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Linq;
using System.Threading.Tasks;

namespace Xamarin.Forms.Controls
{
	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.Bugzilla, 33561, "ListView Pull-to-Refresh ActivityIndicator animation stuck when navigating away and then back again")]
	public class Bugzilla33561 : TestTabbedPage
	{
		public class ListPage : ContentPage
		{
			ListView _listView;
			bool _isRefreshing;

			public ListPage()
			{
				var template = new DataTemplate(typeof(TextCell));
				template.SetBinding(TextCell.TextProperty, ".");

				_listView = new ListView()
				{
					IsPullToRefreshEnabled = true,
					ItemsSource = Enumerable.Range(0, 10).Select(no => $"FAIL {no}"),
					ItemTemplate = template,
					IsRefreshing = true
				};

				_listView.Refreshing += async (object sender, EventArgs e) =>
				{
					if (_isRefreshing)
						return;

					_isRefreshing = true;
					await Task.Delay(10000);
					_listView.EndRefresh();
					_listView.ItemsSource = Enumerable.Range(0, 10).Select(no => $"SUCCESS {no}");
					_isRefreshing = false;
				};

				Content = _listView;

				Device.StartTimer(TimeSpan.FromSeconds(5), () => { _listView.IsRefreshing = false; return false; });
			}
		}

		protected override void Init()
		{
			Children.Add(new NavigationPage(new ListPage()) { Title = "page 1" });
			Children.Add(new ContentPage() { Title = "page 2" });
			Children.Add(new ContentPage() { Title = "page 3" });
		}
	}
}