From 0d96f165f4ea499536a7e9b4027aa9612fcb9aa5 Mon Sep 17 00:00:00 2001 From: Vitaly Knyazev Date: Fri, 20 Dec 2024 20:02:34 +0000 Subject: [PATCH] Fixed issue 26769 - crash when iOS app is running on MacOS and "More" item is clicked in ListView context menu. Checking PopoverPresentationController for null, it seems to be null checked already in all other places. --- .../Core/src/iOS/ContextActionCell.cs | 9 ++++++--- src/Compatibility/Core/src/iOS/Platform.cs | 15 +++++++++++---- .../Handlers/ListView/iOS/ContextActionCell.cs | 9 ++++++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/Compatibility/Core/src/iOS/ContextActionCell.cs b/src/Compatibility/Core/src/iOS/ContextActionCell.cs index e91587cd126b..784d79427244 100644 --- a/src/Compatibility/Core/src/iOS/ContextActionCell.cs +++ b/src/Compatibility/Core/src/iOS/ContextActionCell.cs @@ -345,15 +345,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); diff --git a/src/Compatibility/Core/src/iOS/Platform.cs b/src/Compatibility/Core/src/iOS/Platform.cs index 37ccdfe94be4..d1503c2929c2 100644 --- a/src/Compatibility/Core/src/iOS/Platform.cs +++ b/src/Compatibility/Core/src/iOS/Platform.cs @@ -518,7 +518,11 @@ 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 => { @@ -526,9 +530,12 @@ static void PresentPopUp(UIWindow window, UIAlertController alert, ActionSheetAr 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 + } } window.RootViewController.PresentViewController(alert, true, null); diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ContextActionCell.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ContextActionCell.cs index 47c16b8d96b4..589788cd4bfb 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ContextActionCell.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ContextActionCell.cs @@ -340,15 +340,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);