Clear global routes on unit tests and process global routes in the right place (...
authorShane Neuville <shneuvil@microsoft.com>
Sat, 6 Jul 2019 19:56:10 +0000 (13:56 -0600)
committerGitHub <noreply@github.com>
Sat, 6 Jul 2019 19:56:10 +0000 (13:56 -0600)
* Clear global routes on unit tests and process global routes in the right place

* - route with current item in case shellSection is null

* inset ui test fix

* Fix ColorFilter for API 19

* add missing file

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/ShellInsets.cs
Xamarin.Forms.Core.UnitTests/ShellTestBase.cs
Xamarin.Forms.Core/Shell/Shell.cs
Xamarin.Forms.Platform.Android/AppCompat/SwitchRenderer.cs
Xamarin.Forms.Platform.Android/Extensions/DrawableExtensions.cs [new file with mode: 0644]
Xamarin.Forms.Platform.Android/Renderers/SliderRenderer.cs
Xamarin.Forms.Platform.Android/Renderers/SwitchRenderer.cs
Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj

index 17cb990..e5260f0 100644 (file)
@@ -8,6 +8,7 @@ using System.Linq;
 using Xamarin.Forms.PlatformConfiguration;
 using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
 using System.Threading;
+using System.ComponentModel;
 
 
 #if UITEST
@@ -120,7 +121,7 @@ namespace Xamarin.Forms.Controls.Issues
                void EmptyPageSafeArea()
                {
                        var page = CreateContentPage();
-                       var topLabel = new Label() { Text = "Top Label", HeightRequest = 200, AutomationId = SafeAreaTopLabel, VerticalOptions = LayoutOptions.Start };
+                       var topLabel = new Label() { Text = "Top Label", HeightRequest = 0, AutomationId = SafeAreaTopLabel, VerticalOptions = LayoutOptions.Start };
                        page.Content =
                                new StackLayout()
                                {
@@ -143,11 +144,21 @@ namespace Xamarin.Forms.Controls.Issues
 
                        page.BackgroundColor = Color.Yellow;
 
-                       page.Appearing += (_, __) =>
+                       PropertyChangedEventHandler propertyChangedEventHandler = null;
+                       propertyChangedEventHandler = (sender, args) =>
                        {
-                               topLabel.HeightRequest = page.On<iOS>().SafeAreaInsets().Top;
+                               if(args.PropertyName == PlatformConfiguration.iOSSpecific.Page.SafeAreaInsetsProperty.PropertyName)
+                               {
+                                       if (page.On<iOS>().SafeAreaInsets().Top > 0)
+                                       {
+                                               page.PropertyChanged -= propertyChangedEventHandler;
+                                               topLabel.HeightRequest = page.On<iOS>().SafeAreaInsets().Top;
+                                       }
+                               }
                        };
 
+                       page.PropertyChanged += propertyChangedEventHandler;
+
                        Shell.SetTabBarIsVisible(page, false);
                        Shell.SetNavBarIsVisible(page, false);
                        CurrentItem = Items.Last();
index d2ef648..cae7f92 100644 (file)
@@ -20,6 +20,7 @@ namespace Xamarin.Forms.Core.UnitTests
                public override void TearDown()
                {
                        base.TearDown();
+                       Routing.Clear();
 
                }
 
index cc1affd..1779780 100644 (file)
@@ -421,18 +421,17 @@ namespace Xamarin.Forms
                                                {
                                                        shellSection.SetValueFromRenderer(ShellSection.CurrentItemProperty, shellContent);                                                      
                                                }
-
-                                               if (navigationRequest.Request.GlobalRoutes.Count > 0)
-                                               {
-                                                       // TODO get rid of this hack and fix so if there's a stack the current page doesn't display
-                                                       Device.BeginInvokeOnMainThread(async () =>
-                                                       {
-                                                               await shellSection.GoToAsync(navigationRequest, queryData, false);
-                                                       });
-                                               }
-
                                        }
                                }
+
+                               if (navigationRequest.Request.GlobalRoutes.Count > 0)
+                               {
+                                       // TODO get rid of this hack and fix so if there's a stack the current page doesn't display
+                                       Device.BeginInvokeOnMainThread(async () =>
+                                       {
+                                               await CurrentItem.CurrentItem.GoToAsync(navigationRequest, queryData, false);
+                                       });
+                               }
                        }
                        else
                        {
index b1f089d..a259195 100644 (file)
@@ -91,7 +91,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
                                        aswitch.SetOnCheckedChangeListener(this);
                                        SetNativeControl(aswitch);
                                        _defaultTrackDrawable = aswitch.TrackDrawable;
-                                       _defaultThumbColorFilter = Control.ThumbDrawable.ColorFilter;
+                                       _defaultThumbColorFilter = Control.ThumbDrawable.GetColorFilter();
                                }
                                else
                                        UpdateEnabled(); // Normally set by SetNativeControl, but not when the Control is reused.
@@ -140,11 +140,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
                        if (Element == null)
                                return;
 
-                       Color thumbColor = Element.ThumbColor;
-                       if (thumbColor.IsDefault)
-                               Control.ThumbDrawable.SetColorFilter(_defaultThumbColorFilter);
-                       else
-                               Control.ThumbDrawable.SetColorFilter(thumbColor.ToAndroid(), PorterDuff.Mode.SrcIn);
+                       Control.ThumbDrawable.SetColorFilter(Element.ThumbColor, _defaultThumbColorFilter);
                }
 
                void HandleToggled(object sender, EventArgs e)
diff --git a/Xamarin.Forms.Platform.Android/Extensions/DrawableExtensions.cs b/Xamarin.Forms.Platform.Android/Extensions/DrawableExtensions.cs
new file mode 100644 (file)
index 0000000..b28293d
--- /dev/null
@@ -0,0 +1,44 @@
+using System;
+using ADrawable = Android.Graphics.Drawables.Drawable;
+using AColorFilter = Android.Graphics.ColorFilter;
+using ADrawableCompat = Android.Support.V4.Graphics.Drawable.DrawableCompat;
+using Android.Graphics;
+
+namespace Xamarin.Forms.Platform.Android
+{
+       internal static class DrawableExtensions
+       {
+               public static AColorFilter GetColorFilter(this ADrawable drawable)
+               {
+                       if (drawable == null)
+                               return null;
+
+                       return ADrawableCompat.GetColorFilter(drawable);
+               }
+
+               public static void SetColorFilter(this ADrawable drawable, AColorFilter colorFilter)
+               {
+                       if (drawable == null)
+                               return;
+
+                       if (colorFilter == null)
+                               ADrawableCompat.ClearColorFilter(drawable);
+
+                       drawable.SetColorFilter(colorFilter);
+               }
+
+               public static void SetColorFilter(this ADrawable drawable, Color color, AColorFilter defaultColorFilter)
+               {
+                       if (drawable == null)
+                               return;
+
+                       if (color == Color.Default)
+                       {
+                               SetColorFilter(drawable, defaultColorFilter);
+                               return;
+                       }
+
+                       drawable.SetColorFilter(color.ToAndroid(), PorterDuff.Mode.SrcIn);
+               }
+       }
+}
index b8492d4..7cbf4a8 100644 (file)
@@ -73,7 +73,7 @@ namespace Xamarin.Forms.Platform.Android
 
                                if (Build.VERSION.SdkInt > BuildVersionCodes.Kitkat)
                                {
-                                       defaultthumbcolorfilter = seekBar.Thumb.ColorFilter;
+                                       defaultthumbcolorfilter = seekBar.Thumb.GetColorFilter();
                                        defaultprogresstintmode = seekBar.ProgressTintMode;
                                        defaultprogressbackgroundtintmode = seekBar.ProgressBackgroundTintMode;
                                        defaultprogresstintlist = seekBar.ProgressTintList;
@@ -178,23 +178,12 @@ namespace Xamarin.Forms.Platform.Android
                        }
                }
 
-               private void UpdateThumbColor()
+               void UpdateThumbColor()
                {
-                       if (Element != null)
-                       {
-                               if (Element.ThumbColor == Color.Default)
-                               {
-                                       Control.Thumb.SetColorFilter(defaultthumbcolorfilter);
-                               }
-                               else
-                               {
-                                       Control.Thumb.SetColorFilter(Element.ThumbColor.ToAndroid(), PorterDuff.Mode.SrcIn);
-                               }
-
-                       }
+                       Control.Thumb.SetColorFilter(Element.ThumbColor, defaultthumbcolorfilter);
                }
 
-               private void UpdateThumbImage()
+               void UpdateThumbImage()
                {
                        this.ApplyDrawableAsync(Slider.ThumbImageSourceProperty, Context, drawable =>
                        {
index ba41273..40a28de 100644 (file)
@@ -83,8 +83,8 @@ namespace Xamarin.Forms.Platform.Android
                                        var aswitch = CreateNativeControl();
                                        aswitch.SetOnCheckedChangeListener(this);
                                        SetNativeControl(aswitch);
-                                       _defaultTrackDrawable = Control.TrackDrawable;
-                                       _defaultThumbColorFilter = Control.ThumbDrawable.ColorFilter;
+                                       _defaultTrackDrawable = Control.TrackDrawable;                                  
+                                       _defaultThumbColorFilter = Control.ThumbDrawable.GetColorFilter();
                                }
                                else
                                {
@@ -138,11 +138,7 @@ namespace Xamarin.Forms.Platform.Android
                        if (Element == null)
                                return;
 
-                       Color thumbColor = Element.ThumbColor;
-                       if (thumbColor.IsDefault)
-                               Control.ThumbDrawable.SetColorFilter(_defaultThumbColorFilter);
-                       else
-                               Control.ThumbDrawable.SetColorFilter(thumbColor.ToAndroid(), PorterDuff.Mode.SrcIn);
+                       Control.ThumbDrawable.SetColorFilter(Element.ThumbColor, _defaultThumbColorFilter);
                }
 
                void HandleToggled(object sender, EventArgs e)
index 746e811..1f863b6 100644 (file)
@@ -98,6 +98,7 @@
     <Compile Include="CollectionView\TemplatedItemViewHolder.cs" />
     <Compile Include="CollectionView\TextViewHolder.cs" />
     <Compile Include="Elevation.cs" />
+    <Compile Include="Extensions\DrawableExtensions.cs" />
     <Compile Include="Extensions\EntryRendererExtensions.cs" />
     <Compile Include="Extensions\FragmentManagerExtensions.cs" />
     <Compile Include="Extensions\ScrollViewExtensions.cs" />