summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-06-28 03:25:45 -0700
committerRui Marinho <me@ruimarinho.net>2016-06-28 11:28:39 +0100
commite72762f9dcbf434a4bdac00ba78e7b3eaf1386c2 (patch)
tree35933153b2f9e64d82a6ccbee994fe740aa9b86b
parent6dd32dacf16b6703ee9cd8316e7d322c978e35f4 (diff)
downloadxamarin-forms-e72762f9dcbf434a4bdac00ba78e7b3eaf1386c2.tar.gz
xamarin-forms-e72762f9dcbf434a4bdac00ba78e7b3eaf1386c2.tar.bz2
xamarin-forms-e72762f9dcbf434a4bdac00ba78e7b3eaf1386c2.zip
[iOS] Default BarTextColor/BarBackgroundColor will no longer override values set in custom renderers (#233)release-2.3.0-hf1
* [Controls] Improve TabbedPage test case iOS should default to the color used in a custom renderer instead of to the global default color. * [iOS] TabbedPage Bar*Color default is better Will use the color set by a custom renderer, if any, instead of always pulling from global appearance.
-rw-r--r--Xamarin.Forms.ControlGallery.iOS/CustomRenderers.cs13
-rw-r--r--Xamarin.Forms.Controls/CoreGallery.cs27
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs48
3 files changed, 78 insertions, 10 deletions
diff --git a/Xamarin.Forms.ControlGallery.iOS/CustomRenderers.cs b/Xamarin.Forms.ControlGallery.iOS/CustomRenderers.cs
index 44d86644..92b58455 100644
--- a/Xamarin.Forms.ControlGallery.iOS/CustomRenderers.cs
+++ b/Xamarin.Forms.ControlGallery.iOS/CustomRenderers.cs
@@ -28,7 +28,7 @@ using MonoTouch.CoreLocation;
[assembly: ExportRenderer(typeof(NativeListView2), typeof(NativeiOSListViewRenderer))]
[assembly: ExportRenderer(typeof(NativeListView), typeof(NativeListViewRenderer))]
[assembly: ExportRenderer(typeof(CustomMapView), typeof(CustomIOSMapRenderer))]
-
+[assembly: ExportRenderer(typeof(TabbedPage), typeof(TabbedPageWithCustomBarColorRenderer))]
namespace Xamarin.Forms.ControlGallery.iOS
{
public class CustomIOSMapRenderer : ViewRenderer<CustomMapView, MKMapView>
@@ -593,5 +593,16 @@ namespace Xamarin.Forms.ControlGallery.iOS
}
}
+ public class TabbedPageWithCustomBarColorRenderer : TabbedRenderer
+ {
+ public TabbedPageWithCustomBarColorRenderer()
+ {
+ TabBar.TintColor = UIColor.White;
+ TabBar.BarTintColor = UIColor.Purple;
+
+ //UITabBar.Appearance.TintColor = UIColor.White;
+ //UITabBar.Appearance.BarTintColor = UIColor.Purple;
+ }
+ }
}
diff --git a/Xamarin.Forms.Controls/CoreGallery.cs b/Xamarin.Forms.Controls/CoreGallery.cs
index 27c2f0aa..8fd1f7bc 100644
--- a/Xamarin.Forms.Controls/CoreGallery.cs
+++ b/Xamarin.Forms.Controls/CoreGallery.cs
@@ -69,6 +69,17 @@ namespace Xamarin.Forms.Controls
public CoreNavigationPage ()
{
AutomationId = "NavigationPageRoot";
+
+ BarBackgroundColor = Color.Maroon;
+ BarTextColor = Color.Yellow;
+
+ Device.StartTimer(TimeSpan.FromSeconds(2), () => {
+ BarBackgroundColor = Color.Default;
+ BarTextColor = Color.Default;
+
+ return false;
+ });
+
Navigation.PushAsync (new CoreRootPage (this));
}
}
@@ -85,8 +96,20 @@ namespace Xamarin.Forms.Controls
{
AutomationId = "TabbedPageRoot";
- BarBackgroundColor = Color.Maroon;
- BarTextColor = Color.White;
+
+ Device.StartTimer(TimeSpan.FromSeconds(6), () => {
+ BarBackgroundColor = Color.Maroon;
+ BarTextColor = Color.Yellow;
+
+ Device.StartTimer(TimeSpan.FromSeconds(6), () => {
+ BarBackgroundColor = Color.Default;
+ BarTextColor = Color.Default;
+
+ return false;
+ });
+
+ return false;
+ });
Children.Add(new CoreRootPage(this, NavigationBehavior.PushModalAsync) { Title = "Tab 1" });
Children.Add(new CoreRootPage(this, NavigationBehavior.PushModalAsync) { Title = "Tab 2" });
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
index 2db8ac26..91150769 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
@@ -23,6 +23,12 @@ namespace Xamarin.Forms.Platform.iOS
{
public class TabbedRenderer : UITabBarController, IVisualElementRenderer, IEffectControlProvider
{
+ bool _barBackgroundColorWasSet;
+ bool _barTextColorWasSet;
+ UIColor _defaultBarTextColor;
+ bool _defaultBarTextColorSet;
+ UIColor _defaultBarColor;
+ bool _defaultBarColorSet;
bool _loaded;
Size _queuedSize;
@@ -305,14 +311,31 @@ namespace Xamarin.Forms.Platform.iOS
return;
var barBackgroundColor = Tabbed.BarBackgroundColor;
+ var isDefaultColor = barBackgroundColor.IsDefault;
+
+ if (isDefaultColor && !_barBackgroundColorWasSet)
+ return;
+
+ if (!_defaultBarColorSet)
+ {
+ if (Forms.IsiOS7OrNewer)
+ _defaultBarColor = TabBar.BarTintColor;
+ else
+ _defaultBarColor = TabBar.TintColor;
+
+ _defaultBarColorSet = true;
+ }
+
+ if (!isDefaultColor)
+ _barBackgroundColorWasSet = true;
if (Forms.IsiOS7OrNewer)
{
- TabBar.BarTintColor = barBackgroundColor == Color.Default ? UINavigationBar.Appearance.BarTintColor : barBackgroundColor.ToUIColor();
+ TabBar.BarTintColor = isDefaultColor ? _defaultBarColor : barBackgroundColor.ToUIColor();
}
else
{
- TabBar.TintColor = barBackgroundColor == Color.Default ? UINavigationBar.Appearance.TintColor : barBackgroundColor.ToUIColor();
+ TabBar.TintColor = isDefaultColor ? _defaultBarColor : barBackgroundColor.ToUIColor();
}
}
@@ -322,13 +345,24 @@ namespace Xamarin.Forms.Platform.iOS
return;
var barTextColor = Tabbed.BarTextColor;
+ var isDefaultColor = barTextColor.IsDefault;
+
+ if (isDefaultColor && !_barTextColorWasSet)
+ return;
+
+ if (!_defaultBarTextColorSet)
+ {
+ _defaultBarTextColor = TabBar.TintColor;
+ _defaultBarTextColorSet = true;
+ }
- var globalAttributes = UINavigationBar.Appearance.GetTitleTextAttributes();
+ if (!isDefaultColor)
+ _barTextColorWasSet = true;
- var attributes = new UITextAttributes { Font = globalAttributes.Font };
+ var attributes = new UITextAttributes();
- if (barTextColor == Color.Default)
- attributes.TextColor = globalAttributes.TextColor;
+ if (isDefaultColor)
+ attributes.TextColor = _defaultBarTextColor;
else
attributes.TextColor = barTextColor.ToUIColor();
@@ -341,7 +375,7 @@ namespace Xamarin.Forms.Platform.iOS
// setting the unselected icon tint is not supported by iOS
if (Forms.IsiOS7OrNewer)
{
- TabBar.TintColor = barTextColor == Color.Default ? UINavigationBar.Appearance.TintColor : barTextColor.ToUIColor();
+ TabBar.TintColor = isDefaultColor ? _defaultBarTextColor : barTextColor.ToUIColor();
}
}