summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla55912.cs
blob: 0a2ee05b74111612f910c3550398a9f2d65f6845 (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
99
100
using System;
using System.Diagnostics;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;

#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
	[Category(UITestCategories.Gestures)]
#endif

	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.Bugzilla, 55912, "Tap event not always propagated to containing Grid/StackLayout",
		PlatformAffected.Android)]
	public class Bugzilla55912 : TestContentPage
	{
		const string Success = "Success";
		const string GridLabelId = "GridLabel";
		const string StackLabelId = "StackLabel";

		protected override void Init()
		{
			var layout = new Grid();

			layout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star });
			layout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star });
			layout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star });

			var testGrid = new Grid { BackgroundColor = Color.Red, AutomationId = "testgrid"};
			var gridLabel = new Label
			{
				AutomationId = GridLabelId,
				Text = "This is a Grid with a TapGesture",
				FontSize = 24,
				BackgroundColor = Color.Green
			};
			Grid.SetRow(testGrid, 1);
			testGrid.Children.Add(gridLabel);

			var testStack = new StackLayout { BackgroundColor = Color.Default, AutomationId = "teststack"};
			var stackLabel = new Label
			{
				AutomationId = StackLabelId,
				Text = "This StackLayout also has a TapGesture",
				FontSize = 24,
				BackgroundColor = Color.Green
			};
			Grid.SetRow(testStack, 2);
			testStack.Children.Add(stackLabel);

			layout.Children.Add(testGrid);
			layout.Children.Add(testStack);

			Content = layout;

			testGrid.GestureRecognizers.Add(new TapGestureRecognizer
			{
				NumberOfTapsRequired = 1,
				Command = new Command(() =>
				{
					Debug.WriteLine($"***** TestGrid Tapped: {DateTime.Now} *****");
					layout.Children.Add(new Label { AutomationId = Success, Text = Success });
				})
			});

			testStack.GestureRecognizers.Add(new TapGestureRecognizer
			{
				NumberOfTapsRequired = 1,
				Command = new Command(() =>
				{
					Debug.WriteLine($"***** TestStack Tapped: {DateTime.Now} *****");
					layout.Children.Add(new Label { AutomationId = Success, Text = Success });
				})
			});
		}

#if UITEST
		[Test]
		public void GestureBubblingInStackLayout()
		{
			RunningApp.WaitForElement(StackLabelId);
			RunningApp.Tap(StackLabelId);
			RunningApp.WaitForElement(Success);
		}

		[Test]
		public void GestureBubblingInGrid()
		{
			RunningApp.WaitForElement(GridLabelId);
			RunningApp.Tap(GridLabelId);
			RunningApp.WaitForElement(Success);
		}
#endif
	}
}