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 de76cd464460..c24665ef3515 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs @@ -200,12 +200,20 @@ void OnToolbarPropertyChanged(object? sender, PropertyChangedEventArgs e) protected virtual void UpdateTitle() { - if (!ToolbarReady() || NavigationItem is null || _context?.Shell?.Toolbar is null) + + if (NavigationItem is null) + { + return; + } + + if (ToolbarReady() && _context?.Shell?.Toolbar is not null) { + NavigationItem.Title = _context.Shell.Toolbar.Title; return; } - NavigationItem.Title = _context.Shell.Toolbar.Title; + // Update back-stack pages so iOS back button/history menu reflects title changes + NavigationItem.Title = Page?.Title; } diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue35471.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue35471.cs new file mode 100644 index 000000000000..75d49ad0b44a --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue35471.cs @@ -0,0 +1,67 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 35471, "iOS Shell back button history menu does not update after runtime culture change", PlatformAffected.iOS | PlatformAffected.macOS)] +public class Issue35471 : TestShell +{ + ContentPage _rootPage; + + protected override void Init() + { + _rootPage = CreateContentPage("HomePage"); + _rootPage.Title = "Home"; + + var navigateButton = new Button + { + AutomationId = "NavigateToDetail", + Text = "Go to Detail Page", + Command = new Command(async () => + { + await Navigation.PushAsync(new Issue35471DetailPage(_rootPage)); + }) + }; + + _rootPage.Content = new VerticalStackLayout + { + Padding = 20, + Spacing = 10, + Children = + { + new Label { Text = "Root Page", AutomationId = "RootPageLabel" }, + navigateButton + } + }; + } + + class Issue35471DetailPage : ContentPage + { + readonly ContentPage _previousPage; + + public Issue35471DetailPage(ContentPage previousPage) + { + _previousPage = previousPage; + Title = "Detail"; + + var changeTitleButton = new Button + { + AutomationId = "ChangePreviousPageTitle", + Text = "Change Previous Page Title (simulate culture change)", + Command = new Command(() => + { + // Simulate runtime culture change by updating the previous page's title + _previousPage.Title = "Accueil"; + }) + }; + + Content = new VerticalStackLayout + { + Padding = 20, + Spacing = 10, + Children = + { + new Label { Text = "Detail Page", FontSize = 20 }, + changeTitleButton + } + }; + } + } +} diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue35471.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue35471.cs new file mode 100644 index 000000000000..a02850495562 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue35471.cs @@ -0,0 +1,45 @@ +// iOS/MacCatalyst only: The fix updates UINavigationItem.Title for back-stack pages, +// which iOS uses to display the back button text. This is an Apple platform-specific behavior. +#if IOS || MACCATALYST +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues +{ + public class Issue35471 : _IssuesUITest + { + public override string Issue => "iOS Shell back button history menu does not update after runtime culture change"; + + public Issue35471(TestDevice device) : base(device) + { + } + + [Test] + [Category(UITestCategories.Shell)] + public void ShellBackButtonHistoryUpdatesAfterTitleChange() + { + // iOS 26+ no longer exposes the back button title text via accessibility, + // so there is no reliable way to assert the updated title in a UI test. + if (App is AppiumIOSApp iosApp && HelperExtensions.IsIOS26OrHigher(iosApp)) + { + Assert.Ignore("iOS 26+ does not expose back button title text via accessibility"); + } + + // Navigate to Detail page + App.WaitForElement("NavigateToDetail"); + App.Tap("NavigateToDetail"); + + // Change the previous page's title (simulates runtime culture change) + App.WaitForElement("ChangePreviousPageTitle"); + App.Tap("ChangePreviousPageTitle"); + + // Verify back button now shows updated title "Accueil" + // Without the fix, UINavigationItem.Title is stale and still shows "Home" + App.WaitForElement("Accueil"); + App.Tap("Accueil"); + App.WaitForElement("RootPageLabel"); + } + } +} +#endif