Skip to content

Commit

Permalink
Merge pull request #158 from 0xLeif/develop
Browse files Browse the repository at this point in the history
v1.2
  • Loading branch information
0xLeif authored Jun 15, 2020
2 parents 36b9886 + af87e07 commit a960f27
Show file tree
Hide file tree
Showing 12 changed files with 1,753 additions and 41 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,28 +104,34 @@ class ViewController: UIViewController {

****

# oneleif Project
## oneleif project
This means that the project is sponsored by the oneleif community, and the collaborators are team members from oneleif.

![](https://github.com/oneleif/olDocs/blob/master/assets/images/oneleif_logos/full_logo/oneleif_whiteback.png)
<a href="http://oneleif.com" rel="oneleif website">![](https://github.com/oneleif/olDocs/blob/master/assets/images/oneleif_logos/full_logo/oneleif_whiteback.png)</a>

### Project Info

This project is a oneleif active project.

[![](https://img.shields.io/badge/oneleif-Twitter-blue.svg)](https://twitter.com/oneleifdev)

[![](https://img.shields.io/badge/oneleif-YouTube-red.svg)](https://www.youtube.com/channel/UC3HN0jID38K0Vb_WChvgQmA)

## What is oneleif?
oneleif is a nonprofit community that supports tech minded individuals. We do this by offering a fun loving community that works on Open Sourced projects together.
We love to give back through free resources and guidance.

## How to join oneleif
Click on the link below to join the Discord server.

You will start with limited permissions, in a text channel that only moderators will see.
[![](https://img.shields.io/badge/oneleif-Discord-7284be.svg)](https://discord.gg/tv9UdJK)

To get full access: read the rules, make an introduction in #introductions, and add an appropriate username.
-OR-

When you're done with the above, shoot a message to the #start channel to let us know, and we will give you full access.
[Check out our website](http://oneleif.com)

[![](https://img.shields.io/badge/oneleif-Discord-7284be.svg)](https://discord.gg/tv9UdJK)

### Questions?
Feel free to email us at: [email protected]

-OR-

Ask questions in the discord
49 changes: 49 additions & 0 deletions Sources/SwiftUIKit/Extensions/NSLayoutConstraint+SwiftUIKit.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// NSLayoutConstraint+SwiftUIKit.swift
// SwiftUIKit
//
// Created by Zach Eriksen on 5/17/20.
//

import UIKit

@available(iOS 10.0, *)
public extension NSLayoutConstraint {

/// Check if the `constraint` is connected to the `anchor`
func isConnected<T>(toAnchor anchor: NSLayoutAnchor<T>) -> Bool {
firstAnchor == anchor || secondAnchor == anchor
}
}

@available(iOS 10.0, *)
public extension UIView {

/// The leading constraints held by the view
var leadingConstraints: [NSLayoutConstraint] {
constraints.filter { (constraint) -> Bool in
constraint.isConnected(toAnchor: leadingAnchor)
}
}

/// The trailing constraints held by the view
var trailingConstraints: [NSLayoutConstraint] {
constraints.filter { (constraint) -> Bool in
constraint.isConnected(toAnchor: trailingAnchor)
}
}

/// The top constraints held by the view
var topConstraints: [NSLayoutConstraint] {
constraints.filter { (constraint) -> Bool in
constraint.isConnected(toAnchor: topAnchor)
}
}

/// The bottom constraints held by the view
var bottomConstraints: [NSLayoutConstraint] {
constraints.filter { (constraint) -> Bool in
constraint.isConnected(toAnchor: bottomAnchor)
}
}
}
50 changes: 46 additions & 4 deletions Sources/SwiftUIKit/Extensions/UIView+SwiftUIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,48 @@ public extension UIView {
return self
}

/// Update a padding anchor's constant value
@available(iOS 10.0, *)
@discardableResult
func update(padding: Padding) -> Self {
switch padding {
case .top(let value):
topConstraints.first?.constant = CGFloat(value)
case .bottom(let value):
bottomConstraints.first?.constant = CGFloat(-value)
case .leading(let value):
leadingConstraints.first?.constant = CGFloat(value)
case .trailing(let value):
trailingConstraints.first?.constant = CGFloat(-value)
}

return self
}

/// Update an array of padding anchors' constant values
@available(iOS 10.0, *)
@discardableResult
func update(padding: [Padding]) -> Self {
padding.forEach { update(padding: $0) }

return self
}

/// Update all padding anchors' constant value
@available(iOS 10.0, *)
@discardableResult
func update(padding: Float) -> Self {
update(padding: [
.top(padding),
.bottom(padding),
.leading(padding),
.trailing(padding)
])

return self
}


/// Remove the height anchor constraint
@available(iOS 10.0, *)
@discardableResult
Expand Down Expand Up @@ -432,7 +474,7 @@ public extension UIView {
/// - animated: Should animate setting the left UIBarButtonItem
@discardableResult
func navigateSetLeft(barButton: UIBarButtonItem?, animated: Bool = true) -> Self {
Navigate.shared.setLeft(barButton: barButton)
Navigate.shared.setLeft(barButton: barButton, animated: animated)

return self
}
Expand All @@ -443,7 +485,7 @@ public extension UIView {
/// - animated: Should animate setting the right UIBarButtonItem
@discardableResult
func navigateSetRight(barButton: UIBarButtonItem?, animated: Bool = true) -> Self {
Navigate.shared.setRight(barButton: barButton)
Navigate.shared.setRight(barButton: barButton, animated: animated)

return self
}
Expand All @@ -454,7 +496,7 @@ public extension UIView {
/// - animated: Should animate setting the left [UIBarButtonItem]
@discardableResult
func navigateSetLeft(barButtons: [UIBarButtonItem]?, animated: Bool = true) -> Self {
Navigate.shared.setLeft(barButtons: barButtons)
Navigate.shared.setLeft(barButtons: barButtons, animated: animated)

return self
}
Expand All @@ -465,7 +507,7 @@ public extension UIView {
/// - animated: Should animate setting the right [UIBarButtonItem]
@discardableResult
func navigateSetRight(barButtons: [UIBarButtonItem]?, animated: Bool = true) -> Self {
Navigate.shared.setRight(barButtons: barButtons)
Navigate.shared.setRight(barButtons: barButtons, animated: animated)

return self
}
Expand Down
Loading

0 comments on commit a960f27

Please sign in to comment.