Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Fixed issue #15874 - NRE when iOS app is running on MacOS and "More" item is clicked in ListView context menu #15875

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 6 additions & 3 deletions Xamarin.Forms.Platform.iOS/ContextActionCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,18 @@ void ActivateMore()
if (controller == null)
throw new InvalidOperationException("No UIViewController found to present.");

if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone || (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && actionSheet.PopoverPresentationController == null))
{
var cancel = UIAlertAction.Create(StringResources.Cancel, UIAlertActionStyle.Cancel, null);
actionSheet.AddAction(cancel);
}
else
{
actionSheet.PopoverPresentationController.SourceView = _tableView;
actionSheet.PopoverPresentationController.SourceRect = sourceRect;
if (actionSheet.PopoverPresentationController != null)
{
actionSheet.PopoverPresentationController.SourceView = _tableView;
actionSheet.PopoverPresentationController.SourceRect = sourceRect;
}
}

controller.PresentViewController(actionSheet, true, null);
Expand Down
15 changes: 11 additions & 4 deletions Xamarin.Forms.Platform.iOS/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,17 +472,24 @@ static void PresentPopUp(UIWindow window, UIAlertController alert, ActionSheetAr
{
UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications();
var observer = NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification,
n => { alert.PopoverPresentationController.SourceRect = window.RootViewController.View.Bounds; });
n =>
{
if (alert.PopoverPresentationController != null)
alert.PopoverPresentationController.SourceRect = window.RootViewController.View.Bounds;
});

arguments.Result.Task.ContinueWith(t =>
{
NSNotificationCenter.DefaultCenter.RemoveObserver(observer);
UIDevice.CurrentDevice.EndGeneratingDeviceOrientationNotifications();
}, TaskScheduler.FromCurrentSynchronizationContext());

alert.PopoverPresentationController.SourceView = window.RootViewController.View;
alert.PopoverPresentationController.SourceRect = window.RootViewController.View.Bounds;
alert.PopoverPresentationController.PermittedArrowDirections = 0; // No arrow
if (alert.PopoverPresentationController != null)
{
alert.PopoverPresentationController.SourceView = window.RootViewController.View;
alert.PopoverPresentationController.SourceRect = window.RootViewController.View.Bounds;
alert.PopoverPresentationController.PermittedArrowDirections = 0; // No arrow
}
}

if(!Forms.IsiOS9OrNewer)
Expand Down