summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla36788.cs
blob: 76dbbda7f8b9896cb5a30c8811a40a4d7064afb6 (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
using System;
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;

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

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 36788, "Truncation Issues with Relative Layouts")]
	public class Bugzilla36788 : TestContentPage // or TestMasterDetailPage, etc ...
	{
		Label _resultLabel;
		Label _testLabel;
		View _container;

		protected override void Init ()
		{
			// Initialize ui here instead of ctor
			var stackLayout = new StackLayout {
				Spacing = 8
			};

			var longString = "Very long text in single line to be truncated at tail.  Adding extra text to make sure it gets truncated.";

			var contentView = new ContentView {
				Padding = 16,
				BackgroundColor = Color.Gray,
				Content = new Label {
					BackgroundColor = Color.Aqua,
					Text = longString,
					LineBreakMode = LineBreakMode.TailTruncation
				}
			};

			stackLayout.Children.Add (contentView);

			contentView = new ContentView {
				Padding = 16,
				BackgroundColor = Color.Gray,
				Content = new RelativeLayout {
					BackgroundColor = Color.Navy,
					Children = {
						{new Label {
							BackgroundColor = Color.Blue,
							Text = longString,
							LineBreakMode = LineBreakMode.TailTruncation
						}, Forms.Constraint.Constant (0)},
						{new Label {
							BackgroundColor = Color.Fuchsia,
							Text = longString,
							LineBreakMode = LineBreakMode.TailTruncation
						}, Forms.Constraint.Constant (0), Forms.Constraint.Constant (40)},
						{new Label {
							BackgroundColor = Color.Fuchsia,
							Text = longString,
							LineBreakMode = LineBreakMode.TailTruncation
						}, Forms.Constraint.Constant (10), Forms.Constraint.Constant (80)},
					}
				}
			};

			stackLayout.Children.Add (contentView);

			contentView = new ContentView {
				Padding = 16,
				BackgroundColor = Color.Gray,
				IsClippedToBounds = true,
				Content = _container = new RelativeLayout {
					IsClippedToBounds = true,
					BackgroundColor = Color.Navy,
					Children = {
						{_testLabel = new Label {
							BackgroundColor = Color.Blue,
							Text = longString,
							LineBreakMode = LineBreakMode.TailTruncation
						}, Forms.Constraint.Constant (0)},
						{new Label {
							BackgroundColor = Color.Fuchsia,
							Text = longString,
							LineBreakMode = LineBreakMode.TailTruncation
						}, Forms.Constraint.Constant (0), Forms.Constraint.Constant (40)},
						{new Label {
							BackgroundColor = Color.Fuchsia,
							Text = longString,
							LineBreakMode = LineBreakMode.TailTruncation
						}, Forms.Constraint.Constant (10), Forms.Constraint.Constant (80)},
					}
				}
			};

			stackLayout.Children.Add (contentView);

			_resultLabel = new Label ();
			stackLayout.Children.Add (_resultLabel);

			Content = stackLayout;
		}

		protected override async void OnAppearing ()
		{
			base.OnAppearing ();
			await Task.Delay (200);

			double fuzzFactor = 15; // labels sometimes overflow slightly, thanks hinting

			if (Math.Abs (_testLabel.Width - _container.Width) < fuzzFactor)
				_resultLabel.Text = "Passed";
		}

#if UITEST
		[Test]
		public void Bugzilla36788Test ()
		{
			RunningApp.WaitForElement (q => q.Marked ("Passed"));
		}
#endif
	}
}