Skip to content

iOS two finger fix #12

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -48,7 +48,7 @@ class TouchRecognizer : UIGestureRecognizer
Microsoft.Maui.Controls.Element element; // Forms element for firing events
UIView view; // iOS UIView
MyTouchEffect touchPlatformEffect;

List<Point> xfPoints = new List<Point>();
static Dictionary<UIView, TouchRecognizer> viewDictionary = new();

static Dictionary<long, TouchRecognizer> idToTouchDictionary = new();
Expand Down Expand Up @@ -88,13 +88,15 @@ public override void TouchesMoved(NSSet touches, UIEvent evt)
{
base.TouchesMoved(touches, evt);

foreach (UITouch touch in touches.Cast<UITouch>())
var uitouches = touches.Cast<UITouch>().ToList();
foreach (UITouch touch in uitouches)
{
long id = ((IntPtr)touch.Handle).ToInt64();
CheckForBoundaryHop(touch);
if (idToTouchDictionary[id] != null)
{
FireEvent(idToTouchDictionary[id], id, TouchActionType.Moved, touch, true);
//FireEvent with all the points within the touch event
FireEvent(idToTouchDictionary[id], id, TouchActionType.Moved, touch, true, uitouches.IndexOf(touch) == uitouches.Count - 1);
Copy link
Member

Choose a reason for hiding this comment

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

I guess the same multi-point handling that you're using here should also be applied to the FireEvent calls in TouchesBegan and TouchesEnded ?

}
}
}
Expand Down Expand Up @@ -157,17 +159,22 @@ void CheckForBoundaryHop(UITouch touch)
}
}

void FireEvent(TouchRecognizer recognizer, long id, TouchActionType actionType, UITouch touch, bool isInContact)
void FireEvent(TouchRecognizer recognizer, long id, TouchActionType actionType, UITouch touch, bool isInContact, bool shouldFireEvent = true)
{
// Convert touch location to Maui Point value
CGPoint cgPoint = touch.LocationInView(recognizer.View);
Point xfPoint = new Point(cgPoint.X, cgPoint.Y);

//Add the points in a list and fireevent with all the points
xfPoints.Add(xfPoint);
// Get the method to call for firing events
var onTouchAction = recognizer.touchPlatformEffect.OnTouchAction;

// Call that method
onTouchAction(recognizer.element,
new TouchActionEventArgs(id, actionType, new[] { xfPoint }, isInContact));
if (shouldFireEvent)
{
// Call that method
onTouchAction(recognizer.element,
new TouchActionEventArgs(id, actionType, xfPoints.ToArray(), isInContact));
xfPoints.Clear();
}
}
}