summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32691.cs
blob: 9b6250d46662bc850909f7e23c1f211fec2e21dc (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
58
59
60
61
62
using System;
using Xamarin.Forms.CustomAttributes;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls
{
	public interface ICacheService
	{
		void ClearImageCache ();
	}

	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 32691, "Clearing an image by setting Image.Source to null, while Image.IsLoading is true, doesn't work.")]
	public class Bugzilla32691 : TestContentPage
	{
		const string KSetImageSource = "SET IMAGE SOURCE";
		const string KClearImageSource = "CLEAR IMAGE SOURCE";

		protected override void Init ()
		{
#pragma warning disable 618
			var label = new Label () { XAlign = TextAlignment.Center };
#pragma warning restore 618
			var image = new Image ();

			image.PropertyChanged += (sender, e) => {
				if (e.PropertyName == "IsLoading")
					label.Text = image.IsLoading ? "Loading" : "Done";
			};

			var btnSetOrClear = new Button () { Text = KSetImageSource, AutomationId = "btnLoad" };

			btnSetOrClear.Clicked += delegate {
				if (btnSetOrClear.Text == KSetImageSource) {
					ClearImageCache ();
					image.Source =
						"http://www.public-domain-image.com/free-images/miscellaneous/big-high-border-fence.jpg";
					btnSetOrClear.Text = KClearImageSource;
				} else {
					image.Source = null;
					btnSetOrClear.Text = KSetImageSource;
				}
			};

			Content = new StackLayout {
				Orientation = StackOrientation.Vertical, 
				Padding = new Thickness (10),
				Children = { btnSetOrClear, image, label }
			};
		}

		void ClearImageCache ()
		{
			var cacheService = DependencyService.Get<ICacheService> ();
			cacheService?.ClearImageCache ();
		}
	}
}