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..87b706199b 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,19 @@ 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); + + if (presentationStyle != UIModalPresentationStyle.FullScreen && PageNavigationService.NavigationSource == PageNavigationSource.Device) + { + await MvvmHelpers.HandleNavigationPageSwipedAway(this); + } + + 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).