Skip to content

Commit

Permalink
macOS does not use PopoverPresentationController
Browse files Browse the repository at this point in the history
Fixes #18156
  • Loading branch information
mattleibow committed Feb 18, 2024
1 parent 7773f90 commit 68c930f
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,14 @@ void PresentActionSheet(Page sender, ActionSheetArguments arguments)

static void PresentPopUp(Page sender, Window virtualView, UIWindow platformView, UIAlertController alert, ActionSheetArguments arguments = null)
{
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && arguments != null)
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad &&
arguments is not null &&
alert.PopoverPresentationController is not null &&
platformView.RootViewController?.View is not null)
{
UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications();
var observer = NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification,
n => { alert.PopoverPresentationController.SourceRect = platformView.RootViewController.View.Bounds; });
n => alert.PopoverPresentationController.SourceRect = platformView.RootViewController.View.Bounds);

arguments.Result.Task.ContinueWith(t =>
{
Expand Down Expand Up @@ -214,7 +217,7 @@ static void PresentPopUp(Page sender, Window virtualView, UIWindow platformView,
static UIViewController GetTopUIViewController(UIWindow platformWindow)
{
var topUIViewController = platformWindow.RootViewController;
while (topUIViewController.PresentedViewController is not null)
while (topUIViewController?.PresentedViewController is not null)
{
topUIViewController = topUIViewController.PresentedViewController;
}
Expand Down

0 comments on commit 68c930f

Please sign in to comment.