Skip to content

Commit 07acd63

Browse files
committed
AIDatePicker add safeAreaInsets
1 parent 83134b5 commit 07acd63

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Acr.UserDialogs.iOS/AIDatePickerController.cs

+18-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace AI
88
[Register ("AIDatePickerController")]
99
public class AIDatePickerController : UIViewController, IUIViewControllerAnimatedTransitioning, IUIViewControllerTransitioningDelegate
1010
{
11+
private UIEdgeInsets safeAreaInsets;
12+
1113
public double AnimatedTransitionDuration { get; set; } = 0.4;
1214
public UIDatePickerMode Mode { get; set; } = UIDatePickerMode.Date;
1315
public UIColor BackgroundColor { get; set; } = UIColor.White;
@@ -31,7 +33,9 @@ public AIDatePickerController()
3133
{
3234
//this.ModalPresentationStyle = UIModalPresentationStyle.Custom;
3335
this.ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext;
34-
this.TransitioningDelegate = this;
36+
this.TransitioningDelegate = this;
37+
38+
SetupSafeAreaInsets();
3539
}
3640

3741

@@ -165,9 +169,21 @@ public override void ViewDidLoad()
165169
this.View.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-5-[DatePickerContainerView]-5-|", 0, null, views));
166170
this.View.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-5-[ButtonContainerView]-5-|", 0, null, views));
167171

168-
this.View.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|[DismissButton][DatePickerContainerView]-10-[ButtonContainerView(40)]-5-|", 0, null, views));
172+
this.View.AddConstraints(NSLayoutConstraint.FromVisualFormat($"V:|[DismissButton][DatePickerContainerView]-10-[ButtonContainerView(40)]-{5 + safeAreaInsets.Bottom}-|", 0, null, views));
169173
}
170174

175+
private void SetupSafeAreaInsets()
176+
{
177+
if(UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
178+
{
179+
safeAreaInsets = UIApplication.SharedApplication.KeyWindow.SafeAreaInsets;
180+
}
181+
else
182+
{
183+
safeAreaInsets = new UIEdgeInsets();
184+
}
185+
}
186+
171187
public double TransitionDuration(IUIViewControllerContextTransitioning transitionContext)
172188
{
173189
return AnimatedTransitionDuration;

0 commit comments

Comments
 (0)