Skip to content

Commit

Permalink
[Android] Added null checks (#21437)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaflo committed Apr 8, 2024
1 parent 998f884 commit 757f684
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues;

[XamlCompilation(XamlCompilationOptions.Compile)]
[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
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
23 changes: 23 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue21437.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.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]
public void ExceptionShouldNotBeThrown()
{
_ = App.WaitForElement("Item2");
App.DoubleClick("Item2");

//The test passes if no exception is thrown
}
}

0 comments on commit 757f684

Please sign in to comment.