From 2064a4f4a6bf1b563069251758b3b5d7e316f9c0 Mon Sep 17 00:00:00 2001 From: Axemasta <33064621+Axemasta@users.noreply.github.com> Date: Tue, 13 Feb 2024 14:05:00 +0000 Subject: [PATCH 1/2] Fix unhandled dismissal of iOS modals I've updated PrismNavigationPage to check when disspearing if the modalpresentationstyle is not default. If the page disspears when this style is set to non default & the navigation source is device, the page will be cleaned up with an extra go back call. --- src/Maui/Prism.Maui/Common/MvvmHelpers.cs | 16 ++++++++++++++++ .../Prism.Maui/Controls/PrismNavigationPage.cs | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/Maui/Prism.Maui/Common/MvvmHelpers.cs b/src/Maui/Prism.Maui/Common/MvvmHelpers.cs index 7014445ff2..f75b3dba85 100644 --- a/src/Maui/Prism.Maui/Common/MvvmHelpers.cs +++ b/src/Maui/Prism.Maui/Common/MvvmHelpers.cs @@ -307,6 +307,22 @@ public static async Task HandleNavigationPageGoBack(NavigationPage navigationPag } } + public static async Task HandleNavigationPageSwipedAway(NavigationPage navigationPage) + { + var navigationService = Navigation.Xaml.Navigation.GetNavigationService(navigationPage.CurrentPage); + var navParams = new NavigationParameters() + { + { + KnownNavigationParameters.UseModalNavigation, true + }, + }; + var result = await navigationService.GoBackAsync(navParams); + if (result.Exception is NavigationException navEx && navEx.Message == NavigationException.CannotPopApplicationMainPage) + { + Application.Current.Quit(); + } + } + public static void HandleSystemGoBack(IView previousPage, IView currentPage) { var parameters = new NavigationParameters(); diff --git a/src/Maui/Prism.Maui/Controls/PrismNavigationPage.cs b/src/Maui/Prism.Maui/Controls/PrismNavigationPage.cs index df6b8cd7a7..16507010de 100644 --- a/src/Maui/Prism.Maui/Controls/PrismNavigationPage.cs +++ b/src/Maui/Prism.Maui/Controls/PrismNavigationPage.cs @@ -1,4 +1,6 @@ using Prism.Common; +using Prism.Navigation; +using UIModalPresentationStyle = Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.UIModalPresentationStyle; namespace Prism.Controls; @@ -39,4 +41,17 @@ private async void HandleBackButtonPressed(object sender, EventArgs args) { await MvvmHelpers.HandleNavigationPageGoBack(this); } + + protected override async void OnDisappearing() + { + var presentationStyle = Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetModalPresentationStyle(this); + + if (presentationStyle != UIModalPresentationStyle.FullScreen && PageNavigationService.NavigationSource == PageNavigationSource.Device) + { + await MvvmHelpers.HandleNavigationPageSwipedAway(this); + } + + base.OnDisappearing(); + } } + From fd4811d8b3fa68fe2a02f2f47b442dc928467976 Mon Sep 17 00:00:00 2001 From: Axemasta <33064621+Axemasta@users.noreply.github.com> Date: Tue, 13 Feb 2024 15:54:08 +0000 Subject: [PATCH 2/2] Workaround now only targets iOS Added ios as a target & added compiler directive to the workaround --- src/Maui/Prism.Maui/Controls/PrismNavigationPage.cs | 2 ++ src/Maui/Prism.Maui/Prism.Maui.csproj | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Maui/Prism.Maui/Controls/PrismNavigationPage.cs b/src/Maui/Prism.Maui/Controls/PrismNavigationPage.cs index 16507010de..87b706199b 100644 --- a/src/Maui/Prism.Maui/Controls/PrismNavigationPage.cs +++ b/src/Maui/Prism.Maui/Controls/PrismNavigationPage.cs @@ -42,6 +42,7 @@ private async void HandleBackButtonPressed(object sender, EventArgs args) await MvvmHelpers.HandleNavigationPageGoBack(this); } +#if IOS protected override async void OnDisappearing() { var presentationStyle = Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetModalPresentationStyle(this); @@ -53,5 +54,6 @@ protected override async void OnDisappearing() base.OnDisappearing(); } +#endif } diff --git a/src/Maui/Prism.Maui/Prism.Maui.csproj b/src/Maui/Prism.Maui/Prism.Maui.csproj index 403f39fe99..547fcc78b6 100644 --- a/src/Maui/Prism.Maui/Prism.Maui.csproj +++ b/src/Maui/Prism.Maui/Prism.Maui.csproj @@ -1,7 +1,7 @@ - net8.0;net8.0-android + net8.0;net8.0-android;net8.0-ios; $(TargetFrameworks);net8.0-windows10.0.19041 Prism provides an implementation of a collection of design patterns that are helpful in writing well structured, maintainable, and testable XAML applications, including MVVM, dependency injection, commanding, event aggregation, and more. Prism's core functionality is a shared library targeting the .NET Framework and .NET. Features that need to be platform specific are implemented in the respective libraries for the target platform (WPF, Uno Platform, .NET MAUI and Xamarin Forms).