Skip to content

Commit 035511a

Browse files
HarishwaranVijayakumarPureWeen
authored andcommitted
Fix for TapGestureRecognizer ButtonMask always return 0 (#30372)
* Fix for TapGesture ButtonMask * Added TestCase * Update Testcase * Modified Testcase
1 parent 298026e commit 035511a

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

src/Controls/src/Core/TapGestureRecognizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ internal void SendTapped(View sender, Func<IElement?, Point?>? getPosition = nul
5959
if (cmd != null && cmd.CanExecute(CommandParameter))
6060
cmd.Execute(CommandParameter);
6161

62-
Tapped?.Invoke(sender, new TappedEventArgs(CommandParameter, getPosition));
62+
Tapped?.Invoke(sender, new TappedEventArgs(CommandParameter, getPosition, Buttons));
6363
}
6464

6565
}

src/Controls/src/Core/TappedEventArgs.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ public TappedEventArgs(object? parameter)
1414
Parameter = parameter;
1515
}
1616

17-
internal TappedEventArgs(object? parameter, Func<IElement?, Point?>? getPosition) : this(parameter)
17+
internal TappedEventArgs(object? parameter, Func<IElement?, Point?>? getPosition, ButtonsMask buttons) : this(parameter)
1818
{
1919
_getPosition = getPosition;
20+
Buttons = buttons;
2021
}
2122

2223
/// <include file="../../docs/Microsoft.Maui.Controls/TappedEventArgs.xml" path="//Member[@MemberName='Parameter']/Docs/*" />
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 24734, "TapGestureRecognizer ButtonMask always return 0", PlatformAffected.All)]
4+
public class Issue24734 : ContentPage
5+
{
6+
public Issue24734()
7+
{
8+
VerticalStackLayout stackLayout = new VerticalStackLayout
9+
{
10+
Spacing = 20,
11+
Padding = new Thickness(20)
12+
};
13+
14+
Label label = new Label
15+
{
16+
Text = "Failure",
17+
AutomationId = "LabelwithGesture",
18+
};
19+
20+
TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer
21+
{
22+
Buttons = ButtonsMask.Primary
23+
};
24+
25+
tapGestureRecognizer.Tapped += (sender, e) =>
26+
{
27+
if (e.Buttons == ButtonsMask.Primary)
28+
{
29+
label.Text = "Success";
30+
}
31+
};
32+
33+
label.GestureRecognizers.Add(tapGestureRecognizer);
34+
stackLayout.Add(label);
35+
Content = stackLayout;
36+
}
37+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
7+
public class Issue24734 : _IssuesUITest
8+
{
9+
public Issue24734(TestDevice device) : base(device)
10+
{
11+
}
12+
13+
public override string Issue => "TapGestureRecognizer ButtonMask always return 0";
14+
15+
[Test]
16+
[Category(UITestCategories.Gestures)]
17+
public void ButtonMaskShouldNotReturnZero()
18+
{
19+
App.WaitForElement("LabelwithGesture");
20+
App.Tap("LabelwithGesture");
21+
App.WaitForElement("Success");
22+
}
23+
}

0 commit comments

Comments
 (0)