[iOS,Shell] Fix tab bar style color alignment to match Android (#5075)
authorDavid Ortinau <david.ortinau@microsoft.com>
Mon, 18 Mar 2019 18:52:49 +0000 (13:52 -0500)
committerRui Marinho <me@ruimarinho.net>
Mon, 18 Mar 2019 18:52:49 +0000 (18:52 +0000)
* Set the same TabBar color styles as Android

* unified on title color, made names consistent, and commented unused properties.

Xamarin.Forms.Platform.Android/Renderers/ShellBottomNavViewAppearanceTracker.cs
Xamarin.Forms.Platform.iOS/Renderers/SafeShellTabBarAppearanceTracker.cs
Xamarin.Forms.Platform.iOS/Renderers/ShellTabBarAppearanceTracker.cs

index f2b8002..f74e20b 100644 (file)
@@ -36,29 +36,29 @@ namespace Xamarin.Forms.Platform.Android
                public virtual void SetAppearance(BottomNavigationView bottomView, ShellAppearance appearance)
                {
                        IShellAppearanceElement controller = appearance;
-                       var background = controller.EffectiveTabBarBackgroundColor;
-                       var foreground = controller.EffectiveTabBarForegroundColor;
-                       var disabled = controller.EffectiveTabBarDisabledColor;
-                       var unselected = controller.EffectiveTabBarUnselectedColor;
-                       var title = controller.EffectiveTabBarTitleColor;
+                       var backgroundColor = controller.EffectiveTabBarBackgroundColor;
+                       var foregroundColor = controller.EffectiveTabBarForegroundColor; // currently unused
+                       var disabledColor = controller.EffectiveTabBarDisabledColor;
+                       var unselectedColor = controller.EffectiveTabBarUnselectedColor;
+                       var titleColor = controller.EffectiveTabBarTitleColor;
 
 
                        if (_defaultList == null)
                        {
 #if __ANDROID_28__
-                               _defaultList = bottomView.ItemTextColor ?? MakeColorStateList(title.ToAndroid().ToArgb(), disabled.ToAndroid().ToArgb(), unselected.ToAndroid().ToArgb());
+                               _defaultList = bottomView.ItemTextColor ?? MakeColorStateList(titleColor.ToAndroid().ToArgb(), disabledColor.ToAndroid().ToArgb(), unselectedColor.ToAndroid().ToArgb());
 #else
                                _defaultList = bottomView.ItemTextColor;
 #endif
                        }
 
-                       var colorStateList = MakeColorStateList(title, disabled, unselected);
+                       var colorStateList = MakeColorStateList(titleColor, disabledColor, unselectedColor);
                        bottomView.ItemTextColor = colorStateList;
                        bottomView.ItemIconTintList = colorStateList;
 
                        colorStateList.Dispose();
 
-                       SetBackgroundColor(bottomView, background);
+                       SetBackgroundColor(bottomView, backgroundColor);
                }
 
                protected virtual void SetBackgroundColor(BottomNavigationView bottomView, Color color)
index e7bfa11..33cde3d 100644 (file)
@@ -21,9 +21,13 @@ namespace Xamarin.Forms.Platform.iOS
 
                public void SetAppearance(UITabBarController controller, ShellAppearance appearance)
                {
-                       var background = appearance.BackgroundColor;
-                       var foreground = appearance.ForegroundColor;
-                       var unselectedColor = appearance.UnselectedColor;
+                       IShellAppearanceElement appearanceElement = appearance;
+                       var backgroundColor = appearanceElement.EffectiveTabBarBackgroundColor;
+                       var foregroundColor = appearanceElement.EffectiveTabBarForegroundColor; // currently unused
+                       var disabledColor = appearanceElement.EffectiveTabBarDisabledColor; // unused on iOS
+                       var unselectedColor = appearanceElement.EffectiveTabBarUnselectedColor;
+                       var titleColor = appearanceElement.EffectiveTabBarTitleColor;
+
                        var tabBar = controller.TabBar;
 
                        if (_defaultTint == null)
@@ -33,10 +37,10 @@ namespace Xamarin.Forms.Platform.iOS
                                _defaultUnselectedTint = tabBar.UnselectedItemTintColor;
                        }
 
-                       if (!background.IsDefault)
-                               tabBar.BarTintColor = background.ToUIColor();
-                       if (!foreground.IsDefault)
-                               tabBar.TintColor = foreground.ToUIColor();
+                       if (!backgroundColor.IsDefault)
+                               tabBar.BarTintColor = backgroundColor.ToUIColor();
+                       if (!titleColor.IsDefault)
+                               tabBar.TintColor = titleColor.ToUIColor();
                        if (!unselectedColor.IsDefault)
                                tabBar.UnselectedItemTintColor = unselectedColor.ToUIColor();
                }
index b035d7e..bffba95 100644 (file)
@@ -27,11 +27,13 @@ namespace Xamarin.Forms.Platform.iOS
 
                public void SetAppearance(UITabBarController controller, ShellAppearance appearance)
                {
-                       var background = appearance.BackgroundColor;
-                       var foreground = appearance.ForegroundColor;
-                       var titleColor = appearance.TitleColor;
-                       var disabledColor = appearance.DisabledColor;
-                       var unselectedColor = appearance.UnselectedColor;
+                       IShellAppearanceElement el = appearance;
+                       var backgroundColor = el.EffectiveTabBarBackgroundColor;
+                       var foregroundColor = el.EffectiveTabBarForegroundColor;
+                       var titleColor = el.EffectiveTabBarTitleColor;
+                       var disabledColor = el.EffectiveTabBarDisabledColor;
+                       var unselectedColor = el.EffectiveTabBarUnselectedColor;
+
                        var tabBar = controller.TabBar;
 
                        if (_blurView == null)
@@ -52,10 +54,10 @@ namespace Xamarin.Forms.Platform.iOS
                        tabBar.InsertSubview(_colorView, 0);
                        tabBar.InsertSubview(_blurView, 0);
 
-                       if (!background.IsDefault)
-                               _colorView.BackgroundColor = background.ToUIColor();
-                       if (!foreground.IsDefault)
-                               tabBar.TintColor = foreground.ToUIColor();
+                       if (!backgroundColor.IsDefault)
+                               _colorView.BackgroundColor = backgroundColor.ToUIColor();
+                       if (!foregroundColor.IsDefault)
+                               tabBar.TintColor = foregroundColor.ToUIColor();
                        if (!unselectedColor.IsDefault)
                                tabBar.UnselectedItemTintColor = unselectedColor.ToUIColor();
                }
@@ -69,7 +71,7 @@ namespace Xamarin.Forms.Platform.iOS
                }
 
                #region IDisposable Support
-               
+
                protected virtual void Dispose(bool disposing)
                {
                        if (!_disposed)