summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2016-11-18 12:47:52 -0700
committerSamantha Houts <samantha@teamredwall.com>2016-11-18 11:47:52 -0800
commit54e1e4a56c1e77b395f9f3830ccb2b81b581cdc0 (patch)
tree7fb1d50a65e3bfd76a835ef6d668cc73692fcdc8 /Xamarin.Forms.Platform.iOS
parent4cb6e6de2bf7474ac23c7efe151511cae90b60c3 (diff)
downloadxamarin-forms-54e1e4a56c1e77b395f9f3830ccb2b81b581cdc0.tar.gz
xamarin-forms-54e1e4a56c1e77b395f9f3830ccb2b81b581cdc0.tar.bz2
xamarin-forms-54e1e4a56c1e77b395f9f3830ccb2b81b581cdc0.zip
Have PresentAlert hide new window when alert is dismissed (#543)
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r--Xamarin.Forms.Platform.iOS/Platform.cs130
1 files changed, 82 insertions, 48 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Platform.cs b/Xamarin.Forms.Platform.iOS/Platform.cs
index 762ccf00..f39856b8 100644
--- a/Xamarin.Forms.Platform.iOS/Platform.cs
+++ b/Xamarin.Forms.Platform.iOS/Platform.cs
@@ -48,14 +48,7 @@ namespace Xamarin.Forms.Platform.iOS
if (Forms.IsiOS8OrNewer)
{
- 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)));
-
- PresentAlert(alert);
+ PresentAlert(arguments);
}
else
{
@@ -82,45 +75,7 @@ namespace Xamarin.Forms.Platform.iOS
if (Forms.IsiOS8OrNewer)
{
- 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
- }
-
- PresentAlert(alert);
+ PresentAlert(arguments, pageRenderer);
}
else
{
@@ -430,11 +385,90 @@ namespace Xamarin.Forms.Platform.iOS
return Page == page || _modals.Contains(page);
}
- void PresentAlert(UIAlertController alert)
+ // Creates a UIAlertAction which includes a call to hide the presenting UIWindow at the end
+ UIAlertAction CreateActionWithWindowHide(string text, UIAlertActionStyle style, Action setResult, UIWindow window)
+ {
+ return UIAlertAction.Create(text, style,
+ a =>
+ {
+ setResult();
+ window.Hidden = true;
+ });
+ }
+
+ void PresentAlert(AlertArguments arguments)
+ {
+ var window = new UIWindow { BackgroundColor = Color.Transparent.ToUIColor() };
+
+ 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);
+
+ if (arguments.Cancel != null)
+ {
+ alert.AddAction(CreateActionWithWindowHide(arguments.Cancel, UIAlertActionStyle.Cancel,
+ () => arguments.SetResult(false), window));
+ }
+
+ if (arguments.Accept != null)
+ {
+ alert.AddAction(CreateActionWithWindowHide(arguments.Accept, UIAlertActionStyle.Default,
+ () => arguments.SetResult(true), window));
+ }
+
+ PresentAlert(window, alert);
+ }
+
+ void PresentAlert(ActionSheetArguments arguments, IVisualElementRenderer pageRenderer)
{
+ var alert = UIAlertController.Create(arguments.Title, null, UIAlertControllerStyle.ActionSheet);
var window = new UIWindow { BackgroundColor = Color.Transparent.ToUIColor() };
+
+ if (arguments.Cancel != null)
+ {
+ alert.AddAction(CreateActionWithWindowHide(arguments.Cancel, UIAlertActionStyle.Cancel, () => arguments.SetResult(arguments.Cancel), window));
+ }
+
+ if (arguments.Destruction != null)
+ {
+ alert.AddAction(CreateActionWithWindowHide(arguments.Destruction, UIAlertActionStyle.Destructive, () => arguments.SetResult(arguments.Destruction), window));
+ }
+
+ foreach (var label in arguments.Buttons)
+ {
+ if (label == null)
+ continue;
+
+ var blabel = label;
+
+ alert.AddAction(CreateActionWithWindowHide(blabel, UIAlertActionStyle.Default, () => arguments.SetResult(blabel), window));
+ }
+
+ 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
+ }
+
+ 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);
}