Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 6e3e218

Browse files
committed
[iOS] Fix regression 2.3.1-pre1 UnevenRows (#242)
* [Controls] Add test case for 39486 * [iOS] Fix math refactor error on calculating height
1 parent 0772a52 commit 6e3e218

File tree

3 files changed

+245
-1
lines changed

3 files changed

+245
-1
lines changed
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Xamarin.Forms.CustomAttributes;
4+
using Xamarin.Forms.Internals;
5+
6+
#if UITEST
7+
using Xamarin.UITest;
8+
using NUnit.Framework;
9+
#endif
10+
11+
namespace Xamarin.Forms.Controls
12+
{
13+
[Preserve(AllMembers = true)]
14+
[Issue(IssueTracker.Bugzilla, 39486, "HasUnevenRows=true ignored in Forms iOS project in TableView with CustomCell; row heights are not auto-sized")]
15+
public class Bugzilla39486 : TestContentPage // or TestMasterDetailPage, etc ...
16+
{
17+
protected override void Init()
18+
{
19+
TextCell cell1 = new TextCell
20+
{
21+
Text = "ListView: TextCell"
22+
};
23+
cell1.Tapped += async delegate (object sender, EventArgs e)
24+
{
25+
await Navigation.PushAsync(new ListViewTextCellPage());
26+
};
27+
TextCell cell2 = new TextCell
28+
{
29+
Text = "ListView: CustomCell"
30+
};
31+
cell2.Tapped += async delegate (object sender, EventArgs e)
32+
{
33+
await Navigation.PushAsync(new ListViewCustomCellPage(ListViewCachingStrategy.RetainElement));
34+
};
35+
TextCell cell3 = new TextCell
36+
{
37+
Text = "TableView: TextCell"
38+
};
39+
cell3.Tapped += async delegate (object sender, EventArgs e)
40+
{
41+
await Navigation.PushAsync(new TableViewTextCellPage());
42+
};
43+
TextCell cell4 = new TextCell
44+
{
45+
Text = "TableView: CustomCell"
46+
};
47+
cell4.Tapped += async delegate (object sender, EventArgs e)
48+
{
49+
await Navigation.PushAsync(new TableViewCustomCellPage());
50+
};
51+
52+
TextCell cell5 = new TextCell
53+
{
54+
Text = "ListView: CustomCell RecycleElement"
55+
};
56+
cell5.Tapped += async delegate (object sender, EventArgs e)
57+
{
58+
await Navigation.PushAsync(new ListViewCustomCellPage(ListViewCachingStrategy.RecycleElement));
59+
};
60+
TableView tableV = new TableView
61+
{
62+
Root = new TableRoot {
63+
new TableSection {
64+
cell1,
65+
cell2,
66+
cell3,
67+
cell4,
68+
cell5
69+
}
70+
}
71+
};
72+
Content = tableV;
73+
}
74+
75+
class TableViewTextCellPage : ContentPage
76+
{
77+
public TableViewTextCellPage()
78+
{
79+
TableSection ts = new TableSection();
80+
TableView tableV = new TableView
81+
{
82+
HasUnevenRows = true,
83+
Root = new TableRoot {
84+
ts
85+
}
86+
};
87+
foreach (CustomData data in GetData())
88+
{
89+
ts.Add(new TextCell
90+
{
91+
Text = data.Title,
92+
Detail = data.SubTitle
93+
});
94+
}
95+
Content = tableV;
96+
}
97+
}
98+
99+
class TableViewCustomCellPage : ContentPage
100+
{
101+
public TableViewCustomCellPage()
102+
{
103+
TableSection ts = new TableSection();
104+
TableView tableV = new TableView
105+
{
106+
HasUnevenRows = true,
107+
Root = new TableRoot {
108+
ts
109+
}
110+
};
111+
foreach (CustomData data in GetData())
112+
{
113+
ts.Add(new CustomCell
114+
{
115+
Text = data.Title,
116+
Detail = data.SubTitle
117+
});
118+
}
119+
Content = tableV;
120+
}
121+
}
122+
123+
class ListViewTextCellPage : ContentPage
124+
{
125+
public ListViewTextCellPage()
126+
{
127+
DataTemplate it = new DataTemplate(typeof(TextCell));
128+
it.SetBinding(TextCell.TextProperty, "Title");
129+
it.SetBinding(TextCell.DetailProperty, "SubTitle");
130+
ListView listV = new ListView
131+
{
132+
HasUnevenRows = true,
133+
ItemTemplate = it,
134+
ItemsSource = GetData()
135+
};
136+
Content = listV;
137+
}
138+
}
139+
140+
class ListViewCustomCellPage : ContentPage
141+
{
142+
public ListViewCustomCellPage(ListViewCachingStrategy strategy)
143+
{
144+
DataTemplate it = new DataTemplate(typeof(CustomCell));
145+
it.SetBinding(CustomCell.TextProperty, "Title");
146+
it.SetBinding(CustomCell.DetailProperty, "SubTitle");
147+
ListView listV = new ListView(strategy)
148+
{
149+
HasUnevenRows = true,
150+
ItemTemplate = it,
151+
ItemsSource = GetData()
152+
};
153+
Content = listV;
154+
}
155+
}
156+
157+
class CustomCell : ViewCell
158+
{
159+
public static BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(CustomCell), default(string), propertyChanged:
160+
(bindable, oldValue, newValue) =>
161+
{
162+
var view = (CustomCell)bindable;
163+
view.Text = newValue.ToString();
164+
});
165+
public static BindableProperty DetailProperty = BindableProperty.Create(nameof(Detail), typeof(string), typeof(CustomCell), default(string), propertyChanged:
166+
(bindable, oldValue, newValue) =>
167+
{
168+
var view = (CustomCell)bindable;
169+
view.Detail = newValue.ToString();
170+
});
171+
172+
public string Text
173+
{
174+
get { return (string)GetValue(TextProperty); }
175+
set
176+
{
177+
SetValue(TextProperty, value);
178+
_textL.Text = value;
179+
}
180+
}
181+
public string Detail
182+
{
183+
get { return (string)GetValue(DetailProperty); }
184+
set
185+
{
186+
SetValue(DetailProperty, value);
187+
_detailL.Text = value;
188+
}
189+
}
190+
191+
private Label _textL = null;
192+
private Label _detailL = null;
193+
194+
public CustomCell()
195+
{
196+
_textL = new Label();
197+
_detailL = new Label
198+
{
199+
FontSize = _textL.FontSize * 0.75f
200+
};
201+
StackLayout mainSL = new StackLayout
202+
{
203+
Orientation = StackOrientation.Vertical,
204+
Padding = new Thickness(15, 10),
205+
Spacing = 5,
206+
Children = {
207+
_textL, _detailL
208+
}
209+
};
210+
View = mainSL;
211+
}
212+
}
213+
214+
static List<CustomData> GetData()
215+
{
216+
List<CustomData> retVal = new List<CustomData>(new CustomData[] {
217+
new CustomData {
218+
Title = "One",
219+
SubTitle = "Short"
220+
},
221+
new CustomData {
222+
Title = "Two",
223+
SubTitle = "Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country."
224+
},
225+
new CustomData {
226+
Title = "Three",
227+
SubTitle = "Short"
228+
},
229+
new CustomData {
230+
Title = "Four",
231+
SubTitle = "Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country. Now is the time for all good men to come to the aid of their country."
232+
}
233+
});
234+
return (retVal);
235+
}
236+
237+
class CustomData
238+
{
239+
public string Title { get; set; }
240+
public string SubTitle { get; set; }
241+
}
242+
}
243+
}

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@
407407
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla40704.cs" />
408408
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41038.cs" />
409409
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla38284.cs" />
410+
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla39486.cs" />
410411
</ItemGroup>
411412
<ItemGroup>
412413
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">

Xamarin.Forms.Platform.iOS/Cells/ViewCellRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public override SizeF SizeThatFits(SizeF size)
123123
var result = renderer.Element.Measure(width, height);
124124

125125
// make sure to add in the separator if needed
126-
var finalheight = ((float)result.Request.Height + (SupressSeparator ? 0f : 1f)) / UIScreen.MainScreen.Scale;
126+
var finalheight = (float)result.Request.Height + (SupressSeparator ? 0f : 1f) / UIScreen.MainScreen.Scale;
127127
return new SizeF(size.Width, finalheight);
128128
}
129129

0 commit comments

Comments
 (0)