summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS/GlobalCloseContextGestureRecognizer.cs
blob: fa76b982e47edd13942d7ee984284cc8371f38d0 (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
using System.Collections.Generic;
using System.Drawing;
#if __UNIFIED__
using Foundation;
using UIKit;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
#endif
#if __UNIFIED__
using RectangleF = CoreGraphics.CGRect;
using SizeF = CoreGraphics.CGSize;
using PointF = CoreGraphics.CGPoint;
using NSAction = System.Action;

#else
using nfloat=System.Single;
using nint=System.Int32;
#endif

namespace Xamarin.Forms.Platform.iOS
{
	internal class GlobalCloseContextGestureRecognizer : UIGestureRecognizer
	{
		List<UIButton> _buttons;
		UIScrollView _scrollView;

		public GlobalCloseContextGestureRecognizer(UIScrollView scrollView, List<UIButton> buttons, NSAction activated) : base(activated)
		{
			_scrollView = scrollView;
			_buttons = buttons;

			ShouldReceiveTouch = OnShouldReceiveTouch;
		}

		public override void TouchesBegan(NSSet touches, UIEvent evt)
		{
			State = UIGestureRecognizerState.Began;
			base.TouchesBegan(touches, evt);
		}

		public override void TouchesEnded(NSSet touches, UIEvent evt)
		{
			State = UIGestureRecognizerState.Recognized;
			base.TouchesEnded(touches, evt);
		}

		public override void TouchesMoved(NSSet touches, UIEvent evt)
		{
			State = UIGestureRecognizerState.Recognized;
			base.TouchesMoved(touches, evt);
		}

		protected override void Dispose(bool disposing)
		{
			base.Dispose(disposing);

			if (disposing)
			{
				_buttons = null;
				_scrollView = null;
			}
		}

		bool OnShouldReceiveTouch(UIGestureRecognizer r, UITouch t)
		{
			var scrollPos = t.LocationInView(_scrollView);
			var rect = new RectangleF(0, 0, _scrollView.ContentSize.Width, _scrollView.ContentSize.Height);
			return !rect.Contains(scrollPos);
		}
	}
}