blob: bc06531cf74de276113764a3fe61690425c70ea2 (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
using System;
using System.Linq;
namespace Xamarin.Forms.Platform.Android
{
internal class PinchGestureHandler
{
double _pinchStartingScale = 1;
public PinchGestureHandler(Func<View> getView)
{
GetView = getView;
}
public bool IsPinchSupported
{
get
{
View view = GetView();
return view != null && view.GestureRecognizers.GetGesturesFor<PinchGestureRecognizer>().Any();
}
}
Func<View> GetView { get; }
// A View can have at most one pinch gesture, so we just need to look for one (or none)
PinchGestureRecognizer PinchGesture => GetView()?.GestureRecognizers.GetGesturesFor<PinchGestureRecognizer>().FirstOrDefault();
public bool OnPinch(float scale, Point scalePoint)
{
View view = GetView();
if (view == null)
return false;
PinchGestureRecognizer pinchGesture = PinchGesture;
if (pinchGesture == null)
return true;
var scalePointTransformed = new Point(scalePoint.X / view.Width, scalePoint.Y / view.Height);
((IPinchGestureController)pinchGesture).SendPinch(view, 1 + (scale - 1) * _pinchStartingScale, scalePointTransformed);
return true;
}
public void OnPinchEnded()
{
View view = GetView();
if (view == null)
return;
PinchGestureRecognizer pinchGesture = PinchGesture;
((IPinchGestureController)pinchGesture)?.SendPinchEnded(view);
}
public bool OnPinchStarted(Point scalePoint)
{
View view = GetView();
if (view == null)
return false;
PinchGestureRecognizer pinchGesture = PinchGesture;
if (pinchGesture == null)
return false;
_pinchStartingScale = view.Scale;
var scalePointTransformed = new Point(scalePoint.X / view.Width, scalePoint.Y / view.Height);
((IPinchGestureController)pinchGesture).SendPinchStarted(view, scalePointTransformed);
return true;
}
}
}
|