Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] [iOS] NavigationBarSeparator is visible after changing BarBackgroundColor when SetHideNavigationBarSeparator(true) #15329

Closed
JustickDM opened this issue Apr 22, 2022 · 2 comments · Fixed by #15330
Labels
p/iOS 🍎 s/unverified New report that has yet to be verified t/bug 🐛

Comments

@JustickDM
Copy link
Contributor

JustickDM commented Apr 22, 2022

Description

NavigationBarSeparator is visible after changing BarBackgroundColor when On().SetHideNavigationBarSeparator(true)

Steps to Reproduce

  1. Set On().SetHideNavigationBarSeparator(true) on NavigationPage
  2. Set BarBackgroundColor on NavigationPage
  3. Run App
  4. Change BarBackgroundColor

Expected Behavior

NavigationBarSeparator is Hidden

Actual Behavior

NavigationBarSeparator is Visible

Basic Information

  • Version with issue: 5.0.0.2401
  • Last known good version:
  • Platform Target Frameworks:
    • iOS: 15.2.0.17

Screenshots

  1. App starts with Light Theme (SetHideNavigationBarSeparator(true), NavigationBarSeparator is Hidden - good)
    изображение
  2. Changing App Theme to Dark (SetHideNavigationBarSeparator(true), but NavigationBarSeparator is Visible - bad)
    Capture2
  3. Changing App Theme back to Light (SetHideNavigationBarSeparator(true), but NavigationBarSeparator is Visible - bad)
    Capture3

Workaround

UpdateHideNavigationBarSeparator method from - https://github.com/xamarin/Xamarin.Forms/blob/5.0.0/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs#L506

Line needed to fix - https://github.com/xamarin/Xamarin.Forms/blob/5.0.0/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs#L454

internal sealed class NavigationPageRenderer : NavigationRenderer
	{
		private UIImage _defaultNavBarShadowImage;
		private UIImage _defaultNavBarBackImage;
		private bool _disposed;

		public Xamarin.Forms.NavigationPage NavPage => Element as Xamarin.Forms.NavigationPage;

		public override void ViewDidLoad()
		{
			base.ViewDidLoad();

			NavPage.PropertyChanged += HandlePropertyChanged;
		}

		protected override void Dispose(bool disposing)
		{
			if (_disposed)
				return;

			_disposed = true;

			if (disposing)
				NavPage.PropertyChanged -= HandlePropertyChanged;

			base.Dispose(disposing);
		}

		private void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			if (e.PropertyName == Xamarin.Forms.NavigationPage.BarBackgroundColorProperty.PropertyName)
				UpdateHideNavigationBarSeparator();
		}

		private void UpdateHideNavigationBarSeparator()
		{
			bool shouldHide = NavPage.OnThisPlatform().HideNavigationBarSeparator();

			// Just setting the ShadowImage is good for iOS11
			if (_defaultNavBarShadowImage == null)
				_defaultNavBarShadowImage = NavigationBar.ShadowImage;

			if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
			{
				if (shouldHide)
				{
					NavigationBar.CompactAppearance.ShadowColor = UIColor.Clear;
					NavigationBar.StandardAppearance.ShadowColor = UIColor.Clear;
					NavigationBar.ScrollEdgeAppearance.ShadowColor = UIColor.Clear;
				}
				else
				{
					NavigationBar.CompactAppearance.ShadowColor = UIColor.FromRGBA(0, 0, 0, 76); //default ios13 shadow color
					NavigationBar.StandardAppearance.ShadowColor = UIColor.FromRGBA(0, 0, 0, 76);
					NavigationBar.ScrollEdgeAppearance.ShadowColor = UIColor.FromRGBA(0, 0, 0, 76);
				}
			}
			else
			{
				if (shouldHide)
					NavigationBar.ShadowImage = new UIImage();
				else
					NavigationBar.ShadowImage = _defaultNavBarShadowImage;
			}

			if (!UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
			{
				// For iOS 10 and lower, you need to set the background image.
				// If you set this for iOS11, you'll remove the background color.
				if (_defaultNavBarBackImage == null)
					_defaultNavBarBackImage = NavigationBar.GetBackgroundImage(UIBarMetrics.Default);

				if (shouldHide)
					NavigationBar.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
				else
					NavigationBar.SetBackgroundImage(_defaultNavBarBackImage, UIBarMetrics.Default);
			}
		}
	}
  1. App starts with Light Theme (SetHideNavigationBarSeparator(true), NavigationBarSeparator is Hidden - good)
    Capture4

  2. Changing App Theme to Dark (SetHideNavigationBarSeparator(true), but NavigationBarSeparator is Hidden - good)
    Capture5

  3. Changing App Theme back to Light (SetHideNavigationBarSeparator(true), but NavigationBarSeparator is Hidden - good)
    Capture6

@JustickDM JustickDM added s/unverified New report that has yet to be verified t/bug 🐛 labels Apr 22, 2022
@jfversluis
Copy link
Member

Thanks for the thorough report! I think it might've been reported before. Has to do with some changes in iOS 15 and appearance stuff. Anyway...

It seems like you pretty much pinpointed how to fix this as well, aren't you tempted to put it in a PR? ;)

@JustickDM
Copy link
Contributor Author

Thanks for the thorough report! I think it might've been reported before. Has to do with some changes in iOS 15 and appearance stuff. Anyway...

It seems like you pretty much pinpointed how to fix this as well, aren't you tempted to put it in a PR? ;)

Already:)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p/iOS 🍎 s/unverified New report that has yet to be verified t/bug 🐛
Projects
None yet
2 participants