arvindhK
arvindhK

Reputation: 31

Navigation bar colour change issue in Xamarin.forms in iOS platform after iOS 15 update

In the application I developed, the navigation bar at the bottom of the screen, changes its color between black and white depending on the theme selected by the user. It worked perfectly all this time until I updated the software to iOS 15. Now, even if the user changes it to dark mode, the navigation bar alone stays white (supposed to turn black). Any idea why this happens? This issue only persists in iOS platform.

Upvotes: 3

Views: 2009

Answers (2)

Gerald Versluis
Gerald Versluis

Reputation: 33993

Update 2: Current versions (at the time of writing 5.0.0.2244) should fix this issue

Update: Fixes for this are merged and should be released soon!

This is a known issue that we are tracking here. A workaround is mentioned in there in the form of a custom renderer, I will paste it here but this is specific to Shell though. But it might give you some hint on how to use it on regular components as well.

using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(APPNAME.AppShell), typeof(APPNAME.iOS.Renderers.CustomShellRenderer))]
namespace APPNAME.iOS.Renderers
{

    public class CustomShellRenderer : ShellRenderer
    {
        protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection)
        {
            var renderer = base.CreateShellSectionRenderer(shellSection);
            
            if (renderer != null)
            {
                if (renderer is ShellSectionRenderer shellRenderer)
                {
                    
    
                    var appearance = new UINavigationBarAppearance();
                    appearance.ConfigureWithOpaqueBackground();
                    appearance.BackgroundColor = new UIColor(red: 0.86f, green: 0.24f, blue: 0.00f, alpha: 1.00f);
                    
                    appearance.TitleTextAttributes = new UIStringAttributes() { ForegroundColor = UIColor.White};
                    
              
                    shellRenderer.NavigationBar.Translucent = false;
                    shellRenderer.NavigationBar.StandardAppearance = appearance;
                    shellRenderer.NavigationBar.ScrollEdgeAppearance = shellRenderer.NavigationBar.StandardAppearance;
                    
                }
            }

            return renderer;
        }

        protected override IShellItemRenderer CreateShellItemRenderer(ShellItem item)
        {
            var renderer = base.CreateShellItemRenderer(item);
            
            if (renderer != null)
            {
                if (renderer is ShellItemRenderer shellItemRenderer)
                {
                    var appearance = new UITabBarAppearance();
                    
                    appearance.ConfigureWithOpaqueBackground();

                    shellItemRenderer.TabBar.Translucent = false;
                    shellItemRenderer.TabBar.StandardAppearance = appearance;
               
                }
                

            }

            return renderer;
        }
        
    }
}

The issue seems to be caused by compiling against Xcode 13/running on iOS 15. Other peoples in the linked issue have mentioned that downgrading their Xcode made it work for them.

TL;DR: we're working on a fix that should be released soon :)

Upvotes: 5

 ConstantLearning
ConstantLearning

Reputation: 11

Hello the problem is fixed in pre-release Xamarin Form add source Nuget to access it https://aka.ms/forms-prs/index.json

Then you can install the package Xamarin Form 5.0.0.7649 and solve the problem.

To more information visit the bug in the page of proyect in GitHub: https://github.com/xamarin/Xamarin.Forms/issues/14505

Upvotes: 1

Related Questions