Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NavigationBarColors from NavigationPage not changing on AppTheme changing - fix #24766

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 23 additions & 3 deletions src/Controls/src/Core/Menu/MenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ public partial class MenuItem : BaseMenuItem, IMenuItemController, IStyleSelecta

/// <summary>Bindable property for <see cref="IconImageSource"/>.</summary>
public static readonly BindableProperty IconImageSourceProperty = BindableProperty.Create(nameof(IconImageSource), typeof(ImageSource), typeof(MenuItem), default(ImageSource),
propertyChanged: (bindable, oldValue, newValue) => {
((MenuItem)bindable).AddRemoveLogicalChildren(oldValue, newValue);
}
propertyChanged: (bindable, oldValue, newValue) =>
{
((MenuItem)bindable).AddRemoveLogicalChildren(oldValue, newValue);
((MenuItem)bindable).OnSourcePropertyChanged(oldValue, newValue);
}
);

/// <summary>Bindable property for <see cref="IsEnabled"/>.</summary>
Expand Down Expand Up @@ -207,5 +209,23 @@ static void OnIsEnabledPropertyChanged(BindableObject bindable, object oldValue,

ppc.PropagatePropertyChanged(IsEnabledProperty.PropertyName);
}

void OnSourcePropertyChanged(object oldValue, object newValue)
{
if (oldValue is ImageSource oldSource)
{
oldSource.SourceChanged -= OnSourceChanged;
}

if (newValue is ImageSource newSource)
{
newSource.SourceChanged += OnSourceChanged;
}
}

void OnSourceChanged(object sender, EventArgs e)
{
OnPropertyChanged(IconImageSourceProperty.PropertyName);
}
}
}
31 changes: 31 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issues23195.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8" ?>
<NavigationPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Name="Self"
BarBackgroundColor="{AppThemeBinding Light=White,Dark=Black}"
BarTextColor="{AppThemeBinding Light=Black,Dark=White}"
x:Class="Maui.Controls.Sample.Issues.Issue23195">
<x:Arguments>
<ContentPage x:Name="contentPage" Title="Content page">
<ContentPage.ToolbarItems>
<ToolbarItem>
<ToolbarItem.IconImageSource>
<FontImageSource Glyph="&#xf133;"
Color="{AppThemeBinding Light=Black, Dark=White}"
FontFamily="FA"/>
</ToolbarItem.IconImageSource>
</ToolbarItem>
</ContentPage.ToolbarItems>
<VerticalStackLayout>
<Button Text="Chnage theme"
AutomationId="button"
HeightRequest="100"
Clicked="Button_Clicked"/>
<Label Text="Dark theme applied"
IsVisible="{AppThemeBinding Default=False,Dark=True}"
AutomationId="label"/>
</VerticalStackLayout>
</ContentPage>
</x:Arguments>
</NavigationPage>
18 changes: 18 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issues23195.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 23195, "NavigationBarColors from NavigationPage not changing on AppTheme changing", PlatformAffected.Android | PlatformAffected.iOS)]
public partial class Issue23195 : NavigationPage
{
public Issue23195()
{
InitializeComponent();
PushAsync(contentPage);
}

public void Button_Clicked(object sender, EventArgs eventArgs)
{
Application.Current!.UserAppTheme = AppTheme.Dark;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if IOS || ANDROID
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue23195 : _IssuesUITest
{
public override string Issue => "NavigationBarColors from NavigationPage not changing on AppTheme changing";

public Issue23195(TestDevice device) : base(device)
{
}

[Test]
[Category(UITestCategories.Page)]
public void Issue23195Test()
{
App.WaitForElement("button");
App.Click("button");
App.WaitForElement("label");
VerifyScreenshot();
}
}
}
#endif
Loading