File tree 2 files changed +22
-5
lines changed
2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ public struct Layout {
35
35
public enum Dimension {
36
36
case absolute( CGFloat )
37
37
case relative( CGFloat , to: Boundary )
38
+ case absoluteInsets( CGFloat , to: Boundary )
38
39
}
39
40
40
41
public var width : Dimension ?
@@ -81,6 +82,16 @@ extension Layout.Insets.Dimension {
81
82
}
82
83
}
83
84
85
+ extension Layout . Size . Dimension {
86
+ var boundary : Layout . Boundary ? {
87
+ switch self {
88
+ case . absolute( _) : return nil
89
+ case . relative( _, let boundary) : return boundary
90
+ case . absoluteInsets( _, let boundary) : return boundary
91
+ }
92
+ }
93
+ }
94
+
84
95
extension Layout . Center . Dimension {
85
96
var boundary : Layout . Boundary {
86
97
switch self {
Original file line number Diff line number Diff line change @@ -417,10 +417,8 @@ class MaskingView: PassthroughView, LayoutInstalling {
417
417
for dimension: Layout . Size . Dimension ,
418
418
extractor: ( CGRect ) -> CGFloat
419
419
) -> CGFloat {
420
- switch dimension {
421
- case . absolute( let dimension) :
422
- return dimension
423
- case . relative( let percentage, let boundary) :
420
+ let insetBounds : CGRect = {
421
+ guard let boundary = dimension. boundary else { return . zero }
424
422
let insets : UIEdgeInsets
425
423
switch boundary {
426
424
case . superview: insets = . zero
@@ -432,7 +430,15 @@ class MaskingView: PassthroughView, LayoutInstalling {
432
430
insets = layoutMargins
433
431
}
434
432
}
435
- return extractor ( bounds. inset ( by: insets) ) * percentage
433
+ return bounds. inset ( by: insets)
434
+ } ( )
435
+ switch dimension {
436
+ case . absolute( let dimension) :
437
+ return dimension
438
+ case . relative( let percentage, _) :
439
+ return extractor ( insetBounds) * percentage
440
+ case . absoluteInsets( let dimension, _) :
441
+ return extractor ( insetBounds) - dimension * 2
436
442
}
437
443
}
438
444
You can’t perform that action at this time.
0 commit comments