Skip to content
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 @@ -233,6 +233,10 @@ protected async virtual void OnNavigateBack()
{
try
{
// Call OnBackButtonPressed to allow the page to intercept navigation
if (Page?.SendBackButtonPressed() == true)
return;

await Page.Navigation.PopAsync();
}
catch (Exception exc)
Expand Down
75 changes: 75 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue33523.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 33523, "OnBackButtonPressed not firing for Shell Navigation Bar button in .NET 10 SR2", PlatformAffected.Android)]
public class Issue33523 : Shell
{
public Issue33523()
{
var mainPage = new ContentPage
{
Title = "Main Page",
Content = new VerticalStackLayout
{
Children =
{
new Label
{
Text = "Click the button to navigate to TestPage",
AutomationId = "MainPageLabel"
},
new Button
{
Text = "Navigate to TestPage",
AutomationId = "NavigateButton",
Command = new Command(async () => await Shell.Current.GoToAsync("TestPage"))
}
}
}
};

Items.Add(new ShellContent { Content = mainPage, Route = "MainPage" });

Routing.RegisterRoute("TestPage", typeof(TestPage));
}

class TestPage : ContentPage
{
private Label _statusLabel;

public TestPage()
{
Title = "Test Page";

_statusLabel = new Label
{
Text = "OnBackButtonPressed not called",
AutomationId = "StatusLabel"
};

Content = new VerticalStackLayout
{
Children =
{
new Label
{
Text = "Click the Navigation Bar back button (←)",
AutomationId = "InstructionLabel"
},
_statusLabel
}
};
}

protected override bool OnBackButtonPressed()
{
// Update the label synchronously
_statusLabel.Text = "OnBackButtonPressed was called";

// Return true to prevent navigation (so we can verify the label changed)
return true;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue33523 : _IssuesUITest
{
public override string Issue => "OnBackButtonPressed not firing for Shell Navigation Bar button in .NET 10 SR2";

public Issue33523(TestDevice device) : base(device) { }

[Test]
[Category(UITestCategories.Shell)]
public void OnBackButtonPressedShouldFireForShellNavigationBarButton()
{
// Verify we're on the main page
App.WaitForElement("MainPageLabel");

// Navigate to TestPage
App.Tap("NavigateButton");
App.WaitForElement("StatusLabel");

// Verify initial state
var statusLabel = App.WaitForElement("StatusLabel");
Assert.That(statusLabel.GetText(), Is.EqualTo("OnBackButtonPressed not called"));

// Tap the navigation bar back button
// Note: This uses the Shell's navigation bar back button, not the system back button
App.TapBackArrow();

// Wait a moment for the event to fire
App.WaitForElement("StatusLabel");

// Verify OnBackButtonPressed was called
statusLabel = App.FindElement("StatusLabel");
Assert.That(statusLabel.GetText(), Is.EqualTo("OnBackButtonPressed was called"),
"OnBackButtonPressed should be called when tapping the Shell Navigation Bar back button");
}
}
}
Loading