diff options
author | E.Z. Hart <hartez@users.noreply.github.com> | 2016-12-07 16:11:14 -0700 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-12-07 23:11:14 +0000 |
commit | 8ac7667b9cd0d81a49463a7763aba5d57425af3f (patch) | |
tree | 3fa5e6b16bab3f7cb8049b9c8527ea0486e782de | |
parent | 3199eba80c1e25c18a89c7de457f5c5c06ac7de3 (diff) | |
download | xamarin-forms-8ac7667b9cd0d81a49463a7763aba5d57425af3f.tar.gz xamarin-forms-8ac7667b9cd0d81a49463a7763aba5d57425af3f.tar.bz2 xamarin-forms-8ac7667b9cd0d81a49463a7763aba5d57425af3f.zip |
Fix for 45743 which works with iOS 8 (#616)
* Explicitly set window bounds when presenting alert
* Remove unused methods
-rw-r--r-- | Xamarin.Forms.Platform.iOS/Platform.cs | 74 |
1 files changed, 8 insertions, 66 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Platform.cs b/Xamarin.Forms.Platform.iOS/Platform.cs index 603fe9cb..c9c31887 100644 --- a/Xamarin.Forms.Platform.iOS/Platform.cs +++ b/Xamarin.Forms.Platform.iOS/Platform.cs @@ -46,14 +46,10 @@ namespace Xamarin.Forms.Platform.iOS if (!PageIsChildOfPlatform(sender)) return; - if (Forms.IsiOS9OrNewer) + if (Forms.IsiOS8OrNewer) { PresentAlert(arguments); } - else if (Forms.IsiOS8OrNewer) - { - Present8Alert(arguments); - } else { PresentPre8Alert(arguments); @@ -70,14 +66,10 @@ namespace Xamarin.Forms.Platform.iOS pageRoot = (Page)pageRoot.RealParent; var pageRenderer = GetRenderer(pageRoot); - if (Forms.IsiOS9OrNewer) + if (Forms.IsiOS8OrNewer) { PresentActionSheet(arguments); } - else if (Forms.IsiOS8OrNewer) - { - Present8ActionSheet(arguments, pageRenderer); - } else { PresentPre8ActionSheet(arguments, pageRenderer); @@ -460,6 +452,12 @@ namespace Xamarin.Forms.Platform.iOS alert.PopoverPresentationController.PermittedArrowDirections = 0; // No arrow } + if(!Forms.IsiOS9OrNewer) + { + // For iOS 8, we need to explicitly set the size of the window + window.Frame = new RectangleF(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height); + } + window.RootViewController.PresentViewController(alert, true, null); } @@ -522,62 +520,6 @@ namespace Xamarin.Forms.Platform.iOS }; } - void Present8Alert(AlertArguments arguments) - { - var alert = UIAlertController.Create(arguments.Title, arguments.Message, UIAlertControllerStyle.Alert); - var oldFrame = alert.View.Frame; - alert.View.Frame = new RectangleF(oldFrame.X, oldFrame.Y, oldFrame.Width, oldFrame.Height - _alertPadding * 2); - 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); - } - - void Present8ActionSheet(ActionSheetArguments arguments, IVisualElementRenderer pageRenderer) - { - var alert = UIAlertController.Create(arguments.Title, null, UIAlertControllerStyle.ActionSheet); - - if (arguments.Cancel != null) - { - alert.AddAction(UIAlertAction.Create(arguments.Cancel, UIAlertActionStyle.Cancel, a => arguments.SetResult(arguments.Cancel))); - } - - if (arguments.Destruction != null) - { - alert.AddAction(UIAlertAction.Create(arguments.Destruction, UIAlertActionStyle.Destructive, a => arguments.SetResult(arguments.Destruction))); - } - - foreach (var label in arguments.Buttons) - { - if (label == null) - continue; - - var blabel = label; - alert.AddAction(UIAlertAction.Create(blabel, UIAlertActionStyle.Default, a => arguments.SetResult(blabel))); - } - - if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) - { - UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications(); - var observer = NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, - n => { alert.PopoverPresentationController.SourceRect = pageRenderer.ViewController.View.Bounds; }); - - arguments.Result.Task.ContinueWith(t => - { - NSNotificationCenter.DefaultCenter.RemoveObserver(observer); - UIDevice.CurrentDevice.EndGeneratingDeviceOrientationNotifications(); - }, TaskScheduler.FromCurrentSynchronizationContext()); - - alert.PopoverPresentationController.SourceView = pageRenderer.ViewController.View; - alert.PopoverPresentationController.SourceRect = pageRenderer.ViewController.View.Bounds; - alert.PopoverPresentationController.PermittedArrowDirections = 0; // No arrow - } - - pageRenderer.ViewController.PresentViewController(alert, true, null); - } - internal class DefaultRenderer : VisualElementRenderer<VisualElement> { } |