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 221aff217929..eff94bfb0f47 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs @@ -400,7 +400,7 @@ void UpdateBackButtonTitle() var previousNavItem = viewControllers[count - 2].NavigationItem; if (previousNavItem != null) { - if (!String.IsNullOrWhiteSpace(text)) + if (text is not null) { var barButtonItem = (previousNavItem.BackBarButtonItem ??= new UIBarButtonItem()); barButtonItem.Title = text; diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/UpdatedBackButtonTitleForEmptyString.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/UpdatedBackButtonTitleForEmptyString.png new file mode 100644 index 000000000000..de054cbeab63 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/UpdatedBackButtonTitleForEmptyString.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue25742.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue25742.cs new file mode 100644 index 000000000000..0f0c0373631d --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue25742.cs @@ -0,0 +1,63 @@ +namespace Maui.Controls.Sample.Issues +{ + [Issue(IssueTracker.Github, 25742, "iOS BackButton title does not update when set to an empty string or whitespace", PlatformAffected.iOS)] + public class Issue25742 : Shell + { + public Issue25742() + { + // Register the routes + Routing.RegisterRoute("page2", typeof(Issue25742Page2)); + + // Create and add Shell contents + var page1 = new ShellContent + { + Title = "Page 1", + Content = new Issue25742Page1() + }; + + Items.Add(page1); + } + } + + public class Issue25742Page1 : ContentPage + { + public Issue25742Page1() + { + Title = "Page 1"; + var navigateButton = new Button + { + Text = "Go to Page 2", + AutomationId = "GotoPage2" + }; + navigateButton.Clicked += OnNavigateToPage2Clicked; + + Content = new StackLayout + { + Children = { navigateButton } + }; + } + + private async void OnNavigateToPage2Clicked(object sender, EventArgs e) + { + await Shell.Current.GoToAsync("page2"); // Use the route name "page2" here + } + } + + public class Issue25742Page2 : ContentPage + { + public Issue25742Page2() + { + Title = "Page 2"; + Content = new StackLayout + { + Children = { new Label { Text = "Welcome to Page 2" } } + }; + + // Set back button behavior with empty TextOverride + Shell.SetBackButtonBehavior(this, new BackButtonBehavior + { + TextOverride = "" // Removes the back button text + }); + } + } +} diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27542.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27542.cs new file mode 100644 index 000000000000..a7a5910ad746 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27542.cs @@ -0,0 +1,26 @@ +#if ANDROID || IOS +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues +{ + public class Issue25742 : _IssuesUITest + { + public override string Issue => "iOS BackButton title does not update when set to an empty string or whitespace"; + + public Issue25742(TestDevice device) : base(device) + { + } + + [Test] + [Category(UITestCategories.Shell)] + public void UpdatedBackButtonTitleForEmptyString() + { + App.WaitForElement("GotoPage2"); + App.Tap("GotoPage2"); + VerifyScreenshot(); + } + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/UpdatedBackButtonTitleForEmptyString.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/UpdatedBackButtonTitleForEmptyString.png new file mode 100644 index 000000000000..8088657fde7c Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/UpdatedBackButtonTitleForEmptyString.png differ