Skip to content

Commit

Permalink
Refactors pin methods and cuts down on excess methods
Browse files Browse the repository at this point in the history
  • Loading branch information
joshpc committed Jun 20, 2017
1 parent cfa21f9 commit 8cbae2a
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions Pins/View+Pins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,7 @@ public extension Pinnable where Self: Pinnable {
/// - Returns: The activated `NSLayoutConstraint` object that was created.
@discardableResult
public func pin<View: Pinnable>(_ edge: HorizontalAnchor, to view: View, padding: CGFloat = 0.0) -> NSLayoutConstraint {
let constraint = anchor(self, for: edge).constraint(equalTo: anchor(view, for: edge),
constant: convertPadding(edge, padding))

return disableTranslatesAutoresizingMaskAndActivate(constraint)
return pin(edge, to: anchor(view, for: edge), padding: padding)
}

/// Pin the specified `HorizontalAnchor` of the view less than or equal to the same anchor on another view. Calling this method sets `translatesAutoresizingMaskIntoConstraints` to `false` on the caller.
Expand All @@ -317,10 +314,7 @@ public extension Pinnable where Self: Pinnable {
/// - Returns: The activated `NSLayoutConstraint` object that was created.
@discardableResult
public func pin<View: Pinnable>(_ edge: HorizontalAnchor, lessThanOrEqualTo view: View, padding: CGFloat = 0.0) -> NSLayoutConstraint {
let constraint = anchor(self, for: edge).constraint(lessThanOrEqualTo: anchor(view, for: edge),
constant: convertPadding(edge, padding))

return disableTranslatesAutoresizingMaskAndActivate(constraint)
return pin(edge, lessThanOrEqualTo: anchor(view, for: edge), padding: padding)
}

/// Pin the specified `HorizontalAnchor` of the view greater than equal to the same anchor on another view. Calling this method sets `translatesAutoresizingMaskIntoConstraints` to `false` on the caller.
Expand All @@ -332,10 +326,7 @@ public extension Pinnable where Self: Pinnable {
/// - Returns: The activated `NSLayoutConstraint` object that was created.
@discardableResult
public func pin<View: Pinnable>(_ edge: HorizontalAnchor, greaterThanOrEqualTo view: View, padding: CGFloat = 0.0) -> NSLayoutConstraint {
let constraint = anchor(self, for: edge).constraint(greaterThanOrEqualTo: anchor(view, for: edge),
constant: convertPadding(edge, padding))

return disableTranslatesAutoresizingMaskAndActivate(constraint)
return pin(edge, greaterThanOrEqualTo: anchor(view, for: edge), padding: padding)
}

// MARK: Vertical Anchors
Expand Down Expand Up @@ -394,10 +385,7 @@ public extension Pinnable where Self: Pinnable {
/// - Returns: The activated `NSLayoutConstraint` object that was created.
@discardableResult
public func pin<View: Pinnable>(_ edge: VerticalAnchor, to view: View, padding: CGFloat = 0.0) -> NSLayoutConstraint {
let constraint = anchor(self, for: edge).constraint(equalTo: anchor(view, for: edge),
constant: convertPadding(edge, padding))

return disableTranslatesAutoresizingMaskAndActivate(constraint)
return pin(edge, to: anchor(view, for: edge), padding: padding)
}

/// Pin the specified `VerticalAnchor` of the view less than or equal to the same anchor on another view. Calling this method sets `translatesAutoresizingMaskIntoConstraints` to `false` on the caller.
Expand All @@ -409,10 +397,7 @@ public extension Pinnable where Self: Pinnable {
/// - Returns: The activated `NSLayoutConstraint` object that was created.
@discardableResult
public func pin<View: Pinnable>(_ edge: VerticalAnchor, lessThanOrEqualTo view: View, padding: CGFloat = 0.0) -> NSLayoutConstraint {
let constraint = anchor(self, for: edge).constraint(lessThanOrEqualTo: anchor(view, for: edge),
constant: convertPadding(edge, padding))

return disableTranslatesAutoresizingMaskAndActivate(constraint)
return pin(edge, lessThanOrEqualTo: anchor(view, for: edge), padding: padding)
}

/// Pin the specified `VerticalAnchor` of the view greater than or equal to the same anchor on another view. Calling this method sets `translatesAutoresizingMaskIntoConstraints` to `false` on the caller.
Expand All @@ -424,10 +409,7 @@ public extension Pinnable where Self: Pinnable {
/// - Returns: The activated `NSLayoutConstraint` object that was created.
@discardableResult
public func pin<View: Pinnable>(_ edge: VerticalAnchor, greaterThanOrEqualTo view: View, padding: CGFloat = 0.0) -> NSLayoutConstraint {
let constraint = anchor(self, for: edge).constraint(greaterThanOrEqualTo: anchor(view, for: edge),
constant: convertPadding(edge, padding))

return disableTranslatesAutoresizingMaskAndActivate(constraint)
return pin(edge, greaterThanOrEqualTo: anchor(view, for: edge), padding: padding)
}

// MARK: Dimension Anchors
Expand Down

0 comments on commit 8cbae2a

Please sign in to comment.