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

[iOS] TapGestureRecognizer should not fire when view is not enabled #23049

Merged
merged 5 commits into from
Jun 18, 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 @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,11 @@ public bool ShouldReceiveTouch(UIGestureRecognizer recognizer, UITouch touch)
return false;
}

if (!virtualView.IsEnabled)
{
return false;
}

if (touch.View == platformView)
{
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public GestureRecognizerGallery()
{
Add(new PointerGestureRecognizerEvents());
Add(new DoubleTapGallery());
Add(new SingleTapGallery());
}
}
}
Expand Down
52 changes: 52 additions & 0 deletions src/Controls/tests/TestCases/Elements/TapGestureGallery.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Loading