diff --git a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs index 75a511c14e25..ba6d8a98f69c 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs @@ -608,6 +608,11 @@ void OnTap(object sender, RoutedEventArgs e) if (view == null) return; + if (!view.IsEnabled) + { + return; + } + var tapPosition = e.GetPositionRelativeToPlatformElement(Control); if (tapPosition == null) diff --git a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs index 758342768947..128878f5e566 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs @@ -757,6 +757,11 @@ public bool ShouldReceiveTouch(UIGestureRecognizer recognizer, UITouch touch) return false; } + if (!virtualView.IsEnabled) + { + return false; + } + if (touch.View == platformView) { return true; diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/GestureRecognizerUITests.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/GestureRecognizerUITests.cs index 5fd085c967df..d74956537c09 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/GestureRecognizerUITests.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/GestureRecognizerUITests.cs @@ -52,5 +52,35 @@ public void DoubleTap() var result = App.FindElement("DoubleTapResults").GetText(); ClassicAssert.AreEqual("Success", result); } + + [Test] + [Category(UITestCategories.Gestures)] + public void SingleTap() + { + App.WaitForElement("TargetView"); + App.EnterText("TargetView", "SingleTapGallery"); + App.Tap("GoButton"); + + App.WaitForElement("SingleTapSurface"); + App.Tap("SingleTapSurface"); + + var result = App.FindElement("SingleTapGestureResults").GetText(); + ClassicAssert.AreEqual("Success", result); + } + + [Test] + [Category(UITestCategories.Gestures)] + public void DisabledSingleTap() + { + App.WaitForElement("TargetView"); + App.EnterText("TargetView", "SingleTapGallery"); + App.Tap("GoButton"); + + App.WaitForElement("DisabledTapSurface"); + App.Tap("DisabledTapSurface"); + + var result = App.FindElement("DisabledTapGestureResults").GetText(); + ClassicAssert.AreNotEqual("Failed", result); + } } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases/Elements/GestureRecognizerGallery.cs b/src/Controls/tests/TestCases/Elements/GestureRecognizerGallery.cs index cca7d286762e..a433ed2f3338 100644 --- a/src/Controls/tests/TestCases/Elements/GestureRecognizerGallery.cs +++ b/src/Controls/tests/TestCases/Elements/GestureRecognizerGallery.cs @@ -11,6 +11,7 @@ public GestureRecognizerGallery() { Add(new PointerGestureRecognizerEvents()); Add(new DoubleTapGallery()); + Add(new SingleTapGallery()); } } } diff --git a/src/Controls/tests/TestCases/Elements/TapGestureGallery.cs b/src/Controls/tests/TestCases/Elements/TapGestureGallery.cs new file mode 100644 index 000000000000..1cc4028f0959 --- /dev/null +++ b/src/Controls/tests/TestCases/Elements/TapGestureGallery.cs @@ -0,0 +1,52 @@ +using Microsoft.Maui.Controls; + +namespace Maui.Controls.Sample +{ + public class SingleTapGallery : Microsoft.Maui.Controls.ContentView + { + public SingleTapGallery() + { + AutomationId = nameof(SingleTapGallery); + + var layout = new VerticalStackLayout { Margin = 10, Spacing = 10 }; + + var singleTapResults = new Label { AutomationId = "SingleTapGestureResults", Text = "Should succeed."}; + var singleTapSurface = new Grid() + { + HeightRequest = 100, + WidthRequest = 200, + BackgroundColor = Microsoft.Maui.Graphics.Colors.AliceBlue, + Children = { new Label { Text = "SingleTapSurface", AutomationId = "SingleTapSurface" } } + }; + + var singleTapRecognizer = new TapGestureRecognizer(); + singleTapRecognizer.Tapped += (sender, args) => { singleTapResults.Text = "Success"; }; + singleTapSurface.GestureRecognizers.Add(singleTapRecognizer); + + layout.Add(singleTapSurface); + layout.Add(singleTapResults); + + + // Now add a tap surface that is disabled and a results label that should not change when the surface is tapped + var disabledTapResults = new Label { AutomationId = "DisabledTapGestureResults", Text = "Should not change when tapped" }; + var disabledTapSurface = new Grid() + { + IsEnabled = false, // Disabled + HeightRequest = 100, + WidthRequest = 200, + BackgroundColor = Microsoft.Maui.Graphics.Colors.Bisque, + Children = { new Label { Text = "DisabledTapSurface", AutomationId = "DisabledTapSurface" } } + }; + + // Wire up the tap gesture recognizer, it should never fire + var disabledTapRecognizer = new TapGestureRecognizer(); + disabledTapRecognizer.Tapped += (sender, args) => { disabledTapResults.Text = "Failed"; }; + disabledTapSurface.GestureRecognizers.Add(disabledTapRecognizer); + + layout.Add(disabledTapSurface); + layout.Add(disabledTapResults); + + Content = layout; + } + } +} \ No newline at end of file