Skip to content
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

Secondary ButtonMask #9589

Merged
merged 13 commits into from
Aug 25, 2022
Merged

Secondary ButtonMask #9589

merged 13 commits into from
Aug 25, 2022

Conversation

PureWeen
Copy link
Member

@PureWeen PureWeen commented Aug 22, 2022

Description of Change

This adds ButtonMask to TapGestureRecognizer which allows users to indicate if they want secondary and/or primary to trigger the gesture.

  • Secondary currently won't work with "NumberOfTapsRequired"
  • Remove ClickGestureRecognizer. This wasn't hooked up to anything in .NET MAUI so we're not removing any behavior by deleting this recognizer. It seems a bit excessive and confusing to have a separate recognizer here. Once we get to a point where a user will need to determinate the type of device triggering a Tap we can just add an enum or similar.

Status

  • Currently works only for WinUI. Feel free to review and merge this PR in it current state so the APIs can get in for NET 7.0

API Changes

Maui.Controls

namespace Microsoft.Maui.Controls
{
	public sealed class TapGestureRecognizer : GestureRecognizer
	{
		public static readonly BindableProperty ButtonsProperty = BindableProperty.Create(nameof(Buttons), typeof(ButtonsMask), typeof(TapGestureRecognizer), ButtonsMask.Primary);
namespace Microsoft.Maui.Controls
{	
        public class TappedEventArgs : EventArgs
	{
		// Allow users to request the location of the tap relative to any view 
		 public Point? GetPosition(Element? relativeTo);

		public ButtonsMask Buttons { get; private set; }

		// This was just EventHandler? Tapped.
		public event EventHandler<TappedEventArgs>? Tapped;

Issues Fixed

Fixes #9140

}

/// <include file="../../docs/Microsoft.Maui.Controls/ClickGestureRecognizer.xml" path="Type[@FullName='Microsoft.Maui.Controls.ClickGestureRecognizer']/Docs" />
public sealed class ClickGestureRecognizer : GestureRecognizer
Copy link
Member Author

Choose a reason for hiding this comment

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

This was only wired up to GTK and macOS in XF. Currently in .NET MAUI this gesture does nothing anywhere. I think just condensing down into the TapGestureRecognizer here makes the most sense.

@PureWeen PureWeen force-pushed the buttonmasks branch 2 times, most recently from f52c024 to cfc17c5 Compare August 23, 2022 14:51
@PureWeen PureWeen marked this pull request as ready for review August 23, 2022 17:41
@PureWeen PureWeen marked this pull request as draft August 23, 2022 17:41
@@ -563,5 +599,51 @@ void OnElementChanged(object sender, VisualElementChangedEventArgs e)
}
}
}

ButtonsMask AddFakeRightClickForMacCatalyst(IGestureRecognizer recognizer)
Copy link
Member Author

Choose a reason for hiding this comment

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

Most the changes in this file are organizational. There seemed to be a lot of duplicated code added to process spans. I needed that same code generalized so I could use it from a UIContextMenu.

The code here is the main code required to make right click fire an event on catalyst.

// it only works when you have a mouse connected to an iPad
// so we just ignore setting the mask if the user is running catalyst
// right click is handled by adding a UIContextMenu interaction
if (OperatingSystem.IsIOSVersionAtLeast(13, 4) && !OperatingSystem.IsMacCatalyst())
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the other functional addition to the code. Most of the other changes in this file are organizational

@PureWeen PureWeen marked this pull request as ready for review August 23, 2022 22:11
@PureWeen PureWeen marked this pull request as draft August 23, 2022 22:51
@PureWeen PureWeen marked this pull request as ready for review August 24, 2022 16:56
@jfversluis jfversluis added the area-xaml XAML, CSS, Triggers, Behaviors label Aug 24, 2022
Copy link
Contributor

@hartez hartez left a comment

Choose a reason for hiding this comment

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

Looks pretty good, a few small things.


internal void SendTapped(View sender)
internal void SendTapped(View sender, Func<IElement?, Point?>? getPosition)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can getPosition default to null and reduce the noise of all the SendTapped(..., null) calls?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Also @rookiejava FYI if you want to extend your usages of "SendTapped" to provide location data.

@PureWeen PureWeen requested a review from hartez August 24, 2022 21:03
@PureWeen PureWeen enabled auto-merge (squash) August 25, 2022 00:26
@PureWeen PureWeen merged commit 67e3562 into main Aug 25, 2022
@PureWeen PureWeen deleted the buttonmasks branch August 25, 2022 14:42

bool CheckButtonMask(TapGestureRecognizer tapGestureRecognizer, MotionEvent? motionEvent)
{
if (tapGestureRecognizer.Buttons == ButtonsMask.Secondary)
Copy link
Member Author

Choose a reason for hiding this comment

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

set { SetValue(ButtonsProperty, value); }
}

public event EventHandler<TappedEventArgs>? Tapped;
Copy link
Contributor

Choose a reason for hiding this comment

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

So @PureWeen was this meant to be a breaking change hosing any .NET 6 components?
image

@github-actions github-actions bot locked and limited conversation to collaborators Dec 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-7.0.0-rc.1.6683
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Right click gesture recognizer
5 participants