Skip to content

Commit 12c50ef

Browse files
committed
Update ModalNavigationManager.Android.cs
1 parent 5ed9ca4 commit 12c50ef

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/Controls/src/Core/Platform/ModalNavigationManager/ModalNavigationManager.Android.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,12 @@ sealed class CallBack : OnBackPressedCallback
415415
{
416416
WeakReference<CustomComponentDialog> _customComponentDialog;
417417

418-
private ModalNavigationManager? _modalNavigationManager;
418+
private WeakReference<ModalNavigationManager?> _modalNavigationManager;
419419

420420
public CallBack(bool enabled, CustomComponentDialog customComponentDialog, ModalNavigationManager? modalNavigationManager) : base(enabled)
421421
{
422422
_customComponentDialog = new(customComponentDialog);
423-
_modalNavigationManager = modalNavigationManager;
423+
_modalNavigationManager = new(modalNavigationManager);
424424
}
425425

426426
public override void HandleOnBackPressed()
@@ -456,9 +456,11 @@ public override void HandleOnBackPressed()
456456
}
457457
}
458458

459-
if (!preventBackPropagation)
459+
if (!preventBackPropagation && _modalNavigationManager.TryGetTarget(out var mnm))
460460
{
461-
_ = _modalNavigationManager?.PopModalAsync(true);
461+
{
462+
_ = mnm.PopModalAsync(true);
463+
}
462464
}
463465

464466
eventHandler = null;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
using NUnit.Framework;
1+
#if ANDROID
2+
using NUnit.Framework;
23
using UITest.Appium;
34
using UITest.Core;
45

56
namespace Microsoft.Maui.TestCases.Tests.Issues;
7+
68
public class Issue28811 : _IssuesUITest
79
{
810
public Issue28811(TestDevice testDevice) : base(testDevice)
@@ -21,4 +23,5 @@ public void OverridingBackButtonShouldNotCauseStackOverflow()
2123
App.Back();
2224
App.WaitForElement("NavigateToDetailPage");
2325
}
24-
}
26+
}
27+
#endif

0 commit comments

Comments
 (0)