Skip to content
Merged
Changes from 2 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
34 changes: 31 additions & 3 deletions src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -66,6 +66,7 @@ public PopupPage(Popup popup, IPopupOptions? popupOptions)

Shell.SetPresentationMode(this, PresentationMode.ModalNotAnimated);
On<iOS>().SetModalPresentationStyle(UIModalPresentationStyle.OverFullScreen);
NavigationPage.SetHasNavigationBar(this, false);
}

public event EventHandler<IPopupResult>? PopupClosed;
Expand All @@ -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
Expand Down Expand Up @@ -213,6 +215,32 @@ void HandleTapGestureRecognizerTapped(object? sender, TappedEventArgs e)
}
}

Task<Page> FindPopupPage()
{
var stack = Navigation.ModalStack;

if (stack.Count is 0)
{
throw new PopupNotFoundException();
}

var page = stack[^1];

switch (page)
{
case IPageContainer<Page> 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)
Expand Down
Loading