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

Fix PointerGestureHandler not registering touches on android #22109

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Microsoft.Maui.Controls.Platform
{
internal class PointerGestureHandler : Java.Lang.Object, AView.IOnHoverListener
internal class PointerGestureHandler : Java.Lang.Object, AView.IOnHoverListener, AView.IOnTouchListener
{
internal PointerGestureHandler(Func<View> getView, Func<AView> getControl)
{
Expand Down Expand Up @@ -50,6 +50,34 @@ public bool OnHover(AView control, MotionEvent e)
return false;
}

public bool OnTouch(AView control, MotionEvent e)
{
var view = GetView();
if (view == null)
return false;

var platformPointerArgs = new PlatformPointerEventArgs(control, e);

foreach (var gesture in view.GetCompositeGestureRecognizers())
{
var pgr = gesture as PointerGestureRecognizer;
switch (e.Action)
{
case MotionEventActions.Move:
pgr.SendPointerMoved(view, (relativeTo) => e.CalculatePosition(GetView(), relativeTo), platformPointerArgs);
break;
case MotionEventActions.Down:
pgr.SendPointerPressed(view, (relativeTo) => e.CalculatePosition(GetView(), relativeTo), platformPointerArgs);
break;
case MotionEventActions.Up:
pgr.SendPointerReleased(view, (relativeTo) => e.CalculatePosition(GetView(), relativeTo), platformPointerArgs);
break;
}
}

return true;
}

public void SetupHandlerForPointer()
{
var view = GetView();
Expand All @@ -61,9 +89,15 @@ public void SetupHandlerForPointer()
return;

if (HasAnyPointerGestures())
{
control.SetOnHoverListener(this);
control.SetOnTouchListener(this);
}
else
{
control.SetOnHoverListener(null);
control.SetOnTouchListener(null);
}

return;
}
Expand Down
Binary file modified src/Core/src/maui.aar
Binary file not shown.
Loading