Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ protected virtual void LoadRenderers()

if (item == currentItem)
{
_containerArea.AddSubview(renderer.ViewController.View);
_containerArea.AddSubview(renderer.PlatformView);
_currentContent = currentItem;
_currentIndex = i;
}
Expand Down
65 changes: 34 additions & 31 deletions src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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
}

protected THandler CreateHandler<THandler>(IElement view)
where THandler : IElementHandler, new()
Expand Down Expand Up @@ -81,29 +99,6 @@ protected Task<TValue> GetValueAsync<TValue>(IElement view, Func<IPlatformViewHa
});
}

IWindow CreateWindowForContent(IElement view)
{
IWindow window;

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 });

return window;
}

protected Task CreateHandlerAndAddToWindow(IElement view, Action action)
{
return CreateHandlerAndAddToWindow<IWindowHandler>(CreateWindowForContent(view), handler =>
{
action();
return Task.CompletedTask;
});
}

protected Task CreateHandlerAndAddToWindow<THandler>(IElement view, Action<THandler> action)
where THandler : class, IElementHandler
{
Expand All @@ -122,10 +117,23 @@ protected Task CreateHandlerAndAddToWindow<THandler>(IElement view, Func<THandle

return InvokeOnMainThreadAsync(async () =>
{
IWindow window = CreateWindowForContent(view);
IWindow window = null;

var application = mauiContext.Services.GetService<IApplication>();

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);
Expand All @@ -142,9 +150,6 @@ await SetupWindowForTests<THandler>(window, async () =>
{
IView content = window.Content;

if (content is FlyoutPage fp)
content = fp.Detail;

if (content is IPageContainer<Page> pc)
{
content = pc.CurrentPage;
Expand Down Expand Up @@ -175,8 +180,6 @@ await SetupWindowForTests<THandler>(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)}");

Expand Down
58 changes: 1 addition & 57 deletions src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.iOS.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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);
});
}
}
}
}
}
38 changes: 0 additions & 38 deletions src/Controls/tests/DeviceTests/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,51 +1,13 @@
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
}
}
}

This file was deleted.