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 @@ -24,7 +24,7 @@ internal UIContainerCell(string cellId, View view, Shell shell, object context)

if (_renderer == null)
{
_renderer = (IPlatformViewHandler)view.ToHandler(shell.FindMauiContext());
_renderer = (IPlatformViewHandler)view.ToHandler(view.FindMauiContext() ?? shell.FindMauiContext());
}

ContentView.AddSubview(_renderer.PlatformView);
Expand Down
28 changes: 28 additions & 0 deletions src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Handlers;
using Microsoft.Maui.Controls.Handlers.Compatibility;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Platform;
Expand Down Expand Up @@ -34,6 +36,32 @@ void SetupBuilder()
});
}

#if ANDROID || IOS || MACCATALYST
[Fact]
public async Task SearchHandlerRendersCorrectly()
{
SetupBuilder();

var shell = await CreateShellAsync(shell =>
{
shell.Items.Add(new FlyoutItem() { Route = "FlyoutItem1", Items = { new ContentPage() }, Title = "Flyout Item" });
shell.Items.Add(new FlyoutItem() { Route = "FlyoutItem2", Items = { new ContentPage() }, Title = "Flyout Item" });

Shell.SetSearchHandler(shell, new SearchHandler() { SearchBoxVisibility = SearchBoxVisibility.Expanded });
});

await CreateHandlerAndAddToWindow<ShellRenderer>(shell, async (handler) =>
{
await OnLoadedAsync(shell.CurrentPage);
await OnNavigatedToAsync(shell.CurrentPage);
await Task.Delay(100);
await shell.GoToAsync("//FlyoutItem2");

// No crash using SearchHandler
});
}
#endif

[Fact]
public async Task FlyoutWithAsMultipleItemsRendersWithoutCrashing()
{
Expand Down