summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/Renderers
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/Renderers
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/Renderers')
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/BoxRenderer.cs19
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/ImageRenderer.cs14
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/LabelRenderer.cs14
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/MotionEventHelper.cs53
4 files changed, 82 insertions, 18 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/BoxRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/BoxRenderer.cs
index 380d4018..aa19d81c 100644
--- a/Xamarin.Forms.Platform.Android/Renderers/BoxRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/Renderers/BoxRenderer.cs
@@ -5,7 +5,7 @@ namespace Xamarin.Forms.Platform.Android
{
public class BoxRenderer : VisualElementRenderer<BoxView>
{
- bool _isInViewCell;
+ readonly MotionEventHelper _motionEventHelper = new MotionEventHelper();
public BoxRenderer()
{
@@ -16,26 +16,15 @@ namespace Xamarin.Forms.Platform.Android
{
if (base.OnTouchEvent(e))
return true;
- return !Element.InputTransparent && !_isInViewCell;
+
+ return _motionEventHelper.HandleMotionEvent(Parent);
}
protected override void OnElementChanged(ElementChangedEventArgs<BoxView> e)
{
base.OnElementChanged(e);
- if (e.NewElement != null)
- {
- var parent = e.NewElement.Parent;
- while (parent != null)
- {
- if (parent is ViewCell)
- {
- _isInViewCell = true;
- break;
- }
- parent = parent.Parent;
- }
- }
+ _motionEventHelper.UpdateElement(e.NewElement);
UpdateBackgroundColor();
}
diff --git a/Xamarin.Forms.Platform.Android/Renderers/ImageRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/ImageRenderer.cs
index e18d4b95..fee05f1b 100644
--- a/Xamarin.Forms.Platform.Android/Renderers/ImageRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/Renderers/ImageRenderer.cs
@@ -3,6 +3,7 @@ using System.ComponentModel;
using System.IO;
using System.Threading.Tasks;
using Android.Graphics;
+using Android.Views;
using AImageView = Android.Widget.ImageView;
using Xamarin.Forms.Internals;
@@ -11,8 +12,7 @@ namespace Xamarin.Forms.Platform.Android
public class ImageRenderer : ViewRenderer<Image, AImageView>
{
bool _isDisposed;
-
- IElementController ElementController => Element as IElementController;
+ readonly MotionEventHelper _motionEventHelper = new MotionEventHelper();
public ImageRenderer()
{
@@ -44,6 +44,8 @@ namespace Xamarin.Forms.Platform.Android
SetNativeControl(view);
}
+ _motionEventHelper.UpdateElement(e.NewElement);
+
UpdateBitmap(e.OldElement);
UpdateAspect();
}
@@ -117,5 +119,13 @@ namespace Xamarin.Forms.Platform.Android
((IVisualElementController)Element).NativeSizeChanged();
}
}
+
+ public override bool OnTouchEvent(MotionEvent e)
+ {
+ if (base.OnTouchEvent(e))
+ return true;
+
+ return _motionEventHelper.HandleMotionEvent(Parent);
+ }
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Android/Renderers/LabelRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/LabelRenderer.cs
index c544a239..ab1a6a35 100644
--- a/Xamarin.Forms.Platform.Android/Renderers/LabelRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/Renderers/LabelRenderer.cs
@@ -4,8 +4,8 @@ using Android.Content.Res;
using Android.Graphics;
using Android.Text;
using Android.Util;
+using Android.Views;
using Android.Widget;
-using AColor = Android.Graphics.Color;
namespace Xamarin.Forms.Platform.Android
{
@@ -23,6 +23,8 @@ namespace Xamarin.Forms.Platform.Android
FormsTextView _view;
bool _wasFormatted;
+ readonly MotionEventHelper _motionEventHelper = new MotionEventHelper();
+
public LabelRenderer()
{
AutoPackage = false;
@@ -97,6 +99,8 @@ namespace Xamarin.Forms.Platform.Android
if (e.OldElement.HorizontalTextAlignment != e.NewElement.HorizontalTextAlignment || e.OldElement.VerticalTextAlignment != e.NewElement.VerticalTextAlignment)
UpdateGravity();
}
+
+ _motionEventHelper.UpdateElement(e.NewElement);
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -217,5 +221,13 @@ namespace Xamarin.Forms.Platform.Android
_lastSizeRequest = null;
}
+
+ public override bool OnTouchEvent(MotionEvent e)
+ {
+ if (base.OnTouchEvent(e))
+ return true;
+
+ return _motionEventHelper.HandleMotionEvent(Parent);
+ }
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Android/Renderers/MotionEventHelper.cs b/Xamarin.Forms.Platform.Android/Renderers/MotionEventHelper.cs
new file mode 100644
index 00000000..4ed06d26
--- /dev/null
+++ b/Xamarin.Forms.Platform.Android/Renderers/MotionEventHelper.cs
@@ -0,0 +1,53 @@
+using Android.Views;
+
+namespace Xamarin.Forms.Platform.Android
+{
+ internal class MotionEventHelper
+ {
+ VisualElement _element;
+ bool _isInViewCell;
+
+ public bool HandleMotionEvent(IViewParent parent)
+ {
+ if (_isInViewCell || _element.InputTransparent)
+ {
+ return false;
+ }
+
+ var renderer = parent as Platform.DefaultRenderer;
+ if (renderer == null)
+ {
+ return false;
+ }
+
+ // Let the container know that we're "fake" handling this event
+ renderer.NotifyFakeHandling();
+
+ return true;
+ }
+
+ public void UpdateElement(VisualElement element)
+ {
+ _isInViewCell = false;
+ _element = element;
+
+ if (_element == null)
+ {
+ return;
+ }
+
+ // Determine whether this control is inside a ViewCell;
+ // we don't fake handle the events because ListView needs them for row selection
+ var parent = _element.Parent;
+ while (parent != null)
+ {
+ if (parent is ViewCell)
+ {
+ _isInViewCell = true;
+ break;
+ }
+ parent = parent.Parent;
+ }
+ }
+ }
+} \ No newline at end of file