Fix broken alerts for iPad (#549) beta-2.3.4-pre1
authorE.Z. Hart <hartez@users.noreply.github.com>
Tue, 22 Nov 2016 17:01:20 +0000 (10:01 -0700)
committerRui Marinho <me@ruimarinho.net>
Tue, 22 Nov 2016 17:01:20 +0000 (17:01 +0000)
* Fix broken alerts for iPad

* Remove unnecessary parameter and add null check

* Dropping test limit to 10 so we can get iOS passing

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/TestPages.cs
Xamarin.Forms.Core.iOS.UITests/BaseTestFixture.cs
Xamarin.Forms.Platform.iOS/Platform.cs

index d5b5afd..6400a2a 100644 (file)
@@ -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
index db28993..e6a38e4 100644 (file)
@@ -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 
index f39856b..189faa7 100644 (file)
@@ -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);
                }