You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[BUG] When using iOS ModalPresentationStyles that can be automatically dismissed, navigation service gets out of sync & stops working with NavigationPage
#3071
Closed
Axemasta opened this issue
Feb 13, 2024
· 2 comments
Closing the popover by using the iOS swipe gesture (using Prism to close the modal works as intended), will cause the navigation service to lock up.
I have investigated with a local sample connected to the prism source code and the following happens:
Prism does not know the current page has been dismissed & holds a reference to it
The first time you call the navigation service, there will be an error output in the console:
[Presentation] Attempt to present <Microsoft_Maui_Controls_Platform_ControlsModalWrapper: 0x107931000> on <Microsoft_Maui_Controls_Platform_ControlsModalWrapper: 0x1087425e0> (from <Microsoft_Maui_Controls_Handlers_Compatibility_NavigationRenderer: 0x10c842400>) whose view is not in the window hierarchy.
Subsequent calls to the navigation service get deadlocked because the original semaphore for the previous attempt doesn't get cleared, this looks like the thread actually crashes since the finally & exception blocks on NavigateAsync don't get called.
Normal content pages presented in this way are unaffected, I believe this is because prism is listening for their disappeared events which do fire.
Steps to Reproduce
Create a prism app
Add a modal page to navigate to:
privateasyncvoidOnNavPopover(){varnav=awaitnavigationService.CreateBuilder().AddNavigationPage(true).AddSegment<PopoverViewModel>().NavigateAsync();if(!nav.Success){Debugger.Break();}}3. Swipe the popover closed
4. Try to navigate again, nothing happens&the following warning is present in the console:
[Presentation] Attempt to present <Microsoft_Maui_Controls_Platform_ControlsModalWrapper: 0x107931000> on <Microsoft_Maui_Controls_Platform_ControlsModalWrapper: 0x1087425e0> (from <Microsoft_Maui_Controls_Handlers_Compatibility_NavigationRenderer: 0x10c842400>) whose view is not in the window hierarchy.
5. The navigation service is now soft locked and can't be used for any navigation
### Platform with bug
.NET MAUI
### Affected platforms
iOS
### Did you find any workaround?
I will be raising a PR to address this issue, if the following code is added to the `PrismNavigationPage`, `GoBackAsync` can be called after the page removal to ensure that the navigation service remains in sync with the app's page stack:
```csharp
protected override async void OnDisappearing()
{
var presentationStyle = Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetModalPresentationStyle(this);
if (presentationStyle == UIModalPresentationStyle.FullScreen)
{
return;
}
if (PageNavigationService.NavigationSource == PageNavigationSource.Device)
{
await MvvmHelpers.HandleNavigationPageSwipedAway(this);
}
base.OnDisappearing();
}
Relevant log output
No response
The text was updated successfully, but these errors were encountered:
Here is a little clip from my repro sample, you can see that as soon as I close the navigation page popover, the other commands stop working, the view model code is below & is incredibly simple:
Description
When working with a modal navigation page, where the page in question has the following iOS specific presentation style:
Closing the popover by using the iOS swipe gesture (using Prism to close the modal works as intended), will cause the navigation service to lock up.
I have investigated with a local sample connected to the prism source code and the following happens:
NavigateAsync
don't get called.Normal content pages presented in this way are unaffected, I believe this is because prism is listening for their disappeared events which do fire.
Steps to Reproduce
[Presentation] Attempt to present <Microsoft_Maui_Controls_Platform_ControlsModalWrapper: 0x107931000> on <Microsoft_Maui_Controls_Platform_ControlsModalWrapper: 0x1087425e0> (from <Microsoft_Maui_Controls_Handlers_Compatibility_NavigationRenderer: 0x10c842400>) whose view is not in the window hierarchy.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: