Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Removing TapGestureRecognizer with at least 2 taps causes Exception - fix #21714

Merged
merged 4 commits into from
Aug 17, 2024
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 @@ -62,7 +62,7 @@ public InnerGestureListener(

bool HasAnyGestures()
{
return _panGestureHandler.HasAnyGestures() || _tapGestureHandler.HasAnyGestures() || _swipeGestureHandler.HasAnyGestures();
return (_panGestureHandler?.HasAnyGestures() ?? false) || (_tapGestureHandler?.HasAnyGestures() ?? false) || (_swipeGestureHandler?.HasAnyGestures() ?? false);
}

// This is needed because GestureRecognizer callbacks can be delayed several hundred milliseconds
Expand Down
21 changes: 21 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue21437.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue21437"
xmlns:issues="clr-namespace:Maui.Controls.Sample.Issues"
Title="Issue21437">
<VerticalStackLayout BindableLayout.ItemsSource="{Binding Items}" HorizontalOptions="Start">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Label Text="{Binding .}" AutomationId="{Binding .}" HorizontalOptions="Start">
<Label.GestureRecognizers>
<TapGestureRecognizer
NumberOfTapsRequired="2"
Command="{Binding TapCommand, Source={RelativeSource AncestorType={x:Type issues:Issue21437}}}"
CommandParameter="{Binding .}" />
</Label.GestureRecognizers>
</Label>
</DataTemplate>
</BindableLayout.ItemTemplate>
</VerticalStackLayout>
</ContentPage>
21 changes: 21 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue21437.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 21437, "Removing TapGestureRecognizer with at least 2 taps causes Exception", PlatformAffected.Android)]

public partial class Issue21437 : ContentPage
{
public ObservableCollection<string> Items { get; } = new() { "Item1", "Item2", "Item3" };

public Command TapCommand => new Command<string>(obj =>
{
Items.Remove(obj);
});

public Issue21437()
{
InitializeComponent();
BindingContext = this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#if ANDROID
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue21437 : _IssuesUITest
{
public override string Issue => "Removing TapGestureRecognizer with at least 2 taps causes Exception";

public Issue21437(TestDevice device)
: base(device)
{ }

[Test]
[Category(UITestCategories.Gestures)]
public void ExceptionShouldNotBeThrown()
{
_ = App.WaitForElement("Item2");
App.DoubleClick("Item2");

//The test passes if no exception is thrown
}
}
#endif
Loading