Skip to content

Commit

Permalink
Merge pull request #3072 from Axemasta/axemasta/fix-3071
Browse files Browse the repository at this point in the history
Fix unhandled dismissal of iOS modals
  • Loading branch information
dansiegel committed Feb 14, 2024
2 parents 8035565 + fd4811d commit fa61b55
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/Maui/Prism.Maui/Common/MvvmHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions src/Maui/Prism.Maui/Controls/PrismNavigationPage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Prism.Common;
using Prism.Navigation;
using UIModalPresentationStyle = Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.UIModalPresentationStyle;

namespace Prism.Controls;

Expand Down Expand Up @@ -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
}

2 changes: 1 addition & 1 deletion src/Maui/Prism.Maui/Prism.Maui.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net8.0-android</TargetFrameworks>
<TargetFrameworks>net8.0;net8.0-android;net8.0-ios;</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041</TargetFrameworks>
<Description>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).

Expand Down

0 comments on commit fa61b55

Please sign in to comment.