2016-03-22 23:02:25 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2017-03-07 22:56:24 +03:00
|
|
|
using Xamarin.Forms.Internals;
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
namespace Xamarin.Forms.Platform.Android
|
|
|
|
{
|
|
|
|
internal class TapGestureHandler
|
|
|
|
{
|
2018-05-07 21:02:28 +03:00
|
|
|
public TapGestureHandler(Func<View> getView, Func<IList<GestureElement>> getChildElements)
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
|
|
|
GetView = getView;
|
2018-05-07 21:02:28 +03:00
|
|
|
GetChildElements = getChildElements;
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 21:02:28 +03:00
|
|
|
Func<IList<GestureElement>> GetChildElements { get; }
|
2016-03-22 23:02:25 +03:00
|
|
|
Func<View> GetView { get; }
|
|
|
|
|
|
|
|
public void OnSingleClick()
|
|
|
|
{
|
|
|
|
// only handle click if we don't have double tap registered
|
|
|
|
if (TapGestureRecognizers(2).Any())
|
|
|
|
return;
|
|
|
|
|
2018-05-07 21:02:28 +03:00
|
|
|
OnTap(1, new Point(-1, -1));
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 21:02:28 +03:00
|
|
|
public bool OnTap(int count, Point point)
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
|
|
|
View view = GetView();
|
|
|
|
|
|
|
|
if (view == null)
|
|
|
|
return false;
|
|
|
|
|
2018-05-07 21:02:28 +03:00
|
|
|
var captured = false;
|
|
|
|
|
|
|
|
var children = view.GetChildElements(point);
|
|
|
|
|
|
|
|
if (children != null)
|
|
|
|
foreach (var recognizer in children.GetChildGesturesFor<TapGestureRecognizer>(recognizer => recognizer.NumberOfTapsRequired == count))
|
|
|
|
{
|
|
|
|
recognizer.SendTapped(view);
|
|
|
|
captured = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (captured)
|
|
|
|
return captured;
|
|
|
|
|
2016-03-22 23:02:25 +03:00
|
|
|
IEnumerable<TapGestureRecognizer> gestureRecognizers = TapGestureRecognizers(count);
|
2018-05-07 21:02:28 +03:00
|
|
|
foreach (var gestureRecognizer in gestureRecognizers)
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
|
|
|
gestureRecognizer.SendTapped(view);
|
2018-05-07 21:02:28 +03:00
|
|
|
captured = true;
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 21:02:28 +03:00
|
|
|
return captured;
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 21:49:19 +03:00
|
|
|
public bool HasAnyGestures()
|
|
|
|
{
|
|
|
|
var view = GetView();
|
2018-05-07 21:02:28 +03:00
|
|
|
return view != null && view.GestureRecognizers.OfType<TapGestureRecognizer>().Any()
|
|
|
|
|| GetChildElements().GetChildGesturesFor<TapGestureRecognizer>().Any();
|
2017-09-15 21:49:19 +03:00
|
|
|
}
|
|
|
|
|
2016-03-22 23:02:25 +03:00
|
|
|
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);
|
|
|
|
}
|
2018-05-07 21:02:28 +03:00
|
|
|
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
}
|