TapGestureRecognizer Secondary ButtonMask only sort of works for Android
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
### Description
I've checked in a spike to the following branch [android_secondary_click](https://github.com/dotnet/maui/commit/5a3c3b3386a0f345c46b31a27988d8d1ed0b3063).
The right click action when you have a mouse attached to a tablet by default just navigates back.
It's a bit awkward because the right click fires through `KeyEvents` so you just repurpose the `Back` keybutton that originates from a mouse as a "secondary" click.
You also have to wire up to the `Click` event. You don't have to actually do anything inside the click event but you have to add a `clicklistener` for all this to wire up
```C#
void SetupGestures()
{
if (View == null)
return;
var platformView = Control;
if (platformView == null)
return;
if (View.GestureRecognizers.Count == 0)
{
platformView.Touch -= OnPlatformViewTouched;
platformView.KeyPress -= OnPlatformViewKeyPressed;
}
else
{
platformView.Touch += OnPlatformViewTouched;
platformView.KeyPress += OnPlatformViewKeyPressed;
bool testMe = platformView.HasOnClickListeners;
platformView.Click += PlatformView_Click;
}
}
void PlatformView_Click(object? sender, EventArgs e)
{
}
void OnPlatformViewKeyPressed(object? sender, AView.KeyEventArgs e)
{
if (_disposed)
{
var platformView = Control;
if (platformView != null)
{
platformView.Touch -= OnPlatformViewTouched;
platformView.KeyPress -= OnPlatformViewKeyPressed;
}
return;
}
if ((e.Event?.Source & InputSourceType.Mouse) == InputSourceType.Mouse && e.KeyCode == Keycode.Back)
{
}
```
Contributor guide
Research direction
Review the android_secondary_click spike, especially SetupGestures, PlatformView_Click, and OnPlatformViewKeyPressed, to understand how Android mouse key events and click listeners reach TapGestureRecognizer. Reproduce a secondary-button click on an Android tablet with a mouse, then verify that it triggers the secondary gesture instead of navigating back without requiring an empty Click handler.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, csharp
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 45/100