summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/StackLayoutIssue.cs
blob: e2210eab9483e1737c11a0769ee559f20935bfc7 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System.Diagnostics;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.None, 0, "StackLayout issue", PlatformAffected.All, NavigationBehavior.PushModalAsync)]
	public class StackLayoutIssue : TestContentPage
	{
		protected override void Init ()
		{
			var logo = new Image {
				Source = "cover1.jpg",
				WidthRequest = 20,
				HeightRequest = 20,
				VerticalOptions = LayoutOptions.FillAndExpand,
			};

			var winPrizeLabel = new Label {
				Text = "Win a Xamarin Prize",
#pragma warning disable 618
				XAlign = TextAlignment.Center,
#pragma warning restore 618

#pragma warning disable 618
				YAlign = TextAlignment.Center,
#pragma warning restore 618
				VerticalOptions = LayoutOptions.FillAndExpand
			};

#pragma warning disable 618
			Device.OnPlatform (iOS: () => winPrizeLabel.Font = Font.OfSize ("HelveticaNeue-UltraLight", NamedSize.Large));
#pragma warning restore 618

			StackLayout form = MakeForm ();

			var spinButton = new Button {
				Text = "Spin"
			};

			var mainLayout = new StackLayout {
				Children = {
					logo,
					winPrizeLabel,
					form,
					spinButton
				}
			};

			Content = mainLayout;
			Padding = new Thickness (50);
		}

#if UITEST
		[Test]
		public void StackLayoutIssueTestsAllElementsPresent ()
		{
			// TODO: Fix ME

			//var images = App.Query (PlatformQueries.Images);
			//Assert.AreEqual (2, images.Length);

			//App.WaitForElement (q => q.Marked ("Win a Xamarin Prize"));
			//App.WaitForElement (PlatformQueries.EntryWithPlaceholder ("Full Name"));
			//App.WaitForElement (PlatformQueries.EntryWithPlaceholder ("Email"));
			//App.WaitForElement (PlatformQueries.EntryWithPlaceholder ("Company"));
			//App.WaitForElement (q => q.Marked ("Completed Azure Mobile Services Challenge?"));

			//var switches = App.Query (q => q.Raw ("Switch"));
			//Assert.AreEqual (1, switches.Length);

			//App.WaitForElement (q => q.Button ("Spin"));
			//App.Screenshot ("All elements present");

			Assert.Inconclusive ("Fix Test");
		}
#endif

		StackLayout MakeForm ()
		{
			var nameEntry = new Entry {
				Placeholder = "Full Name"
			};
			var emailEntry = new Entry {
				Placeholder = "Email"
			};

			var companyEntry = new Entry {
				Placeholder = "Company"
			};

			var switchContainer = new StackLayout {
				Orientation = StackOrientation.Horizontal
			};

			var switchLabel = new Label {
				Text = "Completed Azure Mobile Services Challenge?"
			};
			var switchElement = new Switch ();

			switchContainer.Children.Add (switchLabel);
			switchContainer.Children.Add (switchElement);

			var entryContainer = new StackLayout {
				Children = {
					nameEntry,
					emailEntry,
					companyEntry,
					switchContainer
				},
				MinimumWidthRequest = 50
			};

			var qrButton = new Image {
				Source = "cover1.jpg",
				WidthRequest = 100,
				HeightRequest = 100
			};

			var result = new StackLayout {
				Orientation = StackOrientation.Horizontal
			};

			result.Children.Add (entryContainer);
			result.Children.Add (qrButton);

			result.SizeChanged += (sender, args) => {
				Debug.WriteLine (result.Bounds);
			};

			return result;
		}
	}
}