From: E.Z. Hart Date: Tue, 22 Nov 2016 17:01:20 +0000 (-0700) Subject: Fix broken alerts for iPad (#549) X-Git-Tag: beta-2.3.4-pre1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Ftags%2Fbeta-2.3.4-pre1;p=platform%2Fupstream%2Fxamarin-forms.git Fix broken alerts for iPad (#549) * Fix broken alerts for iPad * Remove unnecessary parameter and add null check * Dropping test limit to 10 so we can get iOS passing --- diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/TestPages.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/TestPages.cs index d5b5afd..6400a2a 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/TestPages.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/TestPages.cs @@ -186,7 +186,7 @@ namespace Xamarin.Forms.Controls } static int s_testsrun; - const int ConsecutiveTestLimit = 30; + const int ConsecutiveTestLimit = 10; // Until we get more of our memory leak issues worked out, restart the app // after a specified number of tests so we don't get bogged down in GC diff --git a/Xamarin.Forms.Core.iOS.UITests/BaseTestFixture.cs b/Xamarin.Forms.Core.iOS.UITests/BaseTestFixture.cs index db28993..e6a38e4 100644 --- a/Xamarin.Forms.Core.iOS.UITests/BaseTestFixture.cs +++ b/Xamarin.Forms.Core.iOS.UITests/BaseTestFixture.cs @@ -26,7 +26,7 @@ namespace Xamarin.Forms.Core.UITests } static int s_testsrun; - const int ConsecutiveTestLimit = 30; + const int ConsecutiveTestLimit = 10; // Until we get more of our memory leak issues worked out, restart the app // after a specified number of tests so we don't get bogged down in GC diff --git a/Xamarin.Forms.Platform.iOS/Platform.cs b/Xamarin.Forms.Platform.iOS/Platform.cs index f39856b..189faa7 100644 --- a/Xamarin.Forms.Platform.iOS/Platform.cs +++ b/Xamarin.Forms.Platform.iOS/Platform.cs @@ -75,7 +75,7 @@ namespace Xamarin.Forms.Platform.iOS if (Forms.IsiOS8OrNewer) { - PresentAlert(arguments, pageRenderer); + PresentAlert(arguments); } else { @@ -419,7 +419,7 @@ namespace Xamarin.Forms.Platform.iOS PresentAlert(window, alert); } - void PresentAlert(ActionSheetArguments arguments, IVisualElementRenderer pageRenderer) + void PresentAlert(ActionSheetArguments arguments) { var alert = UIAlertController.Create(arguments.Title, null, UIAlertControllerStyle.ActionSheet); var window = new UIWindow { BackgroundColor = Color.Transparent.ToUIColor() }; @@ -444,11 +444,21 @@ namespace Xamarin.Forms.Platform.iOS alert.AddAction(CreateActionWithWindowHide(blabel, UIAlertActionStyle.Default, () => arguments.SetResult(blabel), window)); } - if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) + PresentAlert(window, alert, arguments); + } + + static void PresentAlert(UIWindow window, UIAlertController alert, ActionSheetArguments arguments = null) + { + window.RootViewController = new UIViewController(); + window.RootViewController.View.BackgroundColor = Color.Transparent.ToUIColor(); + window.WindowLevel = UIWindowLevel.Alert + 1; + window.MakeKeyAndVisible(); + + if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && arguments != null) { UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications(); var observer = NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, - n => { alert.PopoverPresentationController.SourceRect = pageRenderer.ViewController.View.Bounds; }); + n => { alert.PopoverPresentationController.SourceRect = window.RootViewController.View.Bounds; }); arguments.Result.Task.ContinueWith(t => { @@ -456,20 +466,11 @@ namespace Xamarin.Forms.Platform.iOS UIDevice.CurrentDevice.EndGeneratingDeviceOrientationNotifications(); }, TaskScheduler.FromCurrentSynchronizationContext()); - alert.PopoverPresentationController.SourceView = pageRenderer.ViewController.View; - alert.PopoverPresentationController.SourceRect = pageRenderer.ViewController.View.Bounds; + alert.PopoverPresentationController.SourceView = window.RootViewController.View; + alert.PopoverPresentationController.SourceRect = window.RootViewController.View.Bounds; alert.PopoverPresentationController.PermittedArrowDirections = 0; // No arrow } - PresentAlert(window, alert); - } - - static void PresentAlert(UIWindow window, UIAlertController alert) - { - window.RootViewController = new UIViewController(); - window.RootViewController.View.BackgroundColor = Color.Transparent.ToUIColor(); - window.WindowLevel = UIWindowLevel.Alert + 1; - window.MakeKeyAndVisible(); window.RootViewController.PresentViewController(alert, true, null); }