diff --git a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs index fc00b1ae8..0adc36116 100644 --- a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs +++ b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs @@ -1,12 +1,12 @@ using System.ComponentModel; using System.Globalization; -using System.Windows.Input; using CommunityToolkit.Maui.Converters; using CommunityToolkit.Maui.Core; -using CommunityToolkit.Maui.Extensions; using Microsoft.Maui.Controls.PlatformConfiguration; using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific; using Microsoft.Maui.Controls.Shapes; +using NavigationPage = Microsoft.Maui.Controls.NavigationPage; +using Page = Microsoft.Maui.Controls.Page; namespace CommunityToolkit.Maui.Views; @@ -66,6 +66,7 @@ public PopupPage(Popup popup, IPopupOptions? popupOptions) Shell.SetPresentationMode(this, PresentationMode.ModalNotAnimated); On().SetModalPresentationStyle(UIModalPresentationStyle.OverFullScreen); + NavigationPage.SetHasNavigationBar(this, false); } public event EventHandler? PopupClosed; @@ -85,7 +86,8 @@ public async Task CloseAsync(PopupResult result, CancellationToken token = defau if (popupPageToClose is null) { - throw new PopupNotFoundException(); + await FindPopupPage(); + return; } if (Navigation.ModalStack[^1] is Microsoft.Maui.Controls.Page currentVisibleModalPage @@ -213,6 +215,32 @@ void HandleTapGestureRecognizerTapped(object? sender, TappedEventArgs e) } } + Task FindPopupPage() + { + var stack = Navigation.ModalStack; + + if (stack.Count is 0) + { + throw new PopupNotFoundException(); + } + + var page = stack[^1]; + + switch (page) + { + case IPageContainer container: + if (container.CurrentPage is not PopupPage) + { + throw new PopupNotFoundException(); + } + break; + case not PopupPage: + throw new PopupNotFoundException(); + } + + return Navigation.PopModalAsync(false); + } + internal sealed partial class PopupPageLayout : Grid { public PopupPageLayout(in Popup popupContent, in IPopupOptions options)