Skip to content

Commit d54be6f

Browse files
Fixed [Windows] TapGestureRecognizer not working on Entry (dotnet#25311)
* [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]>
1 parent 8b96f6d commit d54be6f

File tree

6 files changed

+72
-6
lines changed

6 files changed

+72
-6
lines changed

src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class GesturePlatformManager : IDisposable
2121
FrameworkElement? _container;
2222
FrameworkElement? _control;
2323
VisualElement? _element;
24+
TappedEventHandler? _tappedEventHandler;
25+
DoubleTappedEventHandler? _doubleTappedEventHandler;
2426

2527
SubscriptionFlags _subscriptionFlags = SubscriptionFlags.None;
2628

@@ -331,15 +333,17 @@ void ClearContainerEventHandlers()
331333
{
332334
_subscriptionFlags &= ~SubscriptionFlags.ContainerTapAndRightTabEventSubscribed;
333335

334-
_container.Tapped -= OnTap;
336+
_container.RemoveHandler(FrameworkElement.TappedEvent, _tappedEventHandler);
337+
_tappedEventHandler = null;
335338
_container.RightTapped -= OnTap;
336339
}
337340

338341
if ((_subscriptionFlags & SubscriptionFlags.ContainerDoubleTapEventSubscribed) != 0)
339342
{
340343
_subscriptionFlags &= ~SubscriptionFlags.ContainerDoubleTapEventSubscribed;
341344

342-
_container.DoubleTapped -= OnTap;
345+
_container.RemoveHandler(FrameworkElement.DoubleTappedEvent, _doubleTappedEventHandler);
346+
_doubleTappedEventHandler = null;
343347
}
344348

345349
if ((_subscriptionFlags & SubscriptionFlags.ContainerPgrPointerEventsSubscribed) != 0)
@@ -779,8 +783,8 @@ void UpdatingGestureRecognizers()
779783
|| children?.GetChildGesturesFor<TapGestureRecognizer>(g => g.NumberOfTapsRequired == 1).Any() == true)
780784
{
781785
_subscriptionFlags |= SubscriptionFlags.ContainerTapAndRightTabEventSubscribed;
782-
783-
_container.Tapped += OnTap;
786+
_tappedEventHandler = new TappedEventHandler(OnTap);
787+
_container.AddHandler(FrameworkElement.TappedEvent,_tappedEventHandler, true);
784788
_container.RightTapped += OnTap;
785789
}
786790
else
@@ -796,8 +800,8 @@ void UpdatingGestureRecognizers()
796800
|| children?.GetChildGesturesFor<TapGestureRecognizer>(g => g.NumberOfTapsRequired == 1 || g.NumberOfTapsRequired == 2).Any() == true)
797801
{
798802
_subscriptionFlags |= SubscriptionFlags.ContainerDoubleTapEventSubscribed;
799-
800-
_container.DoubleTapped += OnTap;
803+
_doubleTappedEventHandler = new DoubleTappedEventHandler(OnTap);
804+
_container.AddHandler(FrameworkElement.DoubleTappedEvent, _doubleTappedEventHandler, true);
801805
}
802806
else
803807
{
83.7 KB
Loading
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Microsoft.Maui.Controls;
2+
using Microsoft.Maui.Controls.CustomAttributes;
3+
using Microsoft.Maui.Graphics;
4+
5+
namespace Maui.Controls.Sample.Issues
6+
{
7+
[Issue(IssueTracker.Github, 12213, "[Windows] TapGestureRecognizer not working on Entry", PlatformAffected.UWP)]
8+
public class Issue12213 : TestContentPage
9+
{
10+
11+
public Issue12213()
12+
{
13+
}
14+
15+
protected override void Init()
16+
{
17+
var stackLayout = new StackLayout();
18+
19+
var entry = new Entry();
20+
entry.Placeholder = "Enter Your Name";
21+
entry.AutomationId = "Entry";
22+
var tapGestureRecognizer = new TapGestureRecognizer();
23+
tapGestureRecognizer.Tapped += TapGestureRecognizer_Tapped;
24+
tapGestureRecognizer.NumberOfTapsRequired = 1;
25+
entry.GestureRecognizers.Add(tapGestureRecognizer);
26+
stackLayout.Children.Add(entry);
27+
Content = stackLayout;
28+
}
29+
30+
private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
31+
{
32+
DisplayAlert("Entry", "Tapped", "OK");
33+
}
34+
}
35+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#if !MACCATALYST
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Issues
7+
{
8+
public class Issue12213 : _IssuesUITest
9+
{
10+
public Issue12213(TestDevice testDevice) : base(testDevice)
11+
{
12+
}
13+
14+
public override string Issue => "[Windows] TapGestureRecognizer not working on Entry";
15+
16+
[Test]
17+
[Category(UITestCategories.Entry)]
18+
[Category(UITestCategories.Gestures)]
19+
public void TapGestureRecognizerNotWorkingOnEntry()
20+
{
21+
App.WaitForElement("Entry");
22+
App.Tap("Entry");
23+
VerifyScreenshot();
24+
}
25+
}
26+
}
27+
#endif
12.5 KB
Loading
83.1 KB
Loading

0 commit comments

Comments
 (0)