-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathToastMessageService.iOS.cs
63 lines (52 loc) · 1.81 KB
/
ToastMessageService.iOS.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#if IOS || MACCATALYST
using CoreGraphics;
using Foundation;
using UIKit;
namespace QSF.Services;
partial class ToastMessageService
{
private NSTimer alertDelay;
private UIAlertController alert;
public void ShortAlert(string message)
{
this.ShowAlert(message, 3.5);
}
private void ShowAlert(string message, double seconds)
{
this.alertDelay = NSTimer.CreateScheduledTimer(seconds, (obj) =>
{
this.DismissMessage();
});
this.alert = UIAlertController.Create(null, message, UIAlertControllerStyle.ActionSheet);
var rootViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
var popoverPresentationController = this.alert.PopoverPresentationController;
if (popoverPresentationController != null)
{
var rootView = rootViewController.View;
var rootRect = rootViewController.View.Bounds;
#if MACCATALYST
var sourceRect = new CGRect(0, rootRect.Height - 10, rootRect.Width, 10);
var arrowDirection = UIPopoverArrowDirection.Down;
#else
var sourceRect = new CGRect(0, rootRect.Height, rootRect.Width, 0);
var arrowDirection = default(UIPopoverArrowDirection);
#endif
popoverPresentationController.SourceView = rootView;
popoverPresentationController.SourceRect = sourceRect;
popoverPresentationController.PermittedArrowDirections = arrowDirection;
}
rootViewController.PresentViewController(this.alert, true, null);
}
private void DismissMessage()
{
if (this.alert != null)
{
this.alert.DismissViewController(true, null);
}
if (this.alertDelay != null)
{
this.alertDelay.Dispose();
}
}
}
#endif