Bug 37431 - NavigationRenderer sets Status Bar Style arbitrarily
Summary: NavigationRenderer sets Status Bar Style arbitrarily
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS (show other bugs)
Version: 2.0.0
Hardware: PC Mac OS
: High normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-01-06 02:55 UTC by david
Modified: 2016-11-16 20:18 UTC (History)
3 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description david 2016-01-06 02:55:04 UTC
The following code in the "UpdateBarTextColor" method of the stock NavigationRenderer causes the iOS status bar to be set incorrectly:

		private void UpdateBarTextColor ()
		{
			Color barTextColor = ((NavigationPage)this.Element).BarTextColor;
			UITextAttributes titleTextAttributes = UINavigationBar.Appearance.GetTitleTextAttributes ();
			if (barTextColor == Color.Default) {
				if (this.NavigationBar.TitleTextAttributes != null) {
					UIStringAttributes uIStringAttributes = new UIStringAttributes ();
					uIStringAttributes.ForegroundColor = titleTextAttributes.TextColor;
					uIStringAttributes.Font = titleTextAttributes.Font;
					this.NavigationBar.TitleTextAttributes = uIStringAttributes;
				}
			}
			else {
				UIStringAttributes uIStringAttributes2 = new UIStringAttributes ();
				uIStringAttributes2.Font = titleTextAttributes.Font;
				uIStringAttributes2.ForegroundColor = ((barTextColor == Color.Default) ? (uIStringAttributes2.ForegroundColor ?? UINavigationBar.Appearance.TintColor) : barTextColor.ToUIColor ());
				this.NavigationBar.TitleTextAttributes = uIStringAttributes2;
			}
			if (Forms.IsiOS7OrNewer) {
				this.NavigationBar.TintColor = ((barTextColor == Color.Default) ? UINavigationBar.Appearance.TintColor : barTextColor.ToUIColor ());
			}

			if (barTextColor.Luminosity > 0.5) {
				UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.BlackTranslucent;
				return;
			}
			UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.Default;
		}


The code sets the StatusBarStyle according to the luminosity of the barTextColor.

Unfortunately this breaks all kinds of useful and attractive interfaces where (for example) we need a light-colored text on a white background WITH A BLACK STATUS BAR.

Please do not make this kind of configuration decision without providing some kind of override. I'm now stuck, unable to implement the designer's desired look, because this code sets my status bar text to white irrespective of anything else I try to do in a custom renderer.
Comment 1 Samantha Houts [MSFT] 2016-10-29 00:44:28 UTC
*** Bug 44777 has been marked as a duplicate of this bug. ***
Comment 2 Samantha Houts [MSFT] 2016-11-16 20:18:50 UTC
Should be fixed in 2.3.4-pre1. Please note that this is an opt-in fix. Please see https://github.com/xamarin/Xamarin.Forms/pull/517 for an example of disabling this behavior. Thank you!