@@ -28,11 +28,11 @@ public class TTGSnackbar : UIView
2828 // Snackbar icon imageView default width
2929 private const float snackbarIconImageViewWidth = 32 ;
3030
31+ private UIEdgeInsets safeAreaInsets ;
32+
3133 public Action < TTGSnackbar > ActionBlock { get ; set ; }
3234 public Action < TTGSnackbar > SecondActionBlock { get ; set ; }
3335
34-
35- public nfloat TopMargin { get ; set ; } = 8 ;
3636 /// <summary>
3737 /// Snackbar display duration. Default is 3 seconds.
3838 /// </summary>
@@ -61,12 +61,55 @@ public nfloat CornerRadius
6161 }
6262 }
6363
64- public nfloat LeftMargin { get ; set ; } = 4 ;
65- public nfloat RightMargin { get ; set ; } = 4 ;
64+ nfloat topMargin = 8 ;
65+ public nfloat TopMargin
66+ {
67+ get
68+ {
69+ return topMargin + safeAreaInsets . Top ;
70+ }
71+ set
72+ {
73+ topMargin = value ;
74+ }
75+ }
6676
77+ nfloat leftMargin = 4 ;
78+ public nfloat LeftMargin
79+ {
80+ get
81+ {
82+ return leftMargin + safeAreaInsets . Left ;
83+ }
84+ set
85+ {
86+ leftMargin = value ;
87+ }
88+ }
89+
90+ nfloat rightMargin = 4 ;
91+ public nfloat RightMargin
92+ {
93+ get
94+ {
95+ return rightMargin + safeAreaInsets . Right ;
96+ }
97+ set
98+ {
99+ rightMargin = value ;
100+ }
101+ }
67102
68103 /// Bottom margin. Default is 4
69- public nfloat BottomMargin { get ; set ; } = 4 ;
104+ nfloat bottomMargin = 4 ;
105+ public nfloat BottomMargin {
106+ get {
107+ return bottomMargin + safeAreaInsets . Bottom ;
108+ }
109+ set {
110+ bottomMargin = value ;
111+ }
112+ }
70113 public nfloat Height { get ; set ; } = 44 ;
71114
72115
@@ -152,6 +195,8 @@ public TTGSnackbar() : base(CoreGraphics.CGRect.FromLTRB(0, 0, 320, 44))
152195 this . Layer . CornerRadius = 4 ;
153196 this . Layer . MasksToBounds = true ;
154197
198+ SetupSafeAreaInsets ( ) ;
199+
155200 this . MessageLabel = new UILabel
156201 {
157202 TranslatesAutoresizingMaskIntoConstraints = false ,
@@ -294,6 +339,18 @@ public TTGSnackbar() : base(CoreGraphics.CGRect.FromLTRB(0, 0, 320, 44))
294339 //this.AddConstraints(hConstraintsForActivityIndicatorView);
295340 }
296341
342+ private void SetupSafeAreaInsets ( )
343+ {
344+ if ( UIDevice . CurrentDevice . CheckSystemVersion ( 11 , 0 ) )
345+ {
346+ safeAreaInsets = UIApplication . SharedApplication . KeyWindow . SafeAreaInsets ;
347+ }
348+ else
349+ {
350+ safeAreaInsets = new UIEdgeInsets ( ) ;
351+ }
352+ }
353+
297354 /// <summary>
298355 /// Show the snackbar
299356 /// </summary>
@@ -364,7 +421,7 @@ public void Show()
364421 localSuperView ,
365422 NSLayoutAttribute . Bottom ,
366423 1 ,
367- - BottomMargin ) ;
424+ - BottomMargin ) ;
368425
369426 // Avoid the "UIView-Encapsulated-Layout-Height" constraint conflicts
370427 // http://stackoverflow.com/questions/25059443/what-is-nslayoutconstraint-uiview-encapsulated-layout-height-and-how-should-i
0 commit comments