summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41415.cs
blob: 1d098985815bd8b3ff21d545f41e360c93bb7462 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.Bugzilla, 41415, "ScrollX and ScrollY values are not consistent with iOS", PlatformAffected.Android)]
	public class Bugzilla41415 : TestContentPage
	{
		const string ButtonText = "Click Me";
		float _x, _y;
		bool _didXChange, _didYChange;

		protected override void Init()
		{
			var grid = new Grid
			{
				BackgroundColor = Color.Yellow,
				WidthRequest = 1000,
				HeightRequest = 1000,
				Children =
				{
					new BoxView
					{
						WidthRequest =  200,
						HeightRequest = 200,
						BackgroundColor = Color.Red,
						HorizontalOptions = LayoutOptions.Center,
						VerticalOptions = LayoutOptions.Center
					}
				}
			};

			var labelx = new Label();
			var labely = new Label();
			var labelz = new Label();
			var labela = new Label();

			var scrollView = new ScrollView
			{
				Orientation = ScrollOrientation.Both,
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.FillAndExpand
			};

			scrollView.Content = grid;
			scrollView.Scrolled += (sender, args) =>
			{
				labelx.Text = $"x: {(int)Math.Round(args.ScrollX)}";
				labely.Text = $"y: {(int)Math.Round(args.ScrollY)}";

				// first and second taps
				if (_x == 0)
				{
					if (args.ScrollX != 0 && args.ScrollX != 100)
						_didXChange = true;
					if (args.ScrollY != 0 && args.ScrollY != 100)
						_didYChange = true;
				}
				else if (_x == 100)
				{
					if (args.ScrollX != _x && args.ScrollX != _x + 100)
						_didXChange = true;
					if (args.ScrollY != 100)
						_didYChange = true;
				}

				labelz.Text = "z: " + _didXChange.ToString();
				labela.Text = "a: " + _didYChange.ToString();
			};

			var button = new Button { Text = ButtonText };
			button.Clicked += async (sender, e) =>
			{
				// reset
				labelx.Text = null;
				labely.Text = null;
				labelz.Text = null;
				labela.Text = null;
				_didXChange = false;
				_didYChange = false;

				await scrollView.ScrollToAsync(_x + 100, _y + 100, true);
				_x = 100;
			};

			Content = new StackLayout { Children = { button, labelx, labely, labelz, labela, scrollView } };
		}

#if UITEST && __ANDROID__

		[Test]
		public void Bugzilla41415Test()
		{
			RunningApp.WaitForElement(q => q.Marked(ButtonText));
			RunningApp.Tap(q => q.Marked(ButtonText));
			RunningApp.WaitForElement(q => q.Marked("x: 100"));
			RunningApp.WaitForElement(q => q.Marked("y: 100"));
			RunningApp.WaitForElement(q => q.Marked("z: True"));
			RunningApp.WaitForElement(q => q.Marked("a: True"));
			RunningApp.Tap(q => q.Marked(ButtonText));
			RunningApp.WaitForElement(q => q.Marked("x: 200"));
			RunningApp.WaitForElement(q => q.Marked("y: 100"));
			RunningApp.WaitForElement(q => q.Marked("z: True"));
			RunningApp.WaitForElement(q => q.Marked("a: False"));
		}

#endif
	}
}