Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public void ResetAppearance(UINavigationController controller)
navBar.BarTintColor = _defaultBarTint;
navBar.TintColor = _defaultTint;
navBar.TitleTextAttributes = _defaultTitleAttributes;

if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13))
UpdateiOS13NavigationBarAppearance(controller, null);
}
}

Expand Down Expand Up @@ -95,37 +98,47 @@ void UpdateiOS13NavigationBarAppearance(UINavigationController controller, Shell

var navigationBarAppearance = new UINavigationBarAppearance();

// since we cannot set the Background Image directly, let's use the alpha in the background color to determine translucence
if (appearance.BackgroundColor?.Alpha < 1.0f)
{
navigationBarAppearance.ConfigureWithTransparentBackground();
navBar.Translucent = true;
}
else
if (appearance is null)
{
navigationBarAppearance.ConfigureWithOpaqueBackground();
navBar.Translucent = false;
navBar.StandardAppearance = navBar.ScrollEdgeAppearance = navigationBarAppearance;
}
else
{

// Set ForegroundColor
var foreground = appearance.ForegroundColor;
// since we cannot set the Background Image directly, let's use the alpha in the background color to determine translucence
if (appearance.BackgroundColor?.Alpha < 1.0f)
{
navigationBarAppearance.ConfigureWithTransparentBackground();
navBar.Translucent = true;
}
else
{
navigationBarAppearance.ConfigureWithOpaqueBackground();
navBar.Translucent = false;
}

if (foreground != null)
navBar.TintColor = foreground.ToPlatform();
// Set ForegroundColor
var foreground = appearance.ForegroundColor;

// Set BackgroundColor
var background = appearance.BackgroundColor;
if (foreground != null)
navBar.TintColor = foreground.ToPlatform();

if (background != null)
navigationBarAppearance.BackgroundColor = background.ToPlatform();
// Set BackgroundColor
var background = appearance.BackgroundColor;

// Set TitleColor
var titleColor = appearance.TitleColor;
if (background != null)
navigationBarAppearance.BackgroundColor = background.ToPlatform();

if (titleColor != null)
navigationBarAppearance.TitleTextAttributes = new UIStringAttributes() { ForegroundColor = titleColor.ToPlatform() };
// Set TitleColor
var titleColor = appearance.TitleColor;

navBar.StandardAppearance = navBar.ScrollEdgeAppearance = navigationBarAppearance;
if (titleColor != null)
navigationBarAppearance.TitleTextAttributes = new UIStringAttributes() { ForegroundColor = titleColor.ToPlatform() };

navBar.StandardAppearance = navBar.ScrollEdgeAppearance = navigationBarAppearance;
}
}

void UpdateNavigationBarAppearance(UINavigationController controller, ShellAppearance appearance)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue33227.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 33227, "Shell NavigationBar colors persist when navigating between pages", PlatformAffected.iOS | PlatformAffected.UWP)]
public class Issue33227 : Shell
{
public Issue33227()
{
var tabBar = new TabBar { Title = "Tab1" };
var tab = new Tab { Title = "Tab1" };

var page1Content = new ShellContent
{
Title = "Page1",
ContentTemplate = new DataTemplate(() => new Issue33227Page1())
};

var page2Content = new ShellContent
{
Title = "Page2",
ContentTemplate = new DataTemplate(() => new Issue33227Page2())
};

tab.Items.Add(page1Content);
tab.Items.Add(page2Content);
tabBar.Items.Add(tab);
Items.Add(tabBar);
}
}

public class Issue33227Page1 : ContentPage
{
public Issue33227Page1()
{
var layout = new VerticalStackLayout
{
Padding = 20,
Spacing = 10,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center
};

var label = new Label
{
Text = "Page1",
AutomationId = "Page1Label"
};

layout.Add(label);
Content = layout;
}
}

public class Issue33227Page2 : ContentPage
{
public Issue33227Page2()
{
Shell.SetBackgroundColor(this, Colors.Yellow);
Shell.SetTitleColor(this, Colors.Orange);

var layout = new VerticalStackLayout
{
Padding = 20,
Spacing = 10,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center
};

var label = new Label
{
Text = "Page2",
AutomationId = "Page2Label"
};

layout.Add(label);
Content = layout;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.Maui.TestCases.Tests;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Maui.Controls.TestCases.Tests.Issues;

public class Issue33227 : _IssuesUITest
{
public Issue33227(TestDevice device) : base(device)
{
}

public override string Issue => "Shell NavigationBar colors persist when navigating between pages";

[Test]
[Category(UITestCategories.Shell)]
public void ShellColorsResetOnNavigation()
{
#if WINDOWS
App.TapTab("Tab1");
App.WaitForElement("Page2");
App.Tap("Page2");
App.TapTab("Tab1");
App.WaitForElement("Page1");
App.Tap("Page1");
App.WaitForElement("Page1Label");
#else
App.TapTab("Page2");
App.TapTab("Page1");
App.WaitForElement("Page1Label");
#endif
VerifyScreenshot();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/Core/src/Platform/Windows/MauiToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ internal void SetBarTextColor(WBrush? brush)
{
title.Foreground = brush;
}
else
{
title.ClearValue(CommandBar.ForegroundProperty);
}

_menuBarForeground = brush;
UpdateMenuBarForeground();
Expand Down
Loading