-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shell pages via controller instead of handler (#13332)
* Add shell pages via controller instead of handler * Auto-format source code * - cleanup * - add wait * - push test into modal to isolate better --------- Co-authored-by: GitHub Actions Autoformatter <autoformat@example.com>
- Loading branch information
Showing
5 changed files
with
204 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,51 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls.Handlers; | ||
using Microsoft.Maui.Controls.Hosting; | ||
using Microsoft.Maui.Devices; | ||
using Microsoft.Maui.DeviceTests.Stubs; | ||
using Microsoft.Maui.Graphics; | ||
using Microsoft.Maui.Handlers; | ||
using Microsoft.Maui.Hosting; | ||
using Microsoft.Maui.Platform; | ||
using Xunit; | ||
#if ANDROID || IOS || MACCATALYST | ||
using ShellHandler = Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer; | ||
#endif | ||
|
||
namespace Microsoft.Maui.DeviceTests | ||
{ | ||
public static class Extensions | ||
{ | ||
public static Task Wait(this Image image, int timeout = 1000) => | ||
AssertionExtensions.Wait(() => !image.IsLoading, timeout); | ||
|
||
public static void SetupShellHandlers(this MauiAppBuilder builder) | ||
{ | ||
builder.ConfigureMauiHandlers(SetupShellHandlers); | ||
} | ||
|
||
public static void SetupShellHandlers(this IMauiHandlersCollection handlers) | ||
{ | ||
handlers.TryAddHandler(typeof(Controls.Shell), typeof(ShellHandler)); | ||
handlers.TryAddHandler<Layout, LayoutHandler>(); | ||
handlers.TryAddHandler<Image, ImageHandler>(); | ||
handlers.TryAddHandler<Label, LabelHandler>(); | ||
handlers.TryAddHandler<Page, PageHandler>(); | ||
handlers.TryAddHandler(typeof(Toolbar), typeof(ToolbarHandler)); | ||
handlers.TryAddHandler(typeof(MenuBar), typeof(MenuBarHandler)); | ||
handlers.TryAddHandler(typeof(MenuBarItem), typeof(MenuBarItemHandler)); | ||
handlers.TryAddHandler(typeof(MenuFlyoutItem), typeof(MenuFlyoutItemHandler)); | ||
handlers.TryAddHandler(typeof(MenuFlyoutSubItem), typeof(MenuFlyoutSubItemHandler)); | ||
handlers.TryAddHandler<ScrollView, ScrollViewHandler>(); | ||
|
||
#if WINDOWS | ||
handlers.TryAddHandler(typeof(ShellItem), typeof(ShellItemHandler)); | ||
handlers.TryAddHandler(typeof(ShellSection), typeof(ShellSectionHandler)); | ||
handlers.TryAddHandler(typeof(ShellContent), typeof(ShellContentHandler)); | ||
#endif | ||
} | ||
} | ||
} | ||
|
77 changes: 77 additions & 0 deletions
77
src/Controls/tests/DeviceTests/TestCases/ControlsPageTypesTestCases.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls.Handlers.Compatibility; | ||
using Microsoft.Maui.DeviceTests.Stubs; | ||
using Microsoft.Maui.Handlers; | ||
using Microsoft.Maui.Hosting; | ||
|
||
#if IOS || MACCATALYST | ||
using FlyoutViewHandler = Microsoft.Maui.Controls.Handlers.Compatibility.PhoneFlyoutPageRenderer; | ||
#endif | ||
|
||
namespace Microsoft.Maui.DeviceTests.TestCases | ||
{ | ||
public class ControlsPageTypesTestCases : IEnumerable<object[]> | ||
{ | ||
private readonly List<object[]> _data = new() | ||
{ | ||
new object[] { nameof(FlyoutPage) }, | ||
new object[] { nameof(TabbedPage) }, | ||
new object[] { nameof(ContentPage) }, | ||
new object[] { nameof(Shell) }, | ||
new object[] { nameof(NavigationPage) }, | ||
}; | ||
|
||
public IEnumerator<object[]> GetEnumerator() => _data.GetEnumerator(); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
|
||
|
||
public static Page CreatePageType(string name, Page content) | ||
{ | ||
switch (name) | ||
{ | ||
case nameof(FlyoutPage): | ||
content.Title = content.Title ?? "Detail Title"; | ||
return new FlyoutPage() { Flyout = new ContentPage() { Title = "title" }, Detail = content }; | ||
case nameof(TabbedPage): | ||
return new TabbedPage() { Children = { content } }; | ||
case nameof(ContentPage): | ||
return content; | ||
case nameof(Shell): | ||
return new Shell() { CurrentItem = (ContentPage)content }; | ||
case nameof(NavigationPage): | ||
return new NavigationPage(content); | ||
} | ||
|
||
throw new Exception($"{name} not found"); | ||
} | ||
|
||
public static void Setup(MauiAppBuilder builder) | ||
{ | ||
builder.ConfigureMauiHandlers(handlers => | ||
{ | ||
handlers.SetupShellHandlers(); | ||
|
||
handlers.AddHandler(typeof(Controls.Label), typeof(LabelHandler)); | ||
handlers.AddHandler(typeof(Controls.Toolbar), typeof(ToolbarHandler)); | ||
handlers.AddHandler(typeof(FlyoutPage), typeof(FlyoutViewHandler)); | ||
#if IOS || MACCATALYST | ||
handlers.AddHandler(typeof(TabbedPage), typeof(TabbedRenderer)); | ||
handlers.AddHandler(typeof(NavigationPage), typeof(NavigationRenderer)); | ||
#else | ||
handlers.AddHandler(typeof(TabbedPage), typeof(TabbedViewHandler)); | ||
handlers.AddHandler(typeof(NavigationPage), typeof(NavigationViewHandler)); | ||
#endif | ||
handlers.AddHandler<Page, PageHandler>(); | ||
handlers.AddHandler<Controls.Window, WindowHandlerStub>(); | ||
}); | ||
} | ||
} | ||
} |