diff --git a/src/Acr.UserDialogs.iOS/AIDatePickerController.cs b/src/Acr.UserDialogs.iOS/AIDatePickerController.cs index 044972c6..1fc00ab3 100644 --- a/src/Acr.UserDialogs.iOS/AIDatePickerController.cs +++ b/src/Acr.UserDialogs.iOS/AIDatePickerController.cs @@ -8,6 +8,8 @@ namespace AI [Register ("AIDatePickerController")] public class AIDatePickerController : UIViewController, IUIViewControllerAnimatedTransitioning, IUIViewControllerTransitioningDelegate { + private UIEdgeInsets safeAreaInsets; + public double AnimatedTransitionDuration { get; set; } = 0.4; public UIDatePickerMode Mode { get; set; } = UIDatePickerMode.Date; public UIColor BackgroundColor { get; set; } = UIColor.White; @@ -31,7 +33,9 @@ public AIDatePickerController() { //this.ModalPresentationStyle = UIModalPresentationStyle.Custom; this.ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext; - this.TransitioningDelegate = this; + this.TransitioningDelegate = this; + + SetupSafeAreaInsets(); } @@ -165,9 +169,21 @@ public override void ViewDidLoad() this.View.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-5-[DatePickerContainerView]-5-|", 0, null, views)); this.View.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-5-[ButtonContainerView]-5-|", 0, null, views)); - this.View.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|[DismissButton][DatePickerContainerView]-10-[ButtonContainerView(40)]-5-|", 0, null, views)); + this.View.AddConstraints(NSLayoutConstraint.FromVisualFormat($"V:|[DismissButton][DatePickerContainerView]-10-[ButtonContainerView(40)]-{5 + safeAreaInsets.Bottom}-|", 0, null, views)); } + private void SetupSafeAreaInsets() + { + if(UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) + { + safeAreaInsets = UIApplication.SharedApplication.KeyWindow.SafeAreaInsets; + } + else + { + safeAreaInsets = new UIEdgeInsets(); + } + } + public double TransitionDuration(IUIViewControllerContextTransitioning transitionContext) { return AnimatedTransitionDuration; diff --git a/src/Acr.UserDialogs.iOS/TTGSnackbar.cs b/src/Acr.UserDialogs.iOS/TTGSnackbar.cs index b41d8e94..b0f03f5c 100644 --- a/src/Acr.UserDialogs.iOS/TTGSnackbar.cs +++ b/src/Acr.UserDialogs.iOS/TTGSnackbar.cs @@ -28,11 +28,11 @@ public class TTGSnackbar : UIView // Snackbar icon imageView default width private const float snackbarIconImageViewWidth = 32; + private UIEdgeInsets safeAreaInsets; + public Action ActionBlock { get; set; } public Action SecondActionBlock { get; set; } - - public nfloat TopMargin { get; set; } = 8; /// /// Snackbar display duration. Default is 3 seconds. /// @@ -61,12 +61,55 @@ public nfloat CornerRadius } } - public nfloat LeftMargin { get; set; } = 4; - public nfloat RightMargin { get; set; } = 4; + nfloat topMargin = 8; + public nfloat TopMargin + { + get + { + return topMargin + safeAreaInsets.Top; + } + set + { + topMargin = value; + } + } + nfloat leftMargin = 4; + public nfloat LeftMargin + { + get + { + return leftMargin + safeAreaInsets.Left; + } + set + { + leftMargin = value; + } + } + + nfloat rightMargin = 4; + public nfloat RightMargin + { + get + { + return rightMargin + safeAreaInsets.Right; + } + set + { + rightMargin = value; + } + } /// Bottom margin. Default is 4 - public nfloat BottomMargin { get; set; } = 4; + nfloat bottomMargin = 4; + public nfloat BottomMargin { + get { + return bottomMargin + safeAreaInsets.Bottom; + } + set { + bottomMargin = value; + } + } public nfloat Height { get; set; } = 44; @@ -152,6 +195,8 @@ public TTGSnackbar() : base(CoreGraphics.CGRect.FromLTRB(0, 0, 320, 44)) this.Layer.CornerRadius = 4; this.Layer.MasksToBounds = true; + SetupSafeAreaInsets(); + this.MessageLabel = new UILabel { TranslatesAutoresizingMaskIntoConstraints = false, @@ -294,6 +339,18 @@ public TTGSnackbar() : base(CoreGraphics.CGRect.FromLTRB(0, 0, 320, 44)) //this.AddConstraints(hConstraintsForActivityIndicatorView); } + private void SetupSafeAreaInsets() + { + if(UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) + { + safeAreaInsets = UIApplication.SharedApplication.KeyWindow.SafeAreaInsets; + } + else + { + safeAreaInsets = new UIEdgeInsets(); + } + } + /// /// Show the snackbar /// @@ -364,7 +421,7 @@ public void Show() localSuperView, NSLayoutAttribute.Bottom, 1, - -BottomMargin); + -BottomMargin ); // Avoid the "UIView-Encapsulated-Layout-Height" constraint conflicts // http://stackoverflow.com/questions/25059443/what-is-nslayoutconstraint-uiview-encapsulated-layout-height-and-how-should-i