diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs index 364dd85fee9b..3196afc56722 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs @@ -255,7 +255,7 @@ protected virtual void LoadRenderers() if (item == currentItem) { - _containerArea.AddSubview(renderer.ViewController.View); + _containerArea.AddSubview(renderer.PlatformView); _currentContent = currentItem; _currentIndex = i; } diff --git a/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs b/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs index 7617c5270044..6174844a4a62 100644 --- a/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs +++ b/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs @@ -41,8 +41,26 @@ protected override MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder return mauiAppBuilder.ConfigureTestBuilder(); } - protected void SetupShellHandlers(IMauiHandlersCollection handlers) => - handlers.SetupShellHandlers(); + protected void SetupShellHandlers(IMauiHandlersCollection handlers) + { + handlers.TryAddHandler(typeof(Controls.Shell), typeof(ShellHandler)); + handlers.TryAddHandler(); + handlers.TryAddHandler(); + handlers.TryAddHandler(); + handlers.TryAddHandler(); + 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(); + +#if WINDOWS + handlers.TryAddHandler(typeof(ShellItem), typeof(ShellItemHandler)); + handlers.TryAddHandler(typeof(ShellSection), typeof(ShellSectionHandler)); + handlers.TryAddHandler(typeof(ShellContent), typeof(ShellContentHandler)); +#endif + } protected THandler CreateHandler(IElement view) where THandler : IElementHandler, new() @@ -81,29 +99,6 @@ protected Task GetValueAsync(IElement view, Func(CreateWindowForContent(view), handler => - { - action(); - return Task.CompletedTask; - }); - } - protected Task CreateHandlerAndAddToWindow(IElement view, Action action) where THandler : class, IElementHandler { @@ -122,10 +117,23 @@ protected Task CreateHandlerAndAddToWindow(IElement view, Func { - IWindow window = CreateWindowForContent(view); + IWindow window = null; var application = mauiContext.Services.GetService(); + if (view is IWindow w) + { + window = w; + } + else if (view is Page page) + { + window = new Controls.Window(page); + } + else + { + window = new Controls.Window(new ContentPage() { Content = (View)view }); + } + if (application is ApplicationStub appStub) { appStub.SetWindow((Window)window); @@ -142,9 +150,6 @@ await SetupWindowForTests(window, async () => { IView content = window.Content; - if (content is FlyoutPage fp) - content = fp.Detail; - if (content is IPageContainer pc) { content = pc.CurrentPage; @@ -175,8 +180,6 @@ await SetupWindowForTests(window, async () => await action((THandler)window.Content.Handler); else if (window.Content is ContentPage cp && typeof(THandler).IsAssignableFrom(cp.Content.Handler.GetType())) await action((THandler)cp.Content.Handler); - else if (typeof(THandler).IsAssignableFrom(typeof(WindowHandler))) - throw new Exception($"Use IWindowHandler instead of WindowHandler for CreateHandlerAndAddToWindow"); else throw new Exception($"I can't work with {typeof(THandler)}"); diff --git a/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.iOS.cs index d9725e5f9a0d..e6612ac553c3 100644 --- a/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.iOS.cs @@ -1,11 +1,6 @@ using System.Threading.Tasks; -using Microsoft.Maui.Controls; -using Microsoft.Maui.DeviceTests.TestCases; using Microsoft.Maui.Handlers; -using Microsoft.Maui.Hosting; -using Microsoft.Maui.Platform; using UIKit; -using Xunit; namespace Microsoft.Maui.DeviceTests { @@ -41,56 +36,5 @@ int GetPlatformSelectionLength(EntryHandler entryHandler) return -1; } - - [Category(TestCategory.Entry)] - [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)] - public partial class EntryTestsWithWindow : ControlsHandlerTestBase - { - [Theory] - [ClassData(typeof(ControlsPageTypesTestCases))] - public async Task NextMovesToNextEntry(string page) - { - EnsureHandlerCreated(builder => - { - ControlsPageTypesTestCases.Setup(builder); - builder.ConfigureMauiHandlers(handlers => - { - handlers.AddHandler(typeof(Entry), typeof(EntryHandler)); - }); - }); - - var entry1 = new Entry - { - Text = "Entry 1", - ReturnType = ReturnType.Next - }; - - var entry2 = new Entry - { - Text = "Entry 2", - ReturnType = ReturnType.Next - }; - - ContentPage contentPage = new ContentPage() - { - Content = new VerticalStackLayout() - { - entry1, - entry2 - } - }; - - Page rootPage = ControlsPageTypesTestCases.CreatePageType(page, contentPage); - Page hostPage = new ContentPage(); - - await CreateHandlerAndAddToWindow(hostPage, async () => - { - await hostPage.Navigation.PushModalAsync(rootPage); - KeyboardAutoManager.GoToNextResponderOrResign(entry1.ToPlatform()); - await AssertionExtensions.Wait(() => entry2.IsFocused); - Assert.True(entry2.IsFocused); - }); - } - } } -} \ No newline at end of file +} diff --git a/src/Controls/tests/DeviceTests/Extensions.cs b/src/Controls/tests/DeviceTests/Extensions.cs index b20b0b9bbd59..ef609a204bc2 100644 --- a/src/Controls/tests/DeviceTests/Extensions.cs +++ b/src/Controls/tests/DeviceTests/Extensions.cs @@ -1,18 +1,6 @@ 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 { @@ -20,32 +8,6 @@ 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(); - handlers.TryAddHandler(); - handlers.TryAddHandler(); - handlers.TryAddHandler(); - 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(); - -#if WINDOWS - handlers.TryAddHandler(typeof(ShellItem), typeof(ShellItemHandler)); - handlers.TryAddHandler(typeof(ShellSection), typeof(ShellSectionHandler)); - handlers.TryAddHandler(typeof(ShellContent), typeof(ShellContentHandler)); -#endif - } } } diff --git a/src/Controls/tests/DeviceTests/TestCases/ControlsPageTypesTestCases.cs b/src/Controls/tests/DeviceTests/TestCases/ControlsPageTypesTestCases.cs deleted file mode 100644 index 0e6de1d421bb..000000000000 --- a/src/Controls/tests/DeviceTests/TestCases/ControlsPageTypesTestCases.cs +++ /dev/null @@ -1,77 +0,0 @@ -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 - { - private readonly List _data = new() - { - new object[] { nameof(FlyoutPage) }, - new object[] { nameof(TabbedPage) }, - new object[] { nameof(ContentPage) }, - new object[] { nameof(Shell) }, - new object[] { nameof(NavigationPage) }, - }; - - public IEnumerator 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(); - handlers.AddHandler(); - }); - } - } -} \ No newline at end of file