Skip to content

Commit de0452d

Browse files
committed
Updates to offset operator to work with axis-specific Edge types
1 parent c1e194b commit de0452d

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

Cartography/Edge+OffsetOperator.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,16 @@ precedencegroup OffsetPrecedence {
2222
infix operator |-|: OffsetPrecedence
2323

2424
@available(iOS 10.0, macOS 10.12, tvOS 10.0, *)
25-
extension Edge {
26-
public static func |-|(lhs: Edge, rhs: Edge) -> Dimension {
27-
if let first = lhs.xAnchor, let second = rhs.xAnchor {
28-
return Dimension(lhs.context, first.anchorWithOffset(to: second))
29-
} else if let first = lhs.yAnchor, let second = rhs.yAnchor {
25+
extension EdgeXAxis {
26+
public static func |-|(lhs: EdgeXAxis, rhs: EdgeXAxis) -> Dimension {
27+
if let first = lhs.anchor, let second = rhs.anchor {
3028
return Dimension(lhs.context, first.anchorWithOffset(to: second))
3129
} else {
3230
return Dimension(lhs.context, lhs.item, .notAnAttribute)
3331
}
3432
}
3533

36-
internal var xAnchor: NSLayoutXAxisAnchor? {
34+
internal var anchor: NSLayoutXAxisAnchor? {
3735
if attribute == .left, let item = item as? SupportsLeftAnchor {
3836
return item.leftAnchor
3937
}
@@ -53,8 +51,19 @@ extension Edge {
5351
return nil
5452
}
5553
}
56-
57-
internal var yAnchor: NSLayoutYAxisAnchor? {
54+
}
55+
56+
@available(iOS 10.0, macOS 10.12, tvOS 10.0, *)
57+
extension EdgeYAxis {
58+
public static func |-|(lhs: EdgeYAxis, rhs: EdgeYAxis) -> Dimension {
59+
if let first = lhs.anchor, let second = rhs.anchor {
60+
return Dimension(lhs.context, first.anchorWithOffset(to: second))
61+
} else {
62+
return Dimension(lhs.context, lhs.item, .notAnAttribute)
63+
}
64+
}
65+
66+
internal var anchor: NSLayoutYAxisAnchor? {
5867
if attribute == .top, let item = item as? SupportsTopAnchor {
5968
return item.topAnchor
6069
}

0 commit comments

Comments
 (0)