diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs index aabf4cc14bc7..abf73c016df3 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs @@ -130,9 +130,15 @@ internal bool SendPop() if (tracker.Value.ViewController == TopViewController) { var behavior = Shell.GetEffectiveBackButtonBehavior(tracker.Value.Page); + var enabled = behavior.GetPropertyIfSet(BackButtonBehavior.IsEnabledProperty, true); var command = behavior.GetPropertyIfSet(BackButtonBehavior.CommandProperty, null); var commandParameter = behavior.GetPropertyIfSet(BackButtonBehavior.CommandParameterProperty, null); + if (!enabled) + { + return false; + } + if (command != null) { if (command.CanExecute(commandParameter)) diff --git a/src/Controls/src/Core/Shell/BackButtonBehavior.cs b/src/Controls/src/Core/Shell/BackButtonBehavior.cs index b75a45c308fa..d3d3f1e85278 100644 --- a/src/Controls/src/Core/Shell/BackButtonBehavior.cs +++ b/src/Controls/src/Core/Shell/BackButtonBehavior.cs @@ -89,7 +89,7 @@ public string TextOverride set { SetValue(TextOverrideProperty, value); } } - bool IsEnabledCore { set => SetValue(IsEnabledProperty, value); } + bool IsEnabledCore { set => SetValue(IsEnabledProperty, value && IsEnabled); } static void OnCommandChanged(BindableObject bindable, object oldValue, object newValue) { diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue28722.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue28722.cs new file mode 100644 index 000000000000..9036cac016d7 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue28722.cs @@ -0,0 +1,45 @@ +namespace Maui.Controls.Sample.Issues; +[Issue(IssueTracker.Github, 28722, "IsEnabled does not work in BackButtonBehavior", PlatformAffected.iOS)] +public class Issue28722 : Shell +{ + public Issue28722() + { + Routing.RegisterRoute(nameof(Issue28722Page1), typeof(Issue28722Page1)); + Items.Add(new ContentPage()); + } + + protected override void OnAppearing() + { + base.OnAppearing(); + Current.GoToAsync(nameof(Issue28722Page1)); + + } +} + +public class Issue28722Page1 : ContentPage +{ + public Issue28722Page1() + { + var label = new Label() + { + Text = "Welcome to Page 1", + AutomationId = "HelloLabel", + IsVisible = false + }; + + var backButtonBehavior = new BackButtonBehavior() + { + IsEnabled = true, + TextOverride = "Click", + }; + + backButtonBehavior.Command = new Command(() => + { + label.IsVisible = !label.IsVisible; + backButtonBehavior.IsEnabled = false; + }); + + Shell.SetBackButtonBehavior(this, backButtonBehavior); + Content = label; + } +} diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28722.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28722.cs new file mode 100644 index 000000000000..ba48c84cf8a5 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28722.cs @@ -0,0 +1,26 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues +{ + public class Issue28722 : _IssuesUITest + { + public Issue28722(TestDevice testDevice) : base(testDevice) + { + } + + public override string Issue => "IsEnabled does not work in BackButtonBehavior"; + + [Test] + [Category(UITestCategories.Shell)] + public void IsEnabledShouldWorkInBackButtonBehavior() + { + App.WaitForElement("Click"); + App.Click("Click"); + App.WaitForElement("HelloLabel"); + App.Click("Click"); + App.WaitForElement("HelloLabel"); + } + } +} \ No newline at end of file