Skip to content

Commit cc1b635

Browse files
committed
Add absoluteInsets size option
1 parent 46347da commit cc1b635

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

SwiftMessages/Layout.swift

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public struct Layout {
3535
public enum Dimension {
3636
case absolute(CGFloat)
3737
case relative(CGFloat, to: Boundary)
38+
case absoluteInsets(CGFloat, to: Boundary)
3839
}
3940

4041
public var width: Dimension?
@@ -81,6 +82,16 @@ extension Layout.Insets.Dimension {
8182
}
8283
}
8384

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+
8495
extension Layout.Center.Dimension {
8596
var boundary: Layout.Boundary {
8697
switch self {

SwiftMessages/MaskingView.swift

+11-5
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,8 @@ class MaskingView: PassthroughView, LayoutInstalling {
417417
for dimension: Layout.Size.Dimension,
418418
extractor: (CGRect) -> CGFloat
419419
) -> 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 }
424422
let insets: UIEdgeInsets
425423
switch boundary {
426424
case .superview: insets = .zero
@@ -432,7 +430,15 @@ class MaskingView: PassthroughView, LayoutInstalling {
432430
insets = layoutMargins
433431
}
434432
}
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
436442
}
437443
}
438444

0 commit comments

Comments
 (0)