blob: 800a967e0dbe60e7361cfb375868249e9a04ec01 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
using System;
namespace Xamarin.Forms.Platform.Android
{
public static class VisualElementExtensions
{
public static IVisualElementRenderer GetRenderer(this VisualElement self)
{
if (self == null)
throw new ArgumentNullException("self");
IVisualElementRenderer renderer = Platform.GetRenderer(self);
return renderer;
}
public static bool ShouldBeMadeClickable(this View view)
{
var shouldBeClickable = false;
for (var i = 0; i < view.GestureRecognizers.Count; i++)
{
IGestureRecognizer gesture = view.GestureRecognizers[i];
if (gesture is TapGestureRecognizer || gesture is PinchGestureRecognizer || gesture is PanGestureRecognizer)
{
shouldBeClickable = true;
break;
}
}
// do some evil
// This is required so that a layout only absorbs click events if it is not fully transparent
// However this is not desirable behavior in a ViewCell because it prevents the ViewCell from activating
if (view is Layout && view.BackgroundColor != Color.Transparent && view.BackgroundColor != Color.Default)
{
Element parent = view.RealParent;
var skip = false;
while (parent != null)
{
if (parent is ViewCell)
{
skip = true;
break;
}
parent = parent.RealParent;
}
if (!skip)
shouldBeClickable = true;
}
return shouldBeClickable;
}
}
}
|