Skip to content

TapGestureRecognizer Secondary ButtonMask only sort of works for Android #9653

Description

@PureWeen

Description

I've checked in a spike to the following branch android_secondary_click.

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

		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)
			{
			}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions