summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT/VisualElementTracker.cs
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2017-03-29 02:52:45 -0600
committerRui Marinho <me@ruimarinho.net>2017-03-29 09:52:45 +0100
commite55efa2a8e1164d805bc76b0f3ce84999d2f1bb8 (patch)
tree62ef93abac6215010ca9fe719ee03fc414e88bfe /Xamarin.Forms.Platform.WinRT/VisualElementTracker.cs
parent90582e977734d40d2023537186ebcf79f826291e (diff)
downloadxamarin-forms-e55efa2a8e1164d805bc76b0f3ce84999d2f1bb8.tar.gz
xamarin-forms-e55efa2a8e1164d805bc76b0f3ce84999d2f1bb8.tar.bz2
xamarin-forms-e55efa2a8e1164d805bc76b0f3ce84999d2f1bb8.zip
Align iOS, Android, Windows handling of tap gesture event bubbling (#842)
* Add test for gesture bubbling behavior on all controls; Make Windows behavior consistent with other platforms; * Fix the stepper test * Make Frame on Android handle tap event bubbling like the other platforms * Formatting changes and query syntax instead of SelectMany
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/VisualElementTracker.cs')
-rw-r--r--Xamarin.Forms.Platform.WinRT/VisualElementTracker.cs51
1 files changed, 49 insertions, 2 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/VisualElementTracker.cs b/Xamarin.Forms.Platform.WinRT/VisualElementTracker.cs
index a29d61ad..06c72b9a 100644
--- a/Xamarin.Forms.Platform.WinRT/VisualElementTracker.cs
+++ b/Xamarin.Forms.Platform.WinRT/VisualElementTracker.cs
@@ -67,6 +67,8 @@ namespace Xamarin.Forms.Platform.WinRT
}
}
+ public bool PreventGestureBubbling { get; set; }
+
public TNativeElement Control
{
get { return _control; }
@@ -75,8 +77,19 @@ namespace Xamarin.Forms.Platform.WinRT
if (_control == value)
return;
+ if (_control != null)
+ {
+ _control.Tapped -= HandleTapped;
+ _control.DoubleTapped -= HandleDoubleTapped;
+ }
+
_control = value;
UpdateNativeControl();
+
+ if (PreventGestureBubbling)
+ {
+ UpdatingGestureRecognizers();
+ }
}
}
@@ -163,6 +176,12 @@ namespace Xamarin.Forms.Platform.WinRT
}
}
+ if (_control != null)
+ {
+ _control.Tapped -= HandleTapped;
+ _control.DoubleTapped -= HandleDoubleTapped;
+ }
+
Control = null;
Element = null;
Container = null;
@@ -502,11 +521,29 @@ namespace Xamarin.Forms.Platform.WinRT
_container.PointerReleased -= OnPointerReleased;
_container.PointerCanceled -= OnPointerCanceled;
- if (gestures.GetGesturesFor<TapGestureRecognizer>(g => g.NumberOfTapsRequired == 1).GetEnumerator().MoveNext())
+ if (gestures.GetGesturesFor<TapGestureRecognizer>(g => g.NumberOfTapsRequired == 1).Any())
+ {
_container.Tapped += OnTap;
+ }
+ else
+ {
+ if (_control != null && PreventGestureBubbling)
+ {
+ _control.Tapped += HandleTapped;
+ }
+ }
- if (gestures.GetGesturesFor<TapGestureRecognizer>(g => g.NumberOfTapsRequired == 2).GetEnumerator().MoveNext())
+ if (gestures.GetGesturesFor<TapGestureRecognizer>(g => g.NumberOfTapsRequired == 2).Any())
+ {
_container.DoubleTapped += OnDoubleTap;
+ }
+ else
+ {
+ if (_control != null && PreventGestureBubbling)
+ {
+ _control.DoubleTapped += HandleDoubleTapped;
+ }
+ }
bool hasPinchGesture = gestures.GetGesturesFor<PinchGestureRecognizer>().GetEnumerator().MoveNext();
bool hasPanGesture = gestures.GetGesturesFor<PanGestureRecognizer>().GetEnumerator().MoveNext();
@@ -532,5 +569,15 @@ namespace Xamarin.Forms.Platform.WinRT
_container.PointerReleased += OnPointerReleased;
_container.PointerCanceled += OnPointerCanceled;
}
+
+ void HandleTapped(object sender, TappedRoutedEventArgs tappedRoutedEventArgs)
+ {
+ tappedRoutedEventArgs.Handled = true;
+ }
+
+ void HandleDoubleTapped(object sender, DoubleTappedRoutedEventArgs doubleTappedRoutedEventArgs)
+ {
+ doubleTappedRoutedEventArgs.Handled = true;
+ }
}
} \ No newline at end of file