maui-linux/Xamarin.Forms.Platform.Android/TapGestureHandler.cs

76 строки
1.8 KiB
C#
Исходник Обычный вид История

2016-03-22 23:02:25 +03:00
using System;
using System.Collections.Generic;
using System.Linq;
using Xamarin.Forms.Internals;
2016-03-22 23:02:25 +03:00
namespace Xamarin.Forms.Platform.Android
{
internal class TapGestureHandler
{
public TapGestureHandler(Func<View> getView, Func<IList<GestureElement>> getChildElements)
2016-03-22 23:02:25 +03:00
{
GetView = getView;
GetChildElements = getChildElements;
2016-03-22 23:02:25 +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;
OnTap(1, new Point(-1, -1));
2016-03-22 23:02:25 +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;
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);
foreach (var gestureRecognizer in gestureRecognizers)
2016-03-22 23:02:25 +03:00
{
gestureRecognizer.SendTapped(view);
captured = true;
2016-03-22 23:02:25 +03:00
}
return captured;
2016-03-22 23:02:25 +03:00
}
public bool HasAnyGestures()
{
var view = GetView();
return view != null && view.GestureRecognizers.OfType<TapGestureRecognizer>().Any()
|| GetChildElements().GetChildGesturesFor<TapGestureRecognizer>().Any();
}
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);
}
2016-03-22 23:02:25 +03:00
}
}