summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2017-06-20 15:38:58 (GMT)
committerRui Marinho <me@ruimarinho.net>2017-06-20 15:38:58 (GMT)
commitf7c943dc7798b3449d2bf8319aca8a9ab448ffec (patch)
tree7b27d6245816765fb320e130d2995f06a1ec3d78 /Xamarin.Forms.Platform.iOS
parentc0a55911ac66caff70dfbefb83a3dcb69c991025 (diff)
downloadxamarin-forms-f7c943dc7798b3449d2bf8319aca8a9ab448ffec.zip
xamarin-forms-f7c943dc7798b3449d2bf8319aca8a9ab448ffec.tar.gz
xamarin-forms-f7c943dc7798b3449d2bf8319aca8a9ab448ffec.tar.bz2
[iOS] Allow Forms gestures on custom renderers for controls which already have gestures (#990)
* Repro 57114 with UI test; fix for 57114 on iOS * Repro/UI test for Windows * Add helpful comment for posterity * Remove stray TODO * Only do ShouldReceiveTouch on mobile * Explicitly require wrapped UIView to have gesture recognizers
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r--Xamarin.Forms.Platform.iOS/EventTracker.cs42
1 files changed, 37 insertions, 5 deletions
diff --git a/Xamarin.Forms.Platform.iOS/EventTracker.cs b/Xamarin.Forms.Platform.iOS/EventTracker.cs
index 48f3064..5b2156c 100644
--- a/Xamarin.Forms.Platform.iOS/EventTracker.cs
+++ b/Xamarin.Forms.Platform.iOS/EventTracker.cs
@@ -33,7 +33,7 @@ namespace Xamarin.Forms.Platform.MacOS
double _previousScale = 1.0;
#if __MOBILE__
- UITouchEventArgs _shouldReceive;
+ UITouchEventArgs _shouldReceiveTouch;
#endif
public EventTracker(IVisualElementRenderer renderer)
@@ -82,9 +82,7 @@ namespace Xamarin.Forms.Platform.MacOS
{
if (_disposed)
throw new ObjectDisposedException(null);
-#if __MOBILE__
- _shouldReceive = (r, t) => t.View is IVisualElementRenderer;
-#endif
+
_handler = handler;
OnElementChanged(this, new VisualElementChangedEventArgs(null, _renderer.Element));
}
@@ -281,11 +279,20 @@ namespace Xamarin.Forms.Platform.MacOS
return result;
}
#endif
+
void LoadRecognizers()
{
if (ElementGestureRecognizers == null)
return;
+#if __MOBILE__
+ if (_shouldReceiveTouch == null)
+ {
+ // Cache this so we don't create a new UITouchEventArgs instance for every recognizer
+ _shouldReceiveTouch = ShouldReceiveTouch;
+ }
+#endif
+
foreach (var recognizer in ElementGestureRecognizers)
{
if (_gestureRecognizers.ContainsKey(recognizer))
@@ -295,7 +302,7 @@ namespace Xamarin.Forms.Platform.MacOS
if (nativeRecognizer != null)
{
#if __MOBILE__
- nativeRecognizer.ShouldReceiveTouch = _shouldReceive;
+ nativeRecognizer.ShouldReceiveTouch = _shouldReceiveTouch;
#endif
_handler.AddGestureRecognizer(nativeRecognizer);
@@ -314,6 +321,31 @@ namespace Xamarin.Forms.Platform.MacOS
}
}
+#if __MOBILE__
+ bool ShouldReceiveTouch(UIGestureRecognizer recognizer, UITouch touch)
+ {
+ if (touch.View is IVisualElementRenderer)
+ {
+ return true;
+ }
+
+ // If the touch is coming from the UIView our renderer is wrapping (e.g., if it's
+ // wrapping a UIView which already has a gesture recognizer), then we should let it through
+ // (This goes for children of that control as well)
+ if (_renderer?.NativeView == null)
+ {
+ return false;
+ }
+
+ if (touch.View.IsDescendantOfView(_renderer.NativeView) && touch.View.GestureRecognizers?.Length > 0)
+ {
+ return true;
+ }
+
+ return false;
+ }
+#endif
+
void ModelGestureRecognizersOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
{
LoadRecognizers();