Skip to content

Conversation

@morning4coffe-dev
Copy link
Contributor

@morning4coffe-dev morning4coffe-dev commented Aug 18, 2025

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

Copy link
Member

@PureWeen PureWeen left a 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

@morning4coffe-dev morning4coffe-dev changed the base branch from main to net10.0 August 20, 2025 14:32
@morning4coffe-dev morning4coffe-dev force-pushed the pointergesturerecognizer-buttons branch from ea4a3d0 to 7d85abe Compare August 20, 2025 14:35
@PureWeen PureWeen added this to the .NET 10.0-rc2 milestone Aug 20, 2025
@morning4coffe-dev morning4coffe-dev marked this pull request as ready for review August 27, 2025 13:36
Copilot AI review requested due to automatic review settings August 27, 2025 13:36
@morning4coffe-dev morning4coffe-dev requested a review from a team as a code owner August 27, 2025 13:36
Copy link
Contributor

Copilot AI left a 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 Buttons property to PointerGestureRecognizer with ButtonsMask enum support
  • Extended PointerEventArgs to 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

Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test SecondaryAreaDoesNotReactToPrimaryTap fails on iOS and Mac:
image

Assert.That(after, Is.EqualTo(before))
Expected: 0
But was:  1

@github-project-automation github-project-automation bot moved this from Todo to Changes Requested in MAUI SDK Ongoing Aug 28, 2025
@morning4coffe-dev
Copy link
Contributor Author

@jsuarezruiz Thanks! I noticed this one too, I need to re-test with a mac to see what is wrong there.

@PureWeen PureWeen added the p/0 Work that we can't release without label Aug 31, 2025
morning4coffe-dev and others added 2 commits September 4, 2025 11:20
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jsuarezruiz jsuarezruiz added the area-gestures Gesture types label Sep 5, 2025
[SupportedOSPlatform("ios13.0")]
[SupportedOSPlatform("maccatalyst13.0.0")]
[UnsupportedOSPlatform("tvos")]
internal class FakeRightClickPointerInteraction : UIContextMenuInteraction
Copy link
Contributor

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.

Copy link
Contributor Author

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?

@github-project-automation github-project-automation bot moved this from Changes Requested to Done in MAUI SDK Ongoing Sep 5, 2025
@github-project-automation github-project-automation bot moved this from Done to In Progress in MAUI SDK Ongoing Sep 5, 2025
@PureWeen PureWeen moved this from In Progress to Ready To Review in MAUI SDK Ongoing Sep 10, 2025
jsuarezruiz
jsuarezruiz previously approved these changes Sep 12, 2025
@jsuarezruiz jsuarezruiz self-requested a review September 12, 2025 08:23
@github-project-automation github-project-automation bot moved this from Ready To Review to Approved in MAUI SDK Ongoing Sep 15, 2025
Copy link
Member

@PureWeen PureWeen left a 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.

@github-project-automation github-project-automation bot moved this from Approved to Changes Requested in MAUI SDK Ongoing Sep 15, 2025
@PureWeen PureWeen moved this from Changes Requested to Ready To Review in MAUI SDK Ongoing Sep 15, 2025
@github-project-automation github-project-automation bot moved this from Ready To Review to Approved in MAUI SDK Ongoing Sep 15, 2025
@PureWeen PureWeen merged commit ae56939 into net10.0 Sep 16, 2025
144 of 148 checks passed
@PureWeen PureWeen deleted the pointergesturerecognizer-buttons branch September 16, 2025 07:52
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Sep 16, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Oct 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-gestures Gesture types p/0 Work that we can't release without

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Differentiate Left/Right click in PointerGestureRecognizer

4 participants