Skip to content

Commit

Permalink
Code review adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivo Silva committed Jan 16, 2020
1 parent b2f6325 commit a9ad12a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 152 deletions.
50 changes: 11 additions & 39 deletions Sources/AutoLayout/Array+ConstrainableProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ extension Array where Element: LeadingConstrainableProxy {
func alignLeading() -> [NSLayoutConstraint] {

guard let first = first else { return [] }
return self[1...].map {
$0.prepare()
return first.leading(to: $0)
}
return self[1...].map { first.leading(to: $0) }
}
}

Expand All @@ -19,10 +16,7 @@ extension Array where Element: TrailingConstrainableProxy {
func alignTrailing() -> [NSLayoutConstraint] {

guard let first = first else { return [] }
return self[1...].map {
$0.prepare()
return first.trailing(to: $0)
}
return self[1...].map { first.trailing(to: $0) }
}
}

Expand All @@ -32,10 +26,7 @@ extension Array where Element: TopConstrainableProxy {
func alignTop() -> [NSLayoutConstraint] {

guard let first = first else { return [] }
return self[1...].map {
$0.prepare()
return first.top(to: $0)
}
return self[1...].map { first.top(to: $0) }
}
}

Expand All @@ -45,10 +36,7 @@ extension Array where Element: BottomConstrainableProxy {
func alignBottom() -> [NSLayoutConstraint] {

guard let first = first else { return [] }
return self[1...].map {
$0.prepare()
return first.bottom(to: $0)
}
return self[1...].map { first.bottom(to: $0) }
}
}

Expand All @@ -58,20 +46,14 @@ extension Array where Element: PositionConstrainableProxy {
func alignCenterX() -> [NSLayoutConstraint] {

guard let first = first else { return [] }
return self[1...].map {
$0.prepare()
return first.centerX(to: $0)
}
return self[1...].map { first.centerX(to: $0) }
}

@discardableResult
func alignCenterY() -> [NSLayoutConstraint] {

guard let first = first else { return [] }
return self[1...].map {
$0.prepare()
return first.centerY(to: $0)
}
return self[1...].map { first.centerY(to: $0) }
}
}

Expand All @@ -81,20 +63,13 @@ extension Array where Element: WidthConstrainableProxy {
func equalWidth() -> [NSLayoutConstraint] {

guard let first = first else { return [] }
return self[1...].map {
$0.prepare()
return first.width(to: $0)
}
return self[1...].map { first.width(to: $0) }
}

@discardableResult
func equal(width: CGFloat) -> [NSLayoutConstraint] {

guard isEmpty == false else { return [] }
return map {
$0.prepare()
return $0.width(width, relation: .equal)
}
map { $0.width(width, relation: .equal) }
}
}

Expand All @@ -104,10 +79,7 @@ extension Array where Element: HeightConstrainableProxy {
func equalHeight() -> [NSLayoutConstraint] {

guard let first = first else { return [] }
return self[1...].map {
$0.prepare()
return first.height(to: $0)
}
return self[1...].map { first.height(to: $0) }
}
}

Expand All @@ -116,7 +88,7 @@ extension Array where Element: LeadingConstrainableProxy & TrailingConstrainable
@discardableResult
func distributeHorizontally(margin: CGFloat = 0.0) -> [NSLayoutConstraint] {

last?.prepare()
guard isEmpty == false else { return [] }
return zip(self, self[1...]).map { first, second in
second.leadingToTrailing(of: first, offset: margin)
}
Expand All @@ -128,7 +100,7 @@ extension Array where Element: TopConstrainableProxy & BottomConstrainableProxy
@discardableResult
func distributeVertically(margin: CGFloat = 0.0) -> [NSLayoutConstraint] {

last?.prepare()
guard isEmpty == false else { return [] }
return zip(self, self[1...]).map { first, second in
second.topToBottom(of: first, offset: margin)
}
Expand Down
8 changes: 2 additions & 6 deletions Sources/AutoLayout/Constrain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ final class ConstraintGroup {
}

var isActive: Bool {
get {
return constraints.allSatisfy { $0.isActive }
}
set {
newValue ? install(constraints) : uninstall(constraints)
}
get { constraints.allSatisfy { $0.isActive } }
set { newValue ? install(constraints) : uninstall(constraints) }
}

private func install(_ constraints: [NSLayoutConstraint]) {
Expand Down
Loading

0 comments on commit a9ad12a

Please sign in to comment.