From 7f9f2530ca1912421e0d88cd47f185dc733cd310 Mon Sep 17 00:00:00 2001 From: Paul DiPietro Date: Tue, 15 Nov 2016 13:36:49 -0600 Subject: [iOS] Use separate UIWindow for UIAlertController (#481) * [iOS] Use separate UIWindow for UIAlertController * Add similar behavior for DisplayActionSheet; consolidate behavior into PresentAlert method --- Xamarin.Forms.Platform.iOS/Platform.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'Xamarin.Forms.Platform.iOS') diff --git a/Xamarin.Forms.Platform.iOS/Platform.cs b/Xamarin.Forms.Platform.iOS/Platform.cs index 04874db8..8db28f6f 100644 --- a/Xamarin.Forms.Platform.iOS/Platform.cs +++ b/Xamarin.Forms.Platform.iOS/Platform.cs @@ -54,9 +54,8 @@ namespace Xamarin.Forms.Platform.iOS alert.AddAction(UIAlertAction.Create(arguments.Cancel, UIAlertActionStyle.Cancel, a => arguments.SetResult(false))); if (arguments.Accept != null) alert.AddAction(UIAlertAction.Create(arguments.Accept, UIAlertActionStyle.Default, a => arguments.SetResult(true))); - var page = _modals.Any() ? _modals.Last() : Page; - var vc = GetRenderer(page).ViewController; - vc.PresentViewController(alert, true, null); + + PresentAlert(alert); } else { @@ -121,7 +120,7 @@ namespace Xamarin.Forms.Platform.iOS alert.PopoverPresentationController.PermittedArrowDirections = 0; // No arrow } - pageRenderer.ViewController.PresentViewController(alert, true, null); + PresentAlert(alert); } else { @@ -431,6 +430,15 @@ namespace Xamarin.Forms.Platform.iOS return Page == page || _modals.Contains(page); } + void PresentAlert(UIAlertController alert) + { + var window = new UIWindow { BackgroundColor = Color.Transparent.ToUIColor() }; + window.RootViewController = new UIViewController(); + window.RootViewController.View.BackgroundColor = Color.Transparent.ToUIColor(); + window.MakeKeyAndVisible(); + window.RootViewController.PresentViewController(alert, true, null); + } + async Task PresentModal(Page modal, bool animated) { var modalRenderer = GetRenderer(modal); -- cgit v1.2.3