-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Issue12574.cs
238 lines (202 loc) · 6.14 KB
/
Issue12574.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using Microsoft.Maui.Controls.CustomAttributes;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Graphics;
#if UITEST
using Microsoft.Maui.Controls.Compatibility.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Microsoft.Maui.Controls.ControlGallery.Issues
{
#if UITEST
[NUnit.Framework.Category(UITestCategories.CarouselView)]
[NUnit.Framework.Category(UITestCategories.UwpIgnore)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 12574, "CarouselView Loop=True default freezes iOS app", PlatformAffected.Default)]
public class Issue12574 : TestContentPage
{
ViewModelIssue12574 viewModel;
CarouselView _carouselView;
Button _btn;
Button _btn2;
string carouselAutomationId = "carouselView";
string btnRemoveAutomationId = "btnRemove";
string btnRemoveAllAutomationId = "btnRemoveAll";
protected override void Init()
{
_btn = new Button
{
Text = "Remove Last",
AutomationId = btnRemoveAutomationId
};
_btn.SetBinding(Button.CommandProperty, "RemoveLastItemCommand");
_btn2 = new Button
{
Text = "Remove All",
AutomationId = btnRemoveAllAutomationId
};
_btn2.SetBinding(Button.CommandProperty, "RemoveAllItemsCommand");
_carouselView = new CarouselView
{
AutomationId = carouselAutomationId,
Margin = new Thickness(30),
BackgroundColor = Colors.Yellow,
ItemTemplate = new DataTemplate(() =>
{
var stacklayout = new StackLayout();
var labelId = new Label();
var labelText = new Label();
var labelDescription = new Label();
labelId.SetBinding(Label.TextProperty, "Id");
labelText.SetBinding(Label.TextProperty, "Text");
labelDescription.SetBinding(Label.TextProperty, "Description");
stacklayout.Children.Add(labelId);
stacklayout.Children.Add(labelText);
stacklayout.Children.Add(labelDescription);
return stacklayout;
})
};
_carouselView.SetBinding(CarouselView.ItemsSourceProperty, "Items");
this.SetBinding(Page.TitleProperty, "Title");
var layout = new Grid();
layout.RowDefinitions.Add(new RowDefinition { Height = 100 });
layout.RowDefinitions.Add(new RowDefinition { Height = 100 });
layout.RowDefinitions.Add(new RowDefinition());
Grid.SetRow(_btn2, 1);
Grid.SetRow(_carouselView, 2);
layout.Children.Add(_btn);
layout.Children.Add(_btn2);
layout.Children.Add(_carouselView);
BindingContext = viewModel = new ViewModelIssue12574();
Content = layout;
}
protected override void OnAppearing()
{
base.OnAppearing();
viewModel.OnAppearing();
}
#if UITEST
[Test]
[Compatibility.UITests.FailsOnMauiIOS]
[Compatibility.UITests.FailsOnMauiAndroid]
public void Issue12574Test()
{
RunningApp.WaitForElement("0 item");
var rect = RunningApp.Query(c => c.Marked(carouselAutomationId)).First().Rect;
var centerX = rect.CenterX;
var rightX = rect.X - 5;
RunningApp.DragCoordinates(centerX + 40, rect.CenterY, rightX, rect.CenterY);
RunningApp.WaitForElement("1 item");
RunningApp.DragCoordinates(centerX + 40, rect.CenterY, rightX, rect.CenterY);
RunningApp.WaitForElement("2 item");
RunningApp.Tap(btnRemoveAutomationId);
RunningApp.WaitForElement("1 item");
rightX = rect.X + rect.Width - 1;
RunningApp.DragCoordinates(rect.X, rect.CenterY, rightX, rect.CenterY);
RunningApp.WaitForElement("0 item");
}
[Test]
[Compatibility.UITests.FailsOnMauiIOS]
public void RemoveItemsQuickly()
{
RunningApp.WaitForElement("0 item");
RunningApp.Tap(btnRemoveAllAutomationId);
// If we haven't crashed, then the other button should be here
RunningApp.WaitForElement(btnRemoveAutomationId);
}
#endif
}
class ViewModelIssue12574 : BaseViewModel1
{
public ObservableCollection<ModelIssue12574> Items { get; set; }
public Command LoadItemsCommand { get; set; }
public Command RemoveAllItemsCommand { get; set; }
public Command RemoveLastItemCommand { get; set; }
public ViewModelIssue12574()
{
Title = "CarouselView Looping";
Items = new ObservableCollection<ModelIssue12574>();
LoadItemsCommand = new Command(() => ExecuteLoadItemsCommand());
RemoveAllItemsCommand = new Command(() => ExecuteRemoveItemsCommand(), () => Items.Count > 0);
RemoveLastItemCommand = new Command(() => ExecuteRemoveLastItemCommand(), () => Items.Count > 0);
}
void ExecuteRemoveItemsCommand()
{
while (Items.Count > 0)
{
Items.Remove(Items.Last());
Items.Remove(Items.Last());
Items.Remove(Items.Last());
}
RemoveAllItemsCommand.ChangeCanExecute();
RemoveLastItemCommand.ChangeCanExecute();
}
void ExecuteRemoveLastItemCommand()
{
Items.Remove(Items.Last());
RemoveAllItemsCommand.ChangeCanExecute();
RemoveLastItemCommand.ChangeCanExecute();
}
void ExecuteLoadItemsCommand()
{
IsBusy = true;
try
{
Items.Clear();
for (int i = 0; i < 3; i++)
{
Items.Add(new ModelIssue12574 { Id = Guid.NewGuid().ToString(), Text = $"{i} item", Description = "This is an item description." });
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
finally
{
IsBusy = false;
RemoveAllItemsCommand.ChangeCanExecute();
RemoveLastItemCommand.ChangeCanExecute();
}
}
public void OnAppearing()
{
IsBusy = true;
LoadItemsCommand.Execute(null);
}
}
class ModelIssue12574
{
public string Id { get; set; }
public string Text { get; set; }
public string Description { get; set; }
}
class BaseViewModel1 : INotifyPropertyChanged
{
public string Title { get; set; }
public bool IsInitialized { get; set; }
bool _isBusy;
/// <summary>
/// Gets or sets if VM is busy working
/// </summary>
public bool IsBusy
{
get { return _isBusy; }
set { _isBusy = value; OnPropertyChanged("IsBusy"); }
}
//INotifyPropertyChanged Implementation
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged == null)
return;
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}