Skip to content

Commit

Permalink
[Android] Fix crash navigating back (dotnet#20420)
Browse files Browse the repository at this point in the history
* Fix the issue

* Added device test
  • Loading branch information
jsuarezruiz authored Apr 16, 2024
1 parent f99ab4b commit e2dd6a4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ internal PointerGestureHandler(Func<View> getView, Func<AView> getControl)
public bool OnHover(AView control, MotionEvent e)
{
var view = GetView();

if (view == null)
return false;

var platformPointerArgs = new PlatformPointerEventArgs(control, e);

foreach (var gesture in view.GetCompositeGestureRecognizers())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Threading.Tasks;
using Android.Views;
Expand All @@ -22,12 +22,67 @@
using static Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutTemplatedContentRenderer;
using static Microsoft.Maui.DeviceTests.AssertHelpers;
using AView = Android.Views.View;
using ShellHandler = Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer;

namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Shell)]
public partial class ShellTests
{
[Fact(DisplayName = "No crash going back using 'Shell.Current.GoToAsync(\"..\")'")]
public async Task GoingBackUsingGoToAsyncMethod()
{
SetupBuilder();

var page1 = new ContentPage();

var page2Content = new Label { Text = "Test" };
var page2 = new ContentPage { Content = page2Content };

var pointerGestureRecognizer = new PointerGestureRecognizer();
pointerGestureRecognizer.PointerPressed += (sender, args) =>
{
Console.WriteLine("Page Content pressed");
};

page2Content.GestureRecognizers.Add(pointerGestureRecognizer);

var shell = await CreateShellAsync((shell) =>
{
shell.Items.Add(new TabBar()
{
Items =
{
new ShellContent()
{
Route = "Item1",
Content = page1
},
new ShellContent()
{
Route = "Item2",
Content = page2
},
}
});
});

await CreateHandlerAndAddToWindow<ShellHandler>(shell, async (handler) =>
{
await OnLoadedAsync(page1);
await shell.GoToAsync("//Item2");
await shell.GoToAsync("..");
await shell.GoToAsync("//Item1");
await shell.GoToAsync("//Item2");
await shell.Navigation.PopAsync();
await shell.GoToAsync("//Item1");
await shell.GoToAsync("//Item2");
await shell.GoToAsync("..");
});
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down

0 comments on commit e2dd6a4

Please sign in to comment.