From 99074753a0f20414be8eb423153fd6aaaafef87b Mon Sep 17 00:00:00 2001 From: "E.Z. Hart" Date: Tue, 20 Jun 2017 09:40:07 -0600 Subject: Align Layout transparency behavior between Android, iOS, Windows (#935) * Setting up repros * Tests for all combos of opacity, background color, and InputTransparent * Make InputTransparent work correctly for Layouts on Windows * Prevent low opacity from making Layouts implicitly input transparent * Real target values in TransparentOverlayTests * Allow layouts with transparent backgrounds to be clickable * Fix gesture bubbling behavior for layouts * Fix spacing * Remove dead code and usings * Fix spacing * Add missing using directive * Adjust transparent overlay test to work with iOS quirks * Fix spacing * Fix bugs caused by not filtering ACTION_CANCEL in MotionEventHelper * Attempting to fix the tests on iOS (where UI tests can't see the buttons) * Remove extra lines * Another attempt to get tests working on iOS * Another attempt to get iOS UI tests working for transparent overlays --- Xamarin.Forms.Platform.iOS/Platform.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'Xamarin.Forms.Platform.iOS/Platform.cs') diff --git a/Xamarin.Forms.Platform.iOS/Platform.cs b/Xamarin.Forms.Platform.iOS/Platform.cs index b3542d69..5a442bab 100644 --- a/Xamarin.Forms.Platform.iOS/Platform.cs +++ b/Xamarin.Forms.Platform.iOS/Platform.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using CoreGraphics; using Foundation; using UIKit; using RectangleF = CoreGraphics.CGRect; @@ -478,6 +479,30 @@ namespace Xamarin.Forms.Platform.iOS internal class DefaultRenderer : VisualElementRenderer { + public override UIView HitTest(CGPoint point, UIEvent uievent) + { + // UIview hit testing ignores objects which have an alpha of less than 0.01 + // (see https://developer.apple.com/reference/uikit/uiview/1622469-hittest) + // To prevent layouts with low opacity from being implicitly input transparent, + // we need to temporarily bump their alpha value during the actual hit testing, + // then restore it. If the opacity is high enough or user interaction is disabled, + // we don't have to worry about it. + + nfloat old = Alpha; + if (UserInteractionEnabled && old <= 0.01) + { + Alpha = (nfloat)0.011; + } + + var result = base.HitTest(point, uievent); + + if (UserInteractionEnabled && old <= 0.01) + { + Alpha = old; + } + + return result; + } } } } \ No newline at end of file -- cgit v1.2.3