Skip to content

Commit bc16a06

Browse files
authored
Update Test HostApp to not use TableView (dotnet#28830)
1 parent 12be867 commit bc16a06

3 files changed

Lines changed: 117 additions & 84 deletions

File tree

src/Controls/tests/TestCases.HostApp/CoreViews/CorePageView.cs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Maui.Controls.Sample
66
{
7-
internal class CorePageView : ListView
7+
internal class CorePageView : CollectionView
88
{
99
internal class GalleryPageFactory
1010
{
@@ -92,43 +92,40 @@ public CorePageView(Page rootPage)
9292

9393
var template = new DataTemplate(() =>
9494
{
95-
var cell = new TextCell();
96-
cell.ContextActions.Add(new MenuItem
95+
var cell = new Grid();
96+
97+
var label = new Label
9798
{
98-
Text = "Select Visual",
99-
Command = new Command(async () =>
100-
{
101-
var buttons = typeof(VisualMarker).GetProperties().Select(p => p.Name);
102-
var selection = await rootPage.DisplayActionSheet("Select Visual", "Cancel", null, buttons.ToArray());
103-
if (cell.BindingContext is GalleryPageFactory pageFactory)
104-
{
105-
var page = pageFactory.Realize();
106-
if (typeof(VisualMarker).GetProperty(selection)?.GetValue(null) is IVisual visual)
107-
{
108-
page.Visual = visual;
109-
}
110-
await PushPage(page);
111-
}
112-
})
113-
});
99+
FontSize = 14,
100+
VerticalOptions = LayoutOptions.Center,
101+
Margin = new Thickness(6)
102+
};
103+
104+
label.SetBinding(Label.TextProperty, "Title");
105+
label.SetBinding(Label.AutomationIdProperty, "TitleAutomationId");
106+
107+
cell.Add(label);
114108

115109
return cell;
116110
});
117111

118-
template.SetBinding(TextCell.TextProperty, "Title");
119-
template.SetBinding(TextCell.AutomationIdProperty, "TitleAutomationId");
120-
121112
ItemTemplate = template;
122113
ItemsSource = _pages;
114+
SelectionMode = SelectionMode.Single;
123115

124-
ItemSelected += (sender, args) =>
116+
SelectionChanged += (sender, args) =>
125117
{
126118
if (SelectedItem == null)
127119
{
128120
return;
129121
}
130122

131-
var item = args.SelectedItem;
123+
var selection = args.CurrentSelection;
124+
125+
if (selection.Count == 0)
126+
return;
127+
128+
var item = args.CurrentSelection[0];
132129
if (item is GalleryPageFactory page)
133130
{
134131
var realize = page.Realize();
Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
namespace Maui.Controls.Sample
22
{
3-
internal class CoreRootPage : Microsoft.Maui.Controls.ContentPage
3+
internal class CoreRootPage : ContentPage
44
{
5-
public CoreRootPage(Microsoft.Maui.Controls.Page rootPage)
5+
public CoreRootPage(Page rootPage)
66
{
77
Title = "Controls TestCases";
88

99
var corePageView = new CorePageView(rootPage);
1010

11-
var searchBar = new Microsoft.Maui.Controls.Entry()
11+
var searchBar = new Entry()
1212
{
1313
AutomationId = "SearchBar"
1414
};
@@ -18,11 +18,11 @@ public CoreRootPage(Microsoft.Maui.Controls.Page rootPage)
1818
corePageView.FilterPages(e.NewTextValue);
1919
};
2020

21-
var testCasesButton = new Microsoft.Maui.Controls.Button
21+
var testCasesButton = new Button
2222
{
2323
Text = "Go to Test Cases",
2424
AutomationId = "GoToTestButton",
25-
Command = new Microsoft.Maui.Controls.Command(async () =>
25+
Command = new Command(async () =>
2626
{
2727
if (!string.IsNullOrEmpty(searchBar.Text))
2828
{
@@ -35,26 +35,37 @@ public CoreRootPage(Microsoft.Maui.Controls.Page rootPage)
3535
})
3636
};
3737

38-
var stackLayout = new Microsoft.Maui.Controls.StackLayout()
38+
var rootLayout = new Grid();
39+
rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
40+
rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
41+
rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
42+
rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star });
43+
44+
45+
rootLayout.Add(testCasesButton);
46+
Grid.SetRow(testCasesButton, 0);
47+
48+
rootLayout.Add(searchBar);
49+
Grid.SetRow(searchBar, 1);
50+
51+
var gcButton = new Button
3952
{
40-
Children = {
41-
testCasesButton,
42-
searchBar,
43-
new Microsoft.Maui.Controls.Button {
44-
Text = "Click to Force GC",
45-
Command = new Microsoft.Maui.Controls.Command(() => {
46-
GC.Collect ();
47-
GC.WaitForPendingFinalizers ();
48-
GC.Collect ();
49-
})
50-
},
51-
corePageView
52-
}
53+
Text = "Click to Force GC",
54+
Command = new Command(() => {
55+
GC.Collect();
56+
GC.WaitForPendingFinalizers();
57+
GC.Collect();
58+
})
5359
};
60+
rootLayout.Add(gcButton);
61+
Grid.SetRow(gcButton, 2);
62+
63+
rootLayout.Add(corePageView);
64+
Grid.SetRow(corePageView, 3);
5465

5566
AutomationId = "Gallery";
5667

57-
Content = stackLayout;
68+
Content = rootLayout;
5869
}
5970
}
6071
}

src/Controls/tests/TestCases.HostApp/TestCases.cs

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Maui.Controls.Sample
44
{
55
public static class TestCases
66
{
7-
public class TestCaseScreen : TableView
7+
public class TestCaseScreen : CollectionView
88
{
99
public static Dictionary<string, Action> PageToAction = new Dictionary<string, Action>(StringComparer.OrdinalIgnoreCase);
1010

@@ -44,18 +44,6 @@ void CheckInternetAndLoadPage(Type type)
4444
}
4545
}
4646

47-
48-
static TextCell MakeIssueCell(string text, string detail, Action tapped)
49-
{
50-
PageToAction[text] = tapped;
51-
if (detail != null)
52-
PageToAction[detail] = tapped;
53-
54-
var cell = new TextCell { Text = text, Detail = detail };
55-
cell.Tapped += (s, e) => tapped();
56-
return cell;
57-
}
58-
5947
Action ActivatePageAndNavigate(IssueAttribute issueAttribute, Type type)
6048
{
6149
Action navigationAction = null;
@@ -148,7 +136,6 @@ public bool Matches(string filter)
148136
}
149137

150138
readonly List<IssueModel> _issues;
151-
TableSection _section;
152139

153140
void VerifyNoDuplicates()
154141
{
@@ -170,8 +157,6 @@ public TestCaseScreen()
170157
{
171158
AutomationId = "TestCasesIssueList";
172159

173-
Intent = TableIntent.Settings;
174-
175160
var assembly = typeof(TestCases).Assembly;
176161

177162
#if NATIVE_AOT
@@ -245,17 +230,17 @@ public void FilterIssues(string filter = null)
245230

246231
PageToAction.Clear();
247232

248-
var issueCells = Enumerable.Empty<TextCell>();
233+
var issues = Enumerable.Empty<IssueModel>();
249234

250235
if (!_filterBugzilla)
251236
{
252237
var bugzillaIssueCells =
253238
from issueModel in _issues
254239
where issueModel.IssueTracker == IssueTracker.Bugzilla && issueModel.Matches(filter)
255240
orderby issueModel.IssueNumber descending
256-
select MakeIssueCell(issueModel.Name, issueModel.Description, issueModel.Action);
241+
select issueModel;
257242

258-
issueCells = issueCells.Concat(bugzillaIssueCells);
243+
issues = issues.Concat(bugzillaIssueCells);
259244
}
260245

261246
if (!_filterGitHub)
@@ -264,9 +249,9 @@ orderby issueModel.IssueNumber descending
264249
from issueModel in _issues
265250
where issueModel.IssueTracker == IssueTracker.Github && issueModel.Matches(filter)
266251
orderby issueModel.IssueNumber descending
267-
select MakeIssueCell(issueModel.Name, issueModel.Description, issueModel.Action);
252+
select issueModel;
268253

269-
issueCells = issueCells.Concat(githubIssueCells);
254+
issues = issues.Concat(githubIssueCells);
270255
}
271256

272257
if (!_filterManual)
@@ -275,9 +260,9 @@ orderby issueModel.IssueNumber descending
275260
from issueModel in _issues
276261
where issueModel.IssueTracker == IssueTracker.ManualTest && issueModel.Matches(filter)
277262
orderby issueModel.IssueNumber descending
278-
select MakeIssueCell(issueModel.Name, issueModel.Description, issueModel.Action);
263+
select issueModel;
279264

280-
issueCells = issueCells.Concat(manualIssueCells);
265+
issues = issues.Concat(manualIssueCells);
281266
}
282267

283268
if (!_filterNone)
@@ -286,24 +271,53 @@ orderby issueModel.IssueNumber descending
286271
from issueModel in _issues
287272
where issueModel.IssueTracker == IssueTracker.None && issueModel.Matches(filter)
288273
orderby issueModel.IssueNumber descending, issueModel.Description
289-
select MakeIssueCell(issueModel.Name, issueModel.Description, issueModel.Action);
274+
select issueModel;
290275

291-
issueCells = issueCells.Concat(untrackedIssueCells);
276+
issues = issues.Concat(untrackedIssueCells);
292277
}
293278

294-
if (_section != null)
279+
ItemTemplate = new DataTemplate(() =>
295280
{
296-
Root.Remove(_section);
297-
}
281+
var grid = new Grid
282+
{
283+
Padding = 10,
284+
RowDefinitions =
285+
{
286+
new RowDefinition { Height = GridLength.Auto },
287+
new RowDefinition { Height = GridLength.Star }
288+
}
289+
};
298290

299-
_section = new TableSection("Bug Repro");
291+
var tapGestureRecognizer = new TapGestureRecognizer();
292+
tapGestureRecognizer.Tapped += (sender, args) =>
293+
{
294+
var issueModel = (IssueModel)grid.BindingContext;
295+
issueModel.Action?.Invoke();
296+
};
297+
grid.GestureRecognizers.Add(tapGestureRecognizer);
300298

301-
foreach (var issueCell in issueCells)
302-
{
303-
_section.Add(issueCell);
304-
}
299+
var titleLabel = new Label
300+
{
301+
FontSize = 14,
302+
FontAttributes = FontAttributes.Bold,
303+
};
304+
titleLabel.SetBinding(Label.TextProperty, "IssueNumber");
305+
306+
var descriptionLabel = new Label
307+
{
308+
FontSize = 12,
309+
};
310+
descriptionLabel.SetBinding(Label.TextProperty, "Description");
305311

306-
Root.Add(_section);
312+
grid.Add(titleLabel);
313+
Grid.SetRow(titleLabel, 0);
314+
grid.Add(descriptionLabel);
315+
Grid.SetRow(descriptionLabel, 1);
316+
317+
return grid;
318+
});
319+
320+
ItemsSource = issues;
307321
}
308322

309323
HashSet<string> _exemptNames = new HashSet<string> { };
@@ -316,7 +330,13 @@ from issueModel in _issues
316330
public static NavigationPage GetTestCases()
317331
{
318332
TestCaseScreen testCaseScreen = null;
319-
var rootLayout = new StackLayout();
333+
var rootLayout = new Grid();
334+
335+
rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
336+
rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
337+
rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
338+
rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
339+
rootLayout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star });
320340

321341
var testCasesRoot = new ContentPage
322342
{
@@ -352,7 +372,6 @@ public static NavigationPage GetTestCases()
352372
System.Diagnostics.Debug.WriteLine(e.Message);
353373
Console.WriteLine(e.Message);
354374
}
355-
356375
})
357376
};
358377

@@ -364,14 +383,21 @@ public static NavigationPage GetTestCases()
364383
};
365384

366385
rootLayout.Children.Add(leaveTestCasesButton);
386+
Grid.SetRow(leaveTestCasesButton, 0);
387+
367388
rootLayout.Children.Add(searchBar);
368-
rootLayout.Children.Add(searchButton);
389+
Grid.SetRow(searchBar, 1);
369390

370-
testCaseScreen = new TestCaseScreen();
391+
rootLayout.Children.Add(searchButton);
392+
Grid.SetRow(searchButton, 2);
371393

372-
rootLayout.Children.Add(CreateTrackerFilter(testCaseScreen));
394+
var trackerFilter = CreateTrackerFilter(testCaseScreen);
395+
rootLayout.Children.Add(trackerFilter);
396+
Grid.SetRow(trackerFilter, 3);
373397

398+
testCaseScreen = new TestCaseScreen();
374399
rootLayout.Children.Add(testCaseScreen);
400+
Grid.SetRow(testCaseScreen, 4);
375401

376402
searchBar.TextChanged += (sender, args) => SearchBarOnTextChanged(sender, args, testCaseScreen);
377403

@@ -434,5 +460,4 @@ static void SearchBarOnTextChanged(object sender, TextChangedEventArgs textChang
434460
cases.FilterIssues(filter);
435461
}
436462
}
437-
438463
}

0 commit comments

Comments
 (0)