summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla34007.cs
blob: 4311f7a99a61917ce730191f17dfad213650c879 (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
using System;
using System.Xml.Linq;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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

#endif

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 34007, "Z order drawing of children views are different on Android, iOS, Win", PlatformAffected.Android | PlatformAffected.iOS)]
	public class Bugzilla34007 : TestContentPage
	{
		protected override void Init ()
		{
			var grid = new Grid ();

			var button0 = new Button {
				Text = "Button 0",
				HorizontalOptions = LayoutOptions.Fill,
				VerticalOptions = LayoutOptions.Fill
			};

			var button1 = new Button {
				Text = "Button 1",
				HorizontalOptions = LayoutOptions.Fill,
				VerticalOptions = LayoutOptions.Fill
			};

			var lastButtonTappedLabel = new Label ();

			Action reorder = () => {
				// Get the last item in the grid
				var item = grid.Children[1];

				// Remove it
				grid.Children.RemoveAt(1);

				// And put it back as the 0th item
				grid.Children.Insert(0, item);
			};

			button0.Clicked += (sender, args) => {
				lastButtonTappedLabel.Text = "Button 0 was tapped last";
			};

			button1.Clicked += (sender, args) => {
				lastButtonTappedLabel.Text = "Button 1 was tapped last";

				reorder ();
			};

			grid.Children.Add(button0, 0, 0);
			grid.Children.Add(button1, 0, 0);

			Content = new StackLayout {
				Children = { grid, lastButtonTappedLabel }
			};
		}

#if UITEST
		[Test]
		[UiTest (typeof (Grid))]
		public void Issue34007TestFirstElementHasLowestZOrder ()
		{
			var buttonLocations = RunningApp.WaitForElement (q => q.Marked ("Button 0"));

			var x = buttonLocations [0].Rect.CenterX;
			var y = buttonLocations [0].Rect.CenterY;

			// Button 1 was the last item added to the grid; it should be tappable
			RunningApp.Tap (q => q.Button ("Button 1"));

			// The label should indicate that Button 1 was the last button tapped
			RunningApp.WaitForElement(q => q.Marked("Button 1 was tapped last"));

			RunningApp.Screenshot("Buttons Reordered");

			// Tapping Button1 1 reordered the buttons in the grid; Button 0 should
			// now be on top. Tapping at the Button 1 location should actually tap
			// Button 0, and the label should indicate that
			RunningApp.TapCoordinates(x, y);
			RunningApp.WaitForElement(q => q.Marked("Button 0 was tapped last"));

			RunningApp.Screenshot("Button 0 Tapped");
		}
#endif
	}
}