summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla26171.cs
blob: af42b2ab8103a0ad9ec2d060945df1acfd0fa1b7 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;

using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Maps;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 26171, "Xamarin.Forms.Maps is not updating VisibleRegion property when layout is changed")]
	public class Bugzilla26171 : TestContentPage // or TestMasterDetailPage, etc ...
	{
		protected override void Init ()
		{
			var map = MakeMap ();

			var label = new Label  { AutomationId = "lblValue" };

			var buttonLayout = new Button { Text = "Change layout" };
			buttonLayout.Clicked += async (a, e) => {
				map.VerticalOptions = LayoutOptions.Start;
				await Print (map,label);
			};

			var stack = new StackLayout {
				Spacing = 0,
				Padding = new Thickness (30, 0)
			};

			stack.Children.Add (label);
			stack.Children.Add (map);
			stack.Children.Add (buttonLayout);

			Content = new ScrollView { Content = stack };

			Appearing += async (sender, e) => await Print (map, label);

		}

		static async Task Print (Map map, Label label)
		{	
			await Task.Delay(500);
			if (map.VisibleRegion != null) {
				label.Text = map.VisibleRegion.Radius.Kilometers.ToString ();
			}
		}

		public static Map MakeMap ()
		{
			Pin colosseum = null;
			Pin pantheon = null;
			Pin chapel = null;

			var map = new Map {
				IsShowingUser = false,
				VerticalOptions = LayoutOptions.FillAndExpand,
				HeightRequest = 100,
				Pins = {
					(colosseum = new Pin {
						Type = PinType.Place,
						Position = new Position (41.890202, 12.492049),
						Label = "Colosseum",
						Address = "Piazza del Colosseo, 00184 Rome, Province of Rome, Italy"
					}),
					(pantheon = new Pin {
						Type = PinType.Place,
						Position = new Position (41.898652, 12.476831),
						Label = "Pantheon",
						Address = "Piazza della Rotunda, 00186 Rome, Province of Rome, Italy"
					}),
					(chapel = new Pin {
						Type = PinType.Place,
						Position = new Position (41.903209, 12.454545),
						Label = "Sistine Chapel",
						Address = "Piazza della Rotunda, 00186 Rome, Province of Rome, Italy"
					})
				}
			};

			return map;
		}

#if UITEST
		[Test]
		public void Bugzilla26171Test ()
		{
			RunningApp.WaitForElement (q => q.Marked ("lblValue"));
			var value = RunningApp.Query (q => q.Marked ("lblValue")) [0].Text;
			RunningApp.Screenshot ("I see the Label");
		}
#endif
	}
}