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

Shell BackButtonBehavior improvement #23466

Merged
merged 4 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -322,11 +322,6 @@ void UpdateLeftToolbarItems()
image = _context.Shell.FlyoutIcon;
}

if (!IsRootPage)
{
NavigationItem.HidesBackButton = !backButtonVisible;
kubaflo marked this conversation as resolved.
Show resolved Hide resolved
}

image.LoadImage(MauiContext, result =>
{
UIImage icon = null;
Expand Down Expand Up @@ -373,6 +368,13 @@ void UpdateLeftToolbarItems()
}
});

if (!IsRootPage)
{
NavigationItem.HidesBackButton = !backButtonVisible;
if(!backButtonVisible)
NavigationItem.LeftBarButtonItem = null;
}

UpdateBackButtonTitle();
}

Expand Down
36 changes: 36 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue23424.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Maui.Controls.Sample.Issues;

[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, "23424", "BackButtonBehavior IsVisible=False does not hide the back button", PlatformAffected.All)]
public partial class Issue23424 : Shell
{
public Issue23424()
{
Items.Add(new ContentPage());
Routing.RegisterRoute(nameof(DetailPage),typeof(DetailPage));
GoToAsync(nameof(DetailPage));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to register a route here.

Maybe just this to keep it simple

Items.Add(new ContentPage());
		Navigation.PushAsync(new DetailPage());

}

public class DetailPage : ContentPage
{
public DetailPage()
{
Title = "Detail page";
BackButtonBehavior backButtonBehavior = new BackButtonBehavior
{
IconOverride = "small_dotnet_bot.png"
};

SetBackButtonBehavior(this, backButtonBehavior);
Content = new VerticalStackLayout()
{
new Button()
{
AutomationId = "button",
Text = "Click to hide the back button",
Command = new Command(()=>backButtonBehavior.IsVisible =! backButtonBehavior.IsVisible)
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue23424: _IssuesUITest
{
public Issue23424(TestDevice device) : base(device)
{
}

public override string Issue => "BackButtonBehavior IsVisible=False does not hide the back button";

[Test]
[Category(UITestCategories.Shell)]
public void RadioButtonWithValueChangeSelected()
{
App.WaitForElement("button");
App.Click("button");

// The test passes if the back button is not visible
VerifyScreenshot();
}
}
}