-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Issue5766.cs
162 lines (145 loc) · 4.83 KB
/
Issue5766.cs
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
using System;
using System.Linq;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve (AllMembers=true)]
[Issue (IssueTracker.Github, 5766, "Frame size gets corrupted when ListView is scrolled", PlatformAffected.Android)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.Layout)]
#endif
public class Issue5766 : TestContentPage
{
const string StartText1 = "start1";
const string BigText1 = "big string > big frame1";
const string SmallText1 = "s1";
const string EndText1 = "end1";
const string List1 = "lst1";
const string StartText2 = "start2";
const string BigText2 = "big string > big frame2";
const string SmallText2 = "s2";
const string EndText2 = "end2";
const string List2 = "lst2";
protected override void Init()
{
var grid = new Grid
{
RowDefinitions = new RowDefinitionCollection
{
new RowDefinition { Height = GridLength.Auto},
new RowDefinition(),
}
};
grid.AddChild(new Label
{
Text = "Scroll up and down several times and make sure Frame size is accurate when using Fast Renderers.",
VerticalTextAlignment = TextAlignment.Center
}, 0, 0, 2);
var template = new DataTemplate(() =>
{
var text = new Label
{
VerticalOptions = LayoutOptions.Fill,
TextColor = Color.White,
};
text.SetBinding(Label.TextProperty, ".");
var view = new Grid
{
HeightRequest = 80,
Margin = new Thickness(0, 10, 0, 0),
BackgroundColor = Color.FromHex("#F1F1F1")
};
view.AddChild(new Frame
{
Padding = new Thickness(5),
Margin = new Thickness(0, 0, 10, 0),
BorderColor = Color.Blue,
BackgroundColor = Color.Gray,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.End,
CornerRadius = 3,
Content = text
}, 0, 0);
return new ViewCell
{
View = view
};
});
grid.AddChild(new ListView
{
AutomationId = List1,
HasUnevenRows = true,
ItemsSource = (new[] { StartText1 }).Concat(Enumerable.Range(0, 99).Select(i => i % 2 != 0 ? SmallText1 : BigText1)).Concat(new[] { EndText1 }),
ItemTemplate = template
}, 0, 1);
grid.AddChild(new ListView(ListViewCachingStrategy.RecycleElement)
{
AutomationId = List2,
HasUnevenRows = true,
ItemsSource = (new[] { StartText2 }).Concat(Enumerable.Range(0, 99).Select(i => i % 2 != 0 ? SmallText2 : BigText2)).Concat(new[] { EndText2 }),
ItemTemplate = template
}, 1, 1);
Content = grid;
}
#if UITEST && __ANDROID__
UITest.Queries.AppRect[] GetLabels(IApp RunningApp, string label)
{
return RunningApp
.Query(q => q.Class("FormsTextView"))
.Where(x => x.Text == label)
.Select(x => x.Rect)
.ToArray();
}
bool RectIsEquals(UITest.Queries.AppRect[] left, UITest.Queries.AppRect[] right)
{
if (left.Length != right.Length)
return false;
for (int i = 0; i < left.Length; i++)
{
if (left[i].X != right[i].X ||
left[i].Y != right[i].Y ||
left[i].Width != right[i].Width ||
left[i].Height != right[i].Height)
return false;
}
return true;
}
[Test]
[Ignore("Fails sometimes - needs a better test")]
public void FrameSizeGetsCorruptedWhenListViewIsScrolled()
{
RunningApp.WaitForElement(StartText1);
var start = GetLabels(RunningApp, StartText1);
var smalls = GetLabels(RunningApp, SmallText1);
var bigs = GetLabels(RunningApp, BigText1);
RunningApp.ScrollDownTo(EndText1, List1, ScrollStrategy.Gesture, 0.9, 15000, timeout: TimeSpan.FromMinutes(1));
RunningApp.ScrollUpTo(StartText1, List1, ScrollStrategy.Gesture, 0.9, 15000, timeout: TimeSpan.FromMinutes(1));
var startAfter = GetLabels(RunningApp, StartText1);
Assert.IsTrue(RectIsEquals(start, startAfter));
var smallAfter = GetLabels(RunningApp, SmallText1);
Assert.IsTrue(RectIsEquals(smalls, smallAfter));
var bigAfter = GetLabels(RunningApp, BigText1);
Assert.IsTrue(RectIsEquals(bigs, bigAfter));
// list2 with ListViewCachingStrategy.RecycleElement - issue 6297
RunningApp.WaitForElement(StartText2);
start = GetLabels(RunningApp, StartText2);
smalls = GetLabels(RunningApp, SmallText2);
bigs = GetLabels(RunningApp, BigText2);
RunningApp.ScrollDownTo(EndText2, List2, ScrollStrategy.Gesture, 0.9, 15000, timeout: TimeSpan.FromMinutes(1));
RunningApp.ScrollUpTo(StartText2, List2, ScrollStrategy.Gesture, 0.9, 15000, timeout: TimeSpan.FromMinutes(1));
startAfter = GetLabels(RunningApp, StartText2);
Assert.IsTrue(RectIsEquals(start, startAfter));
smallAfter = GetLabels(RunningApp, SmallText2);
Assert.IsTrue(RectIsEquals(smalls, smallAfter));
bigAfter = GetLabels(RunningApp, BigText2);
Assert.IsTrue(RectIsEquals(bigs, bigAfter));
}
#endif
}
}