From dd22e787d71045d40aca7f11bbf7dcc0c372bd1e Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Wed, 19 Jun 2019 20:54:07 -0600 Subject: [PATCH] [Android] Change elevation to use float.minvalue instead of negative infinity (#6560) * change negative infinity to float.minvalue * api 19 fixes --- .../Renderers/ShellFlyoutTemplatedContentRenderer.cs | 10 +++++++--- Xamarin.Forms.Platform.Android/ViewExtensions.cs | 9 +++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Xamarin.Forms.Platform.Android/Renderers/ShellFlyoutTemplatedContentRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/ShellFlyoutTemplatedContentRenderer.cs index 2c86e59..57e1abe 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ShellFlyoutTemplatedContentRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ShellFlyoutTemplatedContentRenderer.cs @@ -92,8 +92,7 @@ namespace Xamarin.Forms.Platform.Android _bgImage = new ImageView(context) { - LayoutParameters = new LP(coordinator.LayoutParameters), - Elevation = float.NegativeInfinity + LayoutParameters = new LP(coordinator.LayoutParameters) }; UpdateFlyoutHeaderBehavior(); @@ -167,7 +166,12 @@ namespace Xamarin.Forms.Platform.Android } if (_rootView.IndexOfChild(_bgImage) == -1) - _rootView.AddView(_bgImage); + { + if(_bgImage.SetElevation(float.MinValue)) + _rootView.AddView(_bgImage); + else + _rootView.AddView(_bgImage, 0); + } } } diff --git a/Xamarin.Forms.Platform.Android/ViewExtensions.cs b/Xamarin.Forms.Platform.Android/ViewExtensions.cs index ed540e5..2645a88 100644 --- a/Xamarin.Forms.Platform.Android/ViewExtensions.cs +++ b/Xamarin.Forms.Platform.Android/ViewExtensions.cs @@ -93,5 +93,14 @@ namespace Xamarin.Forms.Platform.Android view.ClipToOutline = value; } + + public static bool SetElevation(this AView view, float value) + { + if (view.IsDisposed() || !Forms.IsLollipopOrNewer) + return false; + + view.Elevation = value; + return true; + } } } \ No newline at end of file -- 2.7.4