summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/Platform.cs
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2017-03-23 11:18:38 -0600
committerRui Marinho <me@ruimarinho.net>2017-03-23 17:18:38 +0000
commitf27f5a3650f37894d4a1ac925d6fab4dc7350087 (patch)
treeb368c6c35f6592ef28e638c431bb5f3012f58a93 /Xamarin.Forms.Platform.Android/Platform.cs
parent2be80a55a514a050ab5ab07a201d13c111f49f63 (diff)
downloadxamarin-forms-f27f5a3650f37894d4a1ac925d6fab4dc7350087.tar.gz
xamarin-forms-f27f5a3650f37894d4a1ac925d6fab4dc7350087.tar.bz2
xamarin-forms-f27f5a3650f37894d4a1ac925d6fab4dc7350087.zip
UI tests for InputTransparent and fixes for Android/Windows (#808)
* Set up automated UI tests for InputTransparent * Pull in Adrian's UI tests from PR 483 * Fix bugs with box/label/image gestures passing through when not transparent * Fix disabling of layouts on Windows; fix 44096 test for iOS/Windows; * Automate the 53445 test
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Platform.cs')
-rw-r--r--Xamarin.Forms.Platform.Android/Platform.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android/Platform.cs b/Xamarin.Forms.Platform.Android/Platform.cs
index ca0b9708..0fc287c9 100644
--- a/Xamarin.Forms.Platform.Android/Platform.cs
+++ b/Xamarin.Forms.Platform.Android/Platform.cs
@@ -1024,6 +1024,50 @@ namespace Xamarin.Forms.Platform.Android
internal class DefaultRenderer : VisualElementRenderer<View>
{
+ bool _notReallyHandled;
+ internal void NotifyFakeHandling()
+ {
+ _notReallyHandled = true;
+ }
+
+ public override bool DispatchTouchEvent(MotionEvent e)
+ {
+ #region
+ // Normally dispatchTouchEvent feeds the touch events to its children one at a time, top child first,
+ // (and only to the children in the hit-test area of the event) stopping as soon as one of them has handled
+ // the event.
+
+ // But to be consistent across the platforms, we don't want this behavior; if an element is not input transparent
+ // we don't want an event to "pass through it" and be handled by an element "behind/under" it. We just want the processing
+ // to end after the first non-transparent child, regardless of whether the event has been handled.
+
+ // This is only an issue for a couple of controls; the interactive controls (switch, button, slider, etc) already "handle" their touches
+ // and the events don't propagate to other child controls. But for image, label, and box that doesn't happen. We can't have those controls
+ // lie about their events being handled because then the events won't propagate to *parent* controls (e.g., a frame with a label in it would
+ // never get a tap gesture from the label). In other words, we *want* parent propagation, but *do not want* sibling propagation. So we need to short-circuit
+ // base.DispatchTouchEvent here, but still return "false".
+
+ // Duplicating the logic of ViewGroup.dispatchTouchEvent and modifying it slightly for our purposes is a non-starter; the method is too
+ // complex and does a lot of micro-optimization. Instead, we provide a signalling mechanism for the controls which don't already "handle" touch
+ // events to tell us that they will be lying about handling their event; they then return "true" to short-circuit base.DispatchTouchEvent.
+
+ // The container gets this message and after it gets the "handled" result from dispatchTouchEvent,
+ // it then knows to ignore that result and return false/unhandled. This allows the event to propagate up the tree.
+ #endregion
+
+ _notReallyHandled = false;
+
+ var result = base.DispatchTouchEvent(e);
+
+ if (result && _notReallyHandled)
+ {
+ // If the child control returned true from its touch event handler but signalled that it was a fake "true", leave the event unhandled
+ // so parent controls have the opportunity
+ return false;
+ }
+
+ return result;
+ }
}
#region IPlatformEngine implementation