summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2017-06-21 05:13:06 -0600
committerRui Marinho <me@ruimarinho.net>2017-06-21 12:13:06 +0100
commitc6f547b298f95a35e5fa16eca6fd7b8b6a0a0920 (patch)
tree9d35af55c208010814a4f5a137efd93453e15bdc
parentc09603732916be56d27f21cea4ef1370057414bc (diff)
downloadxamarin-forms-c6f547b298f95a35e5fa16eca6fd7b8b6a0a0920.tar.gz
xamarin-forms-c6f547b298f95a35e5fa16eca6fd7b8b6a0a0920.tar.bz2
xamarin-forms-c6f547b298f95a35e5fa16eca6fd7b8b6a0a0920.zip
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
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla36780.cs85
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
-rw-r--r--Xamarin.Forms.Platform.iOS/EventTracker.cs46
3 files changed, 129 insertions, 3 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla36780.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla36780.cs
new file mode 100644
index 00000000..fbc5c3d3
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla36780.cs
@@ -0,0 +1,85 @@
+
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.UITest;
+using Xamarin.Forms.Core.UITests;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+#if UITEST
+ [Category(UITestCategories.Gestures)]
+#endif
+
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 36780, "[iOS] Multiple TapGestureRecognizers on an Object Are Not Fired", PlatformAffected.iOS)]
+ public class Bugzilla36780 : TestContentPage
+ {
+ const string Gesture1Success = "Gesture1Success";
+ const string Gesture2Success = "Gesture2Success";
+ const string Gesture3Success = "Gesture3Success";
+ const string Waiting = "Waiting";
+ const string TestImage = "TestImage";
+
+ protected override void Init()
+ {
+ var gesture1Label = new Label { FontSize = 18, Text = Waiting };
+ var gesture2Label = new Label { FontSize = 18, Text = Waiting };
+ var gesture3Label = new Label { FontSize = 18, Text = Waiting };
+
+ var testImage = new Image { Source = "coffee.png", AutomationId = TestImage, HeightRequest = 75 };
+
+ testImage.GestureRecognizers.Add(new TapGestureRecognizer
+ {
+ Command = new Command(() =>
+ {
+ gesture1Label.Text = Gesture1Success;
+ })
+ });
+
+ testImage.GestureRecognizers.Add(new TapGestureRecognizer
+ {
+ Command = new Command(() =>
+ {
+ gesture2Label.Text = Gesture2Success;
+ })
+ });
+
+ testImage.GestureRecognizers.Add(new TapGestureRecognizer
+ {
+ Command = new Command(() =>
+ {
+ gesture3Label.Text = Gesture3Success;
+ })
+ });
+
+ Content = new StackLayout
+ {
+ Padding = new Thickness(0, 20, 0, 0),
+ Children =
+ {
+ gesture1Label,
+ gesture2Label,
+ gesture3Label,
+ testImage
+ }
+ };
+ }
+
+#if UITEST
+ [Test]
+ public void MultipleTapGestures()
+ {
+ RunningApp.WaitForElement(TestImage);
+ RunningApp.Tap(TestImage);
+
+ RunningApp.WaitForElement(Gesture1Success);
+ RunningApp.WaitForElement(Gesture2Success);
+ RunningApp.WaitForElement(Gesture3Success);
+ }
+#endif
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index 5d2cd7b2..91515ed3 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -83,6 +83,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla36649.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla36559.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla36171.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla36780.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla36703.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla36846.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla36955.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<NSPanGestureRecognizer> action)
{