Xamarin.forms: [Bug] navPage.SetHideNavigationBarSeparator(true) no longer works.

Created on 7 Feb 2020  路  20Comments  路  Source: xamarin/Xamarin.Forms

Description

After updating to Xamarin.Forms 4.5.0.266-pre3 from the previous preview package, navPage.On().SetHideNavigationBarSeparator(true) no longer does anything. In other words, it seems to be impossible to hide the navigation bar separator in 4.5.0 pre-3.

Furthermore, my custom renderer that used to fix the navigation bar issues on iOS (that should become redundant after the fixes) had a ViewWillAppear override, that set some NavigationBar properties. After the update, NavigationBar.TitleTextAttributes and NavigationBar.LargeTitleTextAttributes are null in it. This is a lesser evil as the fixes to the navigation bar should make my custom renderer redundant, but breaking both navPage.On().SetHideNavigationBarSeparator and breaking NavigationBar.TitleTextAttributes forces me to roll back.

4.5.0 navbar regression in-progress high impact iOS 馃崕 platform-specifics bug

Most helpful comment

Same issue here (SetHideNavigationBarSeparator(true)) no longer works with 4.5 on iOS 13. (It's fine on iOS < 13). I also had a custom renderer setting some NavigationBar properties to manually remove the separator and these do not work anymore either:

NavigationBar.SetBackgroundImage(new UIImage(), UIBarMetrics.Default); NavigationBar.ShadowImage = new UIImage();

All 20 comments

@Tommigun1980 Can you please attach a small project that demonstrates this issue? Thanks!

Here's the repro project: NavBarSeparator.zip

I have been testing in an example using 4.4 and in that version it is working.

Captura de pantalla 2020-02-26 a las 10 21 23
Captura de pantalla 2020-02-26 a las 10 21 03

Issue9456.zip

However, in 4.5-pre3 is not working (regression).

Of note is also that in some versions it is broken only with large titles
enabled.

Same issue here (SetHideNavigationBarSeparator(true)) no longer works with 4.5 on iOS 13. (It's fine on iOS < 13). I also had a custom renderer setting some NavigationBar properties to manually remove the separator and these do not work anymore either:

NavigationBar.SetBackgroundImage(new UIImage(), UIBarMetrics.Default); NavigationBar.ShadowImage = new UIImage();

Imho it's a bit scary that new versions of the API get released with known regressions (referring to that 4.5.0 shred the pre-release tag). This makes it very hard to commit to an update. Imho a release should not be deemed ready if there are regressions as having such unstable releases makes it a hard sell to update, and also signals that things _will_ break when people update.

Came across this as well, we are using what @skyapps-co uses to hide nav bar line. I need to either find another workaround or revert to 4.4 in the mean time until this can be fixed.

Came across this as well, we are using what @skyapps-co uses to hide nav bar line. I need to either find another workaround or revert to 4.4 in the mean time until this can be fixed.

The following seems to work in 4.5.0.356 and 4.6.0.379-pre1 on the iOS versions I've tested on:

// TODO! remove this class once Xamarin fixes scroll navigation bar separator scroll edge hiding
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;

using AppNameSpace.iOS.Renderers;

[assembly: ExportRenderer(typeof(Xamarin.Forms.NavigationPage), typeof(FixNavigationBarHiddenSeparatorRenderer))]
namespace AppNameSpace.iOS.Renderers
{
    public class FixNavigationBarHiddenSeparatorRenderer : NavigationRenderer
    {
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            if (Element is Xamarin.Forms.NavigationPage navigationPage)
            {
                if (navigationPage.OnThisPlatform().HideNavigationBarSeparator())
                    NavigationBar.ScrollEdgeAppearance.ShadowColor = null;
            }
        }
    }
}

Hope it helps.

@Tommigun1980 I was unable to replicate your solution. I've attached a repro with your fix. Are you able to let me know if that works or not for you?

I also had to add an OS version check as ScrollEdgeAppearance was only added in iOS 13 and would crash when running on iOS 12.

NavBarLineTest.zip

@beeradmoore maybe you could use NavigationBar.StandardAppearance.ShadowColor instead of NavigationBar.ScrollEdgeAppearance.ShadowColor.

@DjeeBay thanks! That workaround works. I want to go do some research into them both and see why they exist and how we should integrate into forms.

using System;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;

[assembly: ExportRenderer(typeof(Xamarin.Forms.NavigationPage), typeof(NavBarLineTest.iOS.Renderers.FixNavigationBarHiddenSeparatorRenderer))]

namespace NavBarLineTest.iOS.Renderers
{
    public class FixNavigationBarHiddenSeparatorRenderer : NavigationRenderer
    {
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            if (Element is Xamarin.Forms.NavigationPage navigationPage)
            {
                if (navigationPage.OnThisPlatform().HideNavigationBarSeparator())
                {
                    //NavigationBar.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
                    //NavigationBar.ShadowImage = new UIImage();
                    if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
                    {
                        NavigationBar.StandardAppearance.ShadowColor = null;
                        //NavigationBar.ScrollEdgeAppearance.ShadowColor = null;
                    }
                }
            }
        }
    }
}

This above workaround doesn't work when using a MasterDetailPage. I'm also getting some odd nav bar color flickering (ill card up in a seperate issue soon).

Both issues may be from this commit based on its use of StandardAppearance, but I am not 100% certain.
https://github.com/xamarin/Xamarin.Forms/commit/271e41c166572e334cd76756af11ffa76dc66f1e#diff-efa21a065745b4e261efc4bf6a5d8784

EDIT: Workaround is to create a method to call the update fix code.

void FixNav()
{
    if (navigationPage.OnThisPlatform().HideNavigationBarSeparator())
    {
        if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
        {
            NavigationBar.CompactAppearance.ShadowColor = null;
            NavigationBar.StandardAppearance.ShadowColor = null;
            NavigationBar.ScrollEdgeAppearance.ShadowColor = null;
        }
    }
}

And then call this whenever XF 4.5 calls UpdateBarBackgroundColor()

void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
{
    if (e.PropertyName == NavigationPage.BarBackgroundColorProperty.PropertyName)
    {
        FixNav();
    }
}
public override void ViewDidLoad()
{
    base.ViewDidLoad();
    FixNav();
}

I notice that #9952 appears to be a duplicate of this, and the fix looks to be released in 4.5.0-sr2

However we are still experiencing this issue on that version, including up to the latest prerelease of 4.6, which at the time of writing is 4.6.0-pre4.

Wondering if you could confirm if this is still considered an active issue? Thanks!

Hi any update on this issue? Not fixed on latest stable 4.6 in my use case. Manually setting:

if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
    NavigationBar.CompactAppearance.ShadowColor = UIColor.Clear;
    NavigationBar.StandardAppearance.ShadowColor = UIColor.Clear;
    NavigationBar.ScrollEdgeAppearance.ShadowColor = UIColor.Clear;
}

In a CustomNavigationPage : NavigationRenderer fixes the issue, but it's not reliable and I rather this bug to be fixed. As a result I can not upgrade from 4.4 to 4.5 or 4.6.

I agree with @michaeldimoudis : this issue (as well as #9943) makes it impossible for us to update from 4.4. to anything newer. Any update on this issue?

Would anyone be able to try the current nightly version? You can see how here.

It looks like this one should be fixed and is set to release in the next 4.6 service release. If that's the case, then it should definitely work in the currently nightly.

@jfversluis One of our developers is going to do tests with the nightly build. I will keep you updated.

@jfversluis I just tried the nightly version: 4.8.0.780-nightly, and before that also 4.6.0.369-nightly and the issue is not fixed yet, as we still see the separator

Please note that we use 'ios:NavigationPage.HideNavigationBarSeparator="True"' directly in XAML for pages that we want to hide the separator

Alright, thanks for trying that out. Then it's clear that this is not fixed yet unfortunately

I just tried 4.8.0.780-nightly and yep the it's not fixed yet. Nor is https://github.com/xamarin/Xamarin.Forms/issues/9943

Was this page helpful?
0 / 5 - 0 ratings