Skip to content

Commit

Permalink
Fixed [Windows] TapGestureRecognizer not working on Entry (#25311)
Browse files Browse the repository at this point in the history
* [Windows] TapGestureRecognizer not working on Entry

* RemoveHandler added for tapped and double tapped event

* Test case committed

* snapshot for ios platform has committed

* Review correction committed

* Codes modified and committed

* Properly handled tapped and double tapped event handlers.

* code changes committed

* Snapshots committed

* Comment added for why Fails on mac attribute is added.

* Removed failsOnMac attribute

---------

Co-authored-by: Karthik Raja <[email protected]>
Co-authored-by: KarthikRajaKalaimani <[email protected]>
  • Loading branch information
3 people authored Nov 11, 2024
1 parent 8b96f6d commit d54be6f
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class GesturePlatformManager : IDisposable
FrameworkElement? _container;
FrameworkElement? _control;
VisualElement? _element;
TappedEventHandler? _tappedEventHandler;
DoubleTappedEventHandler? _doubleTappedEventHandler;

SubscriptionFlags _subscriptionFlags = SubscriptionFlags.None;

Expand Down Expand Up @@ -331,15 +333,17 @@ void ClearContainerEventHandlers()
{
_subscriptionFlags &= ~SubscriptionFlags.ContainerTapAndRightTabEventSubscribed;

_container.Tapped -= OnTap;
_container.RemoveHandler(FrameworkElement.TappedEvent, _tappedEventHandler);
_tappedEventHandler = null;
_container.RightTapped -= OnTap;
}

if ((_subscriptionFlags & SubscriptionFlags.ContainerDoubleTapEventSubscribed) != 0)
{
_subscriptionFlags &= ~SubscriptionFlags.ContainerDoubleTapEventSubscribed;

_container.DoubleTapped -= OnTap;
_container.RemoveHandler(FrameworkElement.DoubleTappedEvent, _doubleTappedEventHandler);
_doubleTappedEventHandler = null;
}

if ((_subscriptionFlags & SubscriptionFlags.ContainerPgrPointerEventsSubscribed) != 0)
Expand Down Expand Up @@ -779,8 +783,8 @@ void UpdatingGestureRecognizers()
|| children?.GetChildGesturesFor<TapGestureRecognizer>(g => g.NumberOfTapsRequired == 1).Any() == true)
{
_subscriptionFlags |= SubscriptionFlags.ContainerTapAndRightTabEventSubscribed;

_container.Tapped += OnTap;
_tappedEventHandler = new TappedEventHandler(OnTap);
_container.AddHandler(FrameworkElement.TappedEvent,_tappedEventHandler, true);
_container.RightTapped += OnTap;
}
else
Expand All @@ -796,8 +800,8 @@ void UpdatingGestureRecognizers()
|| children?.GetChildGesturesFor<TapGestureRecognizer>(g => g.NumberOfTapsRequired == 1 || g.NumberOfTapsRequired == 2).Any() == true)
{
_subscriptionFlags |= SubscriptionFlags.ContainerDoubleTapEventSubscribed;

_container.DoubleTapped += OnTap;
_doubleTappedEventHandler = new DoubleTappedEventHandler(OnTap);
_container.AddHandler(FrameworkElement.DoubleTappedEvent, _doubleTappedEventHandler, true);
}
else
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue12213.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.CustomAttributes;
using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 12213, "[Windows] TapGestureRecognizer not working on Entry", PlatformAffected.UWP)]
public class Issue12213 : TestContentPage
{

public Issue12213()
{
}

protected override void Init()
{
var stackLayout = new StackLayout();

var entry = new Entry();
entry.Placeholder = "Enter Your Name";
entry.AutomationId = "Entry";
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += TapGestureRecognizer_Tapped;
tapGestureRecognizer.NumberOfTapsRequired = 1;
entry.GestureRecognizers.Add(tapGestureRecognizer);
stackLayout.Children.Add(entry);
Content = stackLayout;
}

private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
{
DisplayAlert("Entry", "Tapped", "OK");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if !MACCATALYST
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue12213 : _IssuesUITest
{
public Issue12213(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "[Windows] TapGestureRecognizer not working on Entry";

[Test]
[Category(UITestCategories.Entry)]
[Category(UITestCategories.Gestures)]
public void TapGestureRecognizerNotWorkingOnEntry()
{
App.WaitForElement("Entry");
App.Tap("Entry");
VerifyScreenshot();
}
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d54be6f

Please sign in to comment.