Skip to content

Commit 920d069

Browse files
committed
Fixed OnBackButtonPressed not firing for Shell Navigation
1 parent 6c123d7 commit 920d069

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ internal bool SendPop()
143143
return false;
144144
}
145145

146+
// Allow the page to intercept back navigation via OnBackButtonPressed
147+
if (tracker.Value.Page?.SendBackButtonPressed() == true)
148+
{
149+
return false;
150+
}
151+
146152
break;
147153
}
148154
}

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33523.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#if TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_IOS // Issue: https://github.com/dotnet/maui/issues/34190
2-
31
using NUnit.Framework;
42
using UITest.Appium;
53
using UITest.Core;
@@ -26,19 +24,20 @@ public void OnBackButtonPressedShouldFireForShellNavigationBarButton()
2624
// Verify initial state
2725
var statusLabel = App.WaitForElement("StatusLabel");
2826
Assert.That(statusLabel.GetText(), Is.EqualTo("OnBackButtonPressed not called"));
29-
27+
#if IOS || MACCATALYST
28+
App.TapBackArrow("Main Page");
29+
#else
3030
// Tap the navigation bar back button
3131
// Note: This uses the Shell's navigation bar back button, not the system back button
3232
App.TapBackArrow();
33-
33+
#endif
3434
// Wait a moment for the event to fire
3535
App.WaitForElement("StatusLabel");
3636

3737
// Verify OnBackButtonPressed was called
3838
statusLabel = App.FindElement("StatusLabel");
39-
Assert.That(statusLabel.GetText(), Is.EqualTo("OnBackButtonPressed was called"),
39+
Assert.That(statusLabel.GetText(), Is.EqualTo("OnBackButtonPressed was called"),
4040
"OnBackButtonPressed should be called when tapping the Shell Navigation Bar back button");
4141
}
4242
}
4343
}
44-
#endif

0 commit comments

Comments
 (0)