summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla28650.cs
blob: e6c471a89c2727a2051859746621c1dae715d6b1 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Collections.Generic;
using System;
using System.Threading.Tasks;

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

namespace Xamarin.Forms.Controls
{
	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.Bugzilla, 28650, "In a Listview on iOS, \"andExpand\" does not expand when text is two lines long")]
	public class Bugzilla28650 : TestContentPage
	{
		const string caret_image = "caret_r.png";

		[Preserve(AllMembers = true)]
		internal class MyTextCell : ViewCell
		{
			StackLayout _viewLayout;
			Label _descriptionLabel;
			Image _caret;

			public MyTextCell()
			{
				_descriptionLabel = new Label
				{
					HorizontalOptions = LayoutOptions.FillAndExpand,
					FontSize = 14,
				};
				_descriptionLabel.SetBinding(Label.TextProperty, ".");

				_caret = new Image
				{
					HorizontalOptions = LayoutOptions.End,
					Source = ImageSource.FromFile(caret_image),
					HeightRequest = 20,
					Aspect = Aspect.AspectFit,
					BackgroundColor = Color.Green
				};

				_viewLayout = new StackLayout
				{
					Orientation = StackOrientation.Horizontal,
					HorizontalOptions = LayoutOptions.FillAndExpand,
					Children = { _descriptionLabel, _caret },
				};

				View = _viewLayout;
			}
		}

		protected override void Init()
		{
			var items = new List<string>
			{
				"Short Desc",
				"Thisis averylong description withwords thatarelong",
				"Item Three",
				"Item Four",
				"Short Desc again",
			};

			var cell = new DataTemplate(typeof(MyTextCell));
			var menuView = new ListView
			{
				ItemTemplate = cell,
				ItemsSource = items,
				HasUnevenRows = true
			};

			// let's try the same configuration outside of a ListView
			var grid = new Grid();
			grid.ColumnDefinitions.Add(new ColumnDefinition { Width = 300 });

			const int column = 0;
			int currentRow = 0;
			grid.AddChild(new Label { Text = "If the carets do not ALL align, this test has failed." }, column, currentRow++, columnspan: 2);
			grid.AddChild(menuView, column, currentRow++);
			grid.AddChild(GetStackLayout("Thisis averylong description withwords thatarelong", LineBreakMode.NoWrap), column, currentRow++);
			grid.AddChild(GetStackLayout("Thisis averylong description withwords thatarelong", LineBreakMode.CharacterWrap), column, currentRow++);
			grid.AddChild(GetStackLayout("Thisis averylong description withwords thatarelong", LineBreakMode.HeadTruncation), column, currentRow++);
			grid.AddChild(GetStackLayout("Thisis averylong description withwords thatarelong", LineBreakMode.MiddleTruncation), column, currentRow++);
			grid.AddChild(GetStackLayout("Thisis averylong description withwords thatarelong", LineBreakMode.TailTruncation), column, currentRow++);
			grid.AddChild(GetStackLayout("Thisis averylong description withwords thatarelong", LineBreakMode.WordWrap), column, currentRow++);
			grid.AddChild(GetStackLayout("Short desc", LineBreakMode.WordWrap), column, currentRow++);


			grid.AddChild(new StackLayout
			{
				Orientation = StackOrientation.Horizontal,
				HorizontalOptions = LayoutOptions.FillAndExpand,
				Children = {
					new Label
					{
						HorizontalOptions = LayoutOptions.FillAndExpand,
						FontSize = 14,
						Text = "1",
						LineBreakMode = LineBreakMode.WordWrap,
						BackgroundColor = Color.Red
					}, new Label
					{
						HorizontalOptions = LayoutOptions.FillAndExpand,
						FontSize = 14,
						Text = "2",
						LineBreakMode = LineBreakMode.WordWrap,
						BackgroundColor = Color.Blue
					}
				},
			}, column, currentRow++);

			grid.AddChild(new StackLayout
			{
				Orientation = StackOrientation.Horizontal,
				HorizontalOptions = LayoutOptions.FillAndExpand,
				Children = {
					new Label
					{
						HorizontalOptions = LayoutOptions.FillAndExpand,
						FontSize = 14,
						Text = "1",
						LineBreakMode = LineBreakMode.WordWrap,
						BackgroundColor = Color.Red
					}, new Label
					{
						HorizontalOptions = LayoutOptions.Start,
						FontSize = 14,
						Text = "2",
						LineBreakMode = LineBreakMode.WordWrap,
						BackgroundColor = Color.Blue
					}
				},
			}, column, currentRow++);

			Content = grid;
		}
		private static StackLayout GetStackLayout(string Text, LineBreakMode breakMode)
		{
			return new StackLayout
			{
				Orientation = StackOrientation.Horizontal,
				HorizontalOptions = LayoutOptions.FillAndExpand,
				Children = {
					new Label
					{
						HorizontalOptions = LayoutOptions.FillAndExpand,
						FontSize = 14,
						Text = Text,
						LineBreakMode = breakMode
					}, new Image
					{
						HorizontalOptions = LayoutOptions.End,
						Source = ImageSource.FromFile(caret_image),
						HeightRequest = 20,
						Aspect = Aspect.AspectFit,
						BackgroundColor = Color.Green
					}
				},
			};
		}
	}
}