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

Fixed the iOS BackButton title does not update when set to an empty string or whitespace #25813

Merged
merged 6 commits into from
Nov 26, 2024
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 @@ -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;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25742.cs
Original file line number Diff line number Diff line change
@@ -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
});
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading