diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs index 8826058cee0f..c2c5dca29516 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs @@ -107,7 +107,10 @@ protected virtual void HandleShellPropertyChanged(object sender, PropertyChanged if (e.Is(VisualElement.FlowDirectionProperty)) UpdateFlowDirection(); else if (e.Is(Shell.FlyoutIconProperty) || e.Is(Shell.ForegroundColorProperty)) + { UpdateLeftToolbarItems(); + UpdateRightBarButtonItemTintColors(); + } } #nullable disable @@ -154,6 +157,7 @@ protected virtual void OnPagePropertyChanged(object sender, PropertyChangedEvent else if (e.PropertyName == Shell.ForegroundColorProperty.PropertyName) { UpdateLeftToolbarItems(); + UpdateRightBarButtonItemTintColors(); } } @@ -455,9 +459,37 @@ protected virtual void UpdateToolbarItems() NavigationItem.SetRightBarButtonItems(primaries is null ? Array.Empty() : primaries.ToArray(), false); + UpdateRightBarButtonItemTintColors(); UpdateLeftToolbarItems(); } + /// iOS 26+: LiquidGlass no longer inherits the foreground color from the navigation bar's TintColor. + /// Explicitly set TintColor on each right bar button item to ensure the Shell.ForegroundColor is applied. + void UpdateRightBarButtonItemTintColors() + { + if (!(OperatingSystem.IsIOSVersionAtLeast(26) || OperatingSystem.IsMacCatalystVersionAtLeast(26))) + { + return; + } + + if (NavigationItem?.RightBarButtonItems is not { Length: > 0 } rightItems) + { + return; + } + + var foregroundColor = _context?.Shell?.CurrentPage?.GetValue(Shell.ForegroundColorProperty) ?? + _context?.Shell?.GetValue(Shell.ForegroundColorProperty); + + var platformColor = foregroundColor is Graphics.Color shellForegroundColor + ? shellForegroundColor.ToPlatform() + : null; + + foreach (var item in rightItems) + { + item.TintColor = platformColor; + } + } + void UpdateLeftToolbarItems() { var shell = _context?.Shell; diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue34083.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue34083.cs new file mode 100644 index 000000000000..e3f8e3175699 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue34083.cs @@ -0,0 +1,32 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 34083, "Toolbar Items Do Not Reflect Shell ForegroundColor", PlatformAffected.iOS)] +public class Issue34083 : Shell +{ + public Issue34083() + { + Items.Add(new Issue34083Page()); + Shell.SetForegroundColor(this, Colors.Purple); + } + + public class Issue34083Page : ContentPage + { + public Issue34083Page() + { + Title = "Home"; + ToolbarItems.Add(new ToolbarItem + { + IconImageSource = "calculator.png", + Order = ToolbarItemOrder.Primary + }); + + Content = new Label + { + Text = "The test passes if the color is being applied to the toolbar.", + AutomationId = "Issue34083_DescriptionLabel", + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center + }; + } + } +} diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyShellForegroundColorIsAppliedToToolbarItems.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyShellForegroundColorIsAppliedToToolbarItems.png new file mode 100644 index 000000000000..18d3263d2f28 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyShellForegroundColorIsAppliedToToolbarItems.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue34083.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue34083.cs new file mode 100644 index 000000000000..9f4d578494ce --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue34083.cs @@ -0,0 +1,24 @@ +#if TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_WINDOWS // Android Issue Link: https://github.com/dotnet/maui/issues/24676, Windows Issue Link: https://github.com/dotnet/maui/issues/34071 +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue34083 : _IssuesUITest +{ + public Issue34083(TestDevice testDevice) : base(testDevice) + { + } + + public override string Issue => "Toolbar Items Do Not Reflect Shell ForegroundColor"; + + [Test] + [Category(UITestCategories.Shell)] + public void VerifyShellForegroundColorIsAppliedToToolbarItems() + { + App.WaitForElement("Issue34083_DescriptionLabel"); + VerifyScreenshot(); + } +} +#endif diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/VerifyShellForegroundColorIsAppliedToToolbarItems.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/VerifyShellForegroundColorIsAppliedToToolbarItems.png new file mode 100644 index 000000000000..62f6c79ee6ec Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/VerifyShellForegroundColorIsAppliedToToolbarItems.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyShellForegroundColorIsAppliedToToolbarItems.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyShellForegroundColorIsAppliedToToolbarItems.png new file mode 100644 index 000000000000..bfb2fd03887e Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyShellForegroundColorIsAppliedToToolbarItems.png differ