From 757f684b8d1d75c13af0dc106361ded8b4fb8425 Mon Sep 17 00:00:00 2001 From: Jakub Florkowski Date: Tue, 9 Apr 2024 00:47:59 +0200 Subject: [PATCH] [Android] Added null checks (#21437) --- .../Issues/Issue21437.xaml | 21 ++++++++++++++++ .../Issues/Issue21437.xaml.cs | 24 +++++++++++++++++++ .../Platform/Android/InnerGestureListener.cs | 2 +- .../tests/UITests/Tests/Issues/Issue21437.cs | 23 ++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/Controls/samples/Controls.Sample.UITests/Issues/Issue21437.xaml create mode 100644 src/Controls/samples/Controls.Sample.UITests/Issues/Issue21437.xaml.cs create mode 100644 src/Controls/tests/UITests/Tests/Issues/Issue21437.cs diff --git a/src/Controls/samples/Controls.Sample.UITests/Issues/Issue21437.xaml b/src/Controls/samples/Controls.Sample.UITests/Issues/Issue21437.xaml new file mode 100644 index 000000000000..d54f9cee7400 --- /dev/null +++ b/src/Controls/samples/Controls.Sample.UITests/Issues/Issue21437.xaml @@ -0,0 +1,21 @@ + + + + + + + + + + diff --git a/src/Controls/samples/Controls.Sample.UITests/Issues/Issue21437.xaml.cs b/src/Controls/samples/Controls.Sample.UITests/Issues/Issue21437.xaml.cs new file mode 100644 index 000000000000..89ddb090ea80 --- /dev/null +++ b/src/Controls/samples/Controls.Sample.UITests/Issues/Issue21437.xaml.cs @@ -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 Items { get; } = new() { "Item1", "Item2", "Item3" }; + + public Command TapCommand => new Command(obj => + { + Items.Remove(obj); + }); + + public Issue21437() + { + InitializeComponent(); + BindingContext = this; + } +} diff --git a/src/Controls/src/Core/Platform/Android/InnerGestureListener.cs b/src/Controls/src/Core/Platform/Android/InnerGestureListener.cs index 5d9d1ced94aa..9c6ef68c7f14 100644 --- a/src/Controls/src/Core/Platform/Android/InnerGestureListener.cs +++ b/src/Controls/src/Core/Platform/Android/InnerGestureListener.cs @@ -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 diff --git a/src/Controls/tests/UITests/Tests/Issues/Issue21437.cs b/src/Controls/tests/UITests/Tests/Issues/Issue21437.cs new file mode 100644 index 000000000000..ff4fe0abd8ad --- /dev/null +++ b/src/Controls/tests/UITests/Tests/Issues/Issue21437.cs @@ -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 + } +}