From c6f547b298f95a35e5fa16eca6fd7b8b6a0a0920 Mon Sep 17 00:00:00 2001 From: "E.Z. Hart" Date: Wed, 21 Jun 2017 05:13:06 -0600 Subject: Allow multiple tap gestures to fire simultaneously on iOS (#964) * Allow multiple tap gestures to fire simultaneously on iOS * Verify that the tap came from the same UIView --- Xamarin.Forms.Platform.iOS/EventTracker.cs | 46 ++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'Xamarin.Forms.Platform.iOS/EventTracker.cs') diff --git a/Xamarin.Forms.Platform.iOS/EventTracker.cs b/Xamarin.Forms.Platform.iOS/EventTracker.cs index 5b2156c9..7be924a8 100644 --- a/Xamarin.Forms.Platform.iOS/EventTracker.cs +++ b/Xamarin.Forms.Platform.iOS/EventTracker.cs @@ -254,11 +254,51 @@ namespace Xamarin.Forms.Platform.MacOS UITapGestureRecognizer CreateTapRecognizer(int numTaps, Action action, int numFingers = 1) { - var result = new UITapGestureRecognizer(action); - result.NumberOfTouchesRequired = (uint)numFingers; - result.NumberOfTapsRequired = (uint)numTaps; + var result = new UITapGestureRecognizer(action) + { + NumberOfTouchesRequired = (uint)numFingers, + NumberOfTapsRequired = (uint)numTaps, + ShouldRecognizeSimultaneously = ShouldRecognizeTapsTogether + }; + return result; } + + static bool ShouldRecognizeTapsTogether(NativeGestureRecognizer gesture, NativeGestureRecognizer other) + { + // If multiple tap gestures are potentially firing (because multiple tap gesture recognizers have been + // added to the XF Element), we want to allow them to fire simultaneously if they have the same number + // of taps and touches + + var tap = gesture as UITapGestureRecognizer; + if (tap == null) + { + return false; + } + + var otherTap = other as UITapGestureRecognizer; + if (otherTap == null) + { + return false; + } + + if (!Equals(tap.View, otherTap.View)) + { + return false; + } + + if (tap.NumberOfTapsRequired != otherTap.NumberOfTapsRequired) + { + return false; + } + + if (tap.NumberOfTouchesRequired != otherTap.NumberOfTouchesRequired) + { + return false; + } + + return true; + } #else NSPanGestureRecognizer CreatePanRecognizer(int numTouches, Action action) { -- cgit v1.2.3