Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unhandled dismissal of iOS modals #3072

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
dansiegel marked this conversation as resolved.
Show resolved Hide resolved
#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
Loading