@@ -28,11 +28,11 @@ public class TTGSnackbar : UIView
28
28
// Snackbar icon imageView default width
29
29
private const float snackbarIconImageViewWidth = 32 ;
30
30
31
+ private UIEdgeInsets safeAreaInsets ;
32
+
31
33
public Action < TTGSnackbar > ActionBlock { get ; set ; }
32
34
public Action < TTGSnackbar > SecondActionBlock { get ; set ; }
33
35
34
-
35
- public nfloat TopMargin { get ; set ; } = 8 ;
36
36
/// <summary>
37
37
/// Snackbar display duration. Default is 3 seconds.
38
38
/// </summary>
@@ -61,12 +61,55 @@ public nfloat CornerRadius
61
61
}
62
62
}
63
63
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
+ }
66
76
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
+ }
67
102
68
103
/// 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
+ }
70
113
public nfloat Height { get ; set ; } = 44 ;
71
114
72
115
@@ -152,6 +195,8 @@ public TTGSnackbar() : base(CoreGraphics.CGRect.FromLTRB(0, 0, 320, 44))
152
195
this . Layer . CornerRadius = 4 ;
153
196
this . Layer . MasksToBounds = true ;
154
197
198
+ SetupSafeAreaInsets ( ) ;
199
+
155
200
this . MessageLabel = new UILabel
156
201
{
157
202
TranslatesAutoresizingMaskIntoConstraints = false ,
@@ -294,6 +339,18 @@ public TTGSnackbar() : base(CoreGraphics.CGRect.FromLTRB(0, 0, 320, 44))
294
339
//this.AddConstraints(hConstraintsForActivityIndicatorView);
295
340
}
296
341
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
+
297
354
/// <summary>
298
355
/// Show the snackbar
299
356
/// </summary>
@@ -364,7 +421,7 @@ public void Show()
364
421
localSuperView ,
365
422
NSLayoutAttribute . Bottom ,
366
423
1 ,
367
- - BottomMargin ) ;
424
+ - BottomMargin ) ;
368
425
369
426
// Avoid the "UIView-Encapsulated-Layout-Height" constraint conflicts
370
427
// http://stackoverflow.com/questions/25059443/what-is-nslayoutconstraint-uiview-encapsulated-layout-height-and-how-should-i
0 commit comments