Skip to content

Commit

Permalink
Open popups on the main application window
Browse files Browse the repository at this point in the history
  • Loading branch information
Tor Øyvind Fluør committed Jun 21, 2024
1 parent 44b6af7 commit e96ea59
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 11 additions & 2 deletions Mopups/Mopups.Maui/Platforms/MacCatalyst/MacOSMopups.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CoreGraphics;

using Microsoft.Maui.Controls.Compatibility.Platform.iOS;

using Microsoft.Maui.Platform;
using Mopups.Interfaces;
using Mopups.Pages;
using Mopups.Platforms.MacCatalyst;
Expand Down Expand Up @@ -36,7 +36,16 @@ public Task AddAsync(PopupPage page)

if (IsiOS13OrNewer)
{
var connectedScene = UIApplication.SharedApplication.ConnectedScenes.ToArray().FirstOrDefault(x => x.ActivationState == UISceneActivationState.ForegroundActive);
UIScene connectedScene = null;

if(page.Parent != null && page.Parent.Handler != null && page.Parent.Handler.MauiContext != null) {
var nativeMainPage = page.Parent.ToPlatform(page.Parent.Handler.MauiContext);
connectedScene = nativeMainPage.Window.WindowScene;
}

if(connectedScene == null)
connectedScene = UIApplication.SharedApplication.ConnectedScenes.ToArray().FirstOrDefault(x => x.ActivationState == UISceneActivationState.ForegroundActive);

if (connectedScene != null && connectedScene is UIWindowScene windowScene)
window = new PopupWindow(windowScene);
else
Expand Down
6 changes: 5 additions & 1 deletion Mopups/Mopups.Maui/Platforms/iOS/iOSMopups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public Task AddAsync(PopupPage page)

if (IsiOS13OrNewer)
{
var connectedScene = UIApplication.SharedApplication.ConnectedScenes.ToArray().FirstOrDefault(x => x.ActivationState == UISceneActivationState.ForegroundActive);
var connectedScene = UIApplication.SharedApplication.ConnectedScenes.ToArray()
.Where(scene => scene.Session.Role == UIWindowSceneSessionRole.Application)
.FirstOrDefault(x => x.ActivationState == UISceneActivationState.ForegroundActive);

if (connectedScene != null && connectedScene is UIWindowScene windowScene)
window = new PopupWindow(windowScene);
else
Expand Down Expand Up @@ -65,6 +68,7 @@ UIWindow GetKeyWindow(UIApplication application)
.ConnectedScenes
.ToArray()
.OfType<UIWindowScene>()
.Where(scene => scene.Session.Role == UIWindowSceneSessionRole.Application)
.SelectMany(scene => scene.Windows)
.FirstOrDefault(window => window.IsKeyWindow);

Expand Down

0 comments on commit e96ea59

Please sign in to comment.