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 0c8b06c923d6..f22805bfe85b 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs @@ -325,6 +325,7 @@ void UpdateLeftToolbarItems() if (!IsRootPage) { NavigationItem.HidesBackButton = !backButtonVisible; + image = backButtonVisible ? image : null; } image.LoadImage(MauiContext, result => diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BackButtonBehaviorIsVisibleWorksWithCustomIcon.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BackButtonBehaviorIsVisibleWorksWithCustomIcon.png new file mode 100644 index 000000000000..98fe5dd94070 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BackButtonBehaviorIsVisibleWorksWithCustomIcon.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue23424.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue23424.xaml.cs new file mode 100644 index 000000000000..4fa5b2455916 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue23424.xaml.cs @@ -0,0 +1,35 @@ +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()); + 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) + } + }; + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue23424.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue23424.cs new file mode 100644 index 000000000000..3f446e0a708d --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue23424.cs @@ -0,0 +1,28 @@ +#if !MACCATALYST +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 BackButtonBehaviorIsVisibleWorksWithCustomIcon() + { + App.WaitForElement("button"); + App.Click("button"); + + // The test passes if the back button is not visible + VerifyScreenshot(); + } + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/BackButtonBehaviorIsVisibleWorksWithCustomIcon.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/BackButtonBehaviorIsVisibleWorksWithCustomIcon.png new file mode 100644 index 000000000000..2de02896bb1a Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/BackButtonBehaviorIsVisibleWorksWithCustomIcon.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/BackButtonBehaviorIsVisibleWorksWithCustomIcon.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/BackButtonBehaviorIsVisibleWorksWithCustomIcon.png new file mode 100644 index 000000000000..0cbdd62c2b6a Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/BackButtonBehaviorIsVisibleWorksWithCustomIcon.png differ