summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/TapGestureHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.Android/TapGestureHandler.cs')
-rw-r--r--Xamarin.Forms.Platform.Android/TapGestureHandler.cs52
1 files changed, 52 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android/TapGestureHandler.cs b/Xamarin.Forms.Platform.Android/TapGestureHandler.cs
new file mode 100644
index 00000000..dcd8d6f7
--- /dev/null
+++ b/Xamarin.Forms.Platform.Android/TapGestureHandler.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Xamarin.Forms.Platform.Android
+{
+ internal class TapGestureHandler
+ {
+ public TapGestureHandler(Func<View> getView)
+ {
+ GetView = getView;
+ }
+
+ Func<View> GetView { get; }
+
+ public void OnSingleClick()
+ {
+ // only handle click if we don't have double tap registered
+ if (TapGestureRecognizers(2).Any())
+ return;
+
+ OnTap(1);
+ }
+
+ public bool OnTap(int count)
+ {
+ View view = GetView();
+
+ if (view == null)
+ return false;
+
+ IEnumerable<TapGestureRecognizer> gestureRecognizers = TapGestureRecognizers(count);
+ var result = false;
+ foreach (TapGestureRecognizer gestureRecognizer in gestureRecognizers)
+ {
+ gestureRecognizer.SendTapped(view);
+ result = true;
+ }
+
+ return result;
+ }
+
+ public IEnumerable<TapGestureRecognizer> TapGestureRecognizers(int count)
+ {
+ View view = GetView();
+ if (view == null)
+ return Enumerable.Empty<TapGestureRecognizer>();
+
+ return view.GestureRecognizers.GetGesturesFor<TapGestureRecognizer>(recognizer => recognizer.NumberOfTapsRequired == count);
+ }
+ }
+} \ No newline at end of file