forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIEventExtensions.iOS.cs
More file actions
84 lines (70 loc) · 1.87 KB
/
Copy pathUIEventExtensions.iOS.cs
File metadata and controls
84 lines (70 loc) · 1.87 KB
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
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Text;
using CoreGraphics;
using UIKit;
using Uno.Extensions;
using Windows.Foundation;
using Windows.UI.Xaml;
namespace Uno.UI.Extensions
{
public static class UIEventExtensions
{
public static bool IsTouchInView(this UIEvent evt, UIView view)
{
var touch = evt?.AllTouches?.AnyObject as UITouch;
if (touch == null)
{
return false;
}
else
{
var window = UIApplication.SharedApplication.KeyWindow;
var screenLocation = touch.LocationInView(window);
var bounds = GetBounds(window, view);
return screenLocation.X >= bounds.X
&& screenLocation.Y >= bounds.Y
&& screenLocation.X < bounds.Right
&& screenLocation.Y < bounds.Bottom;
}
}
/// <summary>
/// Determines the bounds of the provided view, including the <see cref="UIElement.Clip"/>, using the window coordinate system.
/// </summary>
private static CGRect GetBounds(UIWindow window, UIView view)
{
CGRect? finalRect = null;
while (view != null)
{
if (view is UIScrollView)
{
// We don't support ScrollViewer clipping, because detecting
// the scrolling position and adjusting it makes it for unreliable
// calculations, for now.
view = view.Superview;
}
else
{
var viewOnScreen = view.ConvertRectToView(view.Bounds, window);
var element = view as FrameworkElement;
if (element?.Clip != null)
{
var clip = element.Clip.Rect.ToCGRect();
// Offset the local clip bounds to get the clip bounds on screen
clip.Offset(viewOnScreen.X, viewOnScreen.Y);
viewOnScreen.Intersect(clip);
}
if (finalRect == null)
{
finalRect = viewOnScreen;
}
var r2 = finalRect.Value;
r2.Intersect(viewOnScreen);
finalRect = r2;
view = view.Superview;
}
}
return finalRect.Value;
}
}
}