Skip to content

Commit

Permalink
[macOS] Fix crash using Shell SearchHandler on Catalyst (dotnet#11926)
Browse files Browse the repository at this point in the history
* Fix crash using Shell SearchHandler on Catalyst

* Updated changes

* Added device test

* Update src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/UIContainerCell.cs

Co-authored-by: Shane Neuville <[email protected]>

* Fix merge issue

* Moved test

---------

Co-authored-by: Rui Marinho <[email protected]>
Co-authored-by: Matthew Leibowitz <[email protected]>
Co-authored-by: Shane Neuville <[email protected]>
  • Loading branch information
4 people authored and TJ Lambert committed Feb 21, 2023
1 parent 7d75a47 commit 8125970
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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
27 changes: 27 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,7 @@
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;
Expand Down Expand Up @@ -35,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

0 comments on commit 8125970

Please sign in to comment.