-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Implement PointerGestureRecognizer Buttons
#31214
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rebase this one to net10.0?
It also looks like you gained some extra unshipped.txt files
If you rebase this to net10.0 there's a cake target on net10.0
dotnet cake --target=publicapi that you can use to generate those
ea4a3d0 to
7d85abe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements mouse button differentiation in PointerGestureRecognizer by adding a new Buttons property that allows developers to specify which mouse buttons should trigger pointer events. Previously, only TapGestureRecognizer exposed button information but lacked pointer detection capabilities.
Key changes:
- Added
Buttonsproperty toPointerGestureRecognizerwithButtonsMaskenum support - Extended
PointerEventArgsto include button information for event handlers - Implemented platform-specific button detection across iOS, Android, and Windows
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/Controls/src/Core/PointerGestureRecognizer.cs |
Added Buttons property and updated internal methods to pass button information |
src/Controls/src/Core/PointerEventArgs.cs |
Added Button property to expose which mouse button triggered the event |
src/Controls/src/Core/Platform/iOS/CustomPressGestureRecognizer.cs |
Implemented iOS button detection using UIEventButtonMask for Mac Catalyst |
src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs |
Added right-click detection via fake context menu interaction for Mac Catalyst |
src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs |
Implemented Windows button detection using PointerUpdateKind and pointer properties |
src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Android.cs |
Updated to integrate pointer gesture handler with button detection |
src/Controls/src/Core/Platform/Android/PointerGestureHandler.cs |
Added comprehensive Android button detection using MotionEventButtonState |
src/Controls/tests/TestCases.HostApp/Issues/Issue24666.xaml |
Created test UI with three areas for testing different button configurations |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24666.cs |
Added automated tests for primary button behavior and button isolation |
src/Controls/tests/Core.UnitTests/Gestures/PointerGestureRecognizerTests.cs |
Comprehensive unit tests for the new Buttons property functionality |
src/Controls/src/Core/Platform/iOS/CustomPressGestureRecognizer.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@jsuarezruiz Thanks! I noticed this one too, I need to re-test with a mac to see what is wrong there. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs
Outdated
Show resolved
Hide resolved
src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs
Show resolved
Hide resolved
| [SupportedOSPlatform("ios13.0")] | ||
| [SupportedOSPlatform("maccatalyst13.0.0")] | ||
| [UnsupportedOSPlatform("tvos")] | ||
| internal class FakeRightClickPointerInteraction : UIContextMenuInteraction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FakeRightClickPointerInteraction holds a strong reference to delegate but no have a disposal mechanism.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @jsuarezruiz , I will make the adjustments. Should I add the disposal mechanism for the FakeRightClickContextMenuInteraction for TapGR as well?
… mask and refactor pointer event methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add public api comments to the released event for this behavior?
The secondary button press is implemented via a fake context menu (similar to TapGestureRecognizer), as there doesn’t appear to be any other reliable way to achieve this using UIKit UIEvent APIs. It currently fires the PointerReleased event right after the PointerPressed for Secondary option. Detecting a right-click directly would require using AppKit NSEvent for the desktop version. Any alternative solutions or feedback are welcome.

Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description of Change
Enables mouse button differentiation in PointerGestureRecognizer. This PR introduces support for detecting left and right mouse clicks in PointerGestureRecognizer via a new Buttons parameter. Previously, only TapGestureRecognizer exposed button info, but lacked pointer detection. This update allows developers to handle pointer down events with button specificity, enabling distinct actions for each mouse button.
Implementation Limitations
macOS/iOS
The secondary button press is implemented via a fake context menu (similar to
TapGestureRecognizer), as there doesn’t appear to be any other reliable way to achieve this using UIKit UIEvent APIs. It currently fires the PointerReleased event right after the PointerPressed for Secondary option. Detecting a right-click directly would require using AppKit NSEvent for the desktop version. Any alternative solutions or feedback are welcome.Tizen
Unsupported
Issues Fixed
Fixes #24666