Skip to content
This repository was archived by the owner on Sep 15, 2019. It is now read-only.

Commit b779507

Browse files
author
Satinder Singh
committed
[FEATURE] Added Greater SnapManager Chaining
- SnapManager supports greater number of chaining methods
1 parent 29fcbcc commit b779507

File tree

7 files changed

+112
-11
lines changed

7 files changed

+112
-11
lines changed

Example/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- SnapLayout (1.1.0)
2+
- SnapLayout (1.3.0)
33

44
DEPENDENCIES:
55
- SnapLayout (from `../`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
99
:path: "../"
1010

1111
SPEC CHECKSUMS:
12-
SnapLayout: 3fd4d7b9e43598c6d2140e2827a5ea5791dced05
12+
SnapLayout: 80268468432382a44ba9277365d42b4acb4932d1
1313

1414
PODFILE CHECKSUM: f6cd245470fd9f107dd94e8ef9bffeaa3467d0af
1515

Example/Pods/Local Podspecs/SnapLayout.podspec.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/SnapLayout/Info.plist

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ button1.snap(trailingView: button2, constant: 8)
7474
```
7575
These buttons are now side by side where button2 is now the trailingView. No longer will developers have to think which trailing constraint should apply to which leading constraint. This keeps the code lean and clean.
7676

77-
<!-- Chaining ability not setup yet. TODO
7877
### Chaining
7978
```swift
8079
let snapManager = view.snap(top: 8, leading: 8, width: 50)
@@ -83,7 +82,6 @@ print(snapManager.top?.constant) # 8.0
8382
print(snapManager.height?.constant) # 0.5
8483
```
8584
Snap calls may also be chained and will continue to return a `SnapManager`.
86-
-->
8785
### Constants
8886
A `SnapConfig ` struct is also available where a developer may list all of their constraint constants beforehand and provide this type to the snap method argument.
8987

SnapLayout.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'SnapLayout'
11-
s.version = '1.2.2'
11+
s.version = '1.3.0'
1212
s.summary = 'Concise API for iOS Auto Layout'
1313

1414
s.description = <<-DESC

SnapLayout/Classes/SnapManager.swift

+104-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class SnapManager {
8585
/// - constants: ConstraintConstants to apply
8686
/// - Returns: SnapManager holding all the values associated with constraints
8787
@discardableResult
88-
func snap(to view: UIView? = nil, constants: SnapConfig) -> SnapManager {
88+
public func snap(to view: UIView? = nil, constants: SnapConfig) -> SnapManager {
8989
return snap(to: view,
9090
top: constants.top,
9191
leading: constants.leading,
@@ -97,4 +97,107 @@ public class SnapManager {
9797
centerY: constants.centerY)
9898
}
9999

100+
/// Apply width anchor between calling view and argument view with specified multiplier
101+
///
102+
/// - Parameters:
103+
/// - view: UIView to apply constraint with (defaulted to superview if nil)
104+
/// - multiplier: Multiplier value to apply constraint with (default 1)
105+
/// - Returns: SnapManager holding all the values associated with constraints
106+
@discardableResult
107+
public func snapWidth(to view: UIView? = nil, multiplier: CGFloat = 1) -> SnapManager {
108+
guard let selfView = selfView else {
109+
print("SnapLayout Error - Cannot apply constraint upon a view that is not retained")
110+
return SnapManager()
111+
}
112+
return selfView.snapWidth(to: view, multiplier: multiplier)
113+
}
114+
115+
/// Apply height anchor between calling view and argument view with specified multiplier
116+
///
117+
/// - Parameters:
118+
/// - view: UIView to apply constraint with (defaulted to superview if nil)
119+
/// - multiplier: Multiplier value to apply constraint with (default 1)
120+
/// - Returns: SnapManager holding all the values associated with constraints
121+
@discardableResult
122+
public func snapHeight(to view: UIView? = nil, multiplier: CGFloat = 1) -> SnapManager {
123+
guard let selfView = selfView else {
124+
print("SnapLayout Error - Cannot apply constraint upon a view that is not retained")
125+
return SnapManager()
126+
}
127+
return selfView.snapHeight(to: view, multiplier: multiplier)
128+
}
129+
130+
/// Anchor size by applying width anchor and height anchor
131+
///
132+
/// - Parameter size: CGSize specifying width and height
133+
/// - Returns: SnapManager holding all the values associated with constraints
134+
@discardableResult
135+
public func snapSize(size: CGSize) -> SnapManager {
136+
guard let selfView = selfView else {
137+
print("SnapLayout Error - Cannot apply constraint upon a view that is not retained")
138+
return SnapManager()
139+
}
140+
return selfView.snapSize(size: size)
141+
}
142+
143+
/// Applies necessary constraint to ensure calling view will be leading view and the trailingView is on the trailing side.
144+
/// Initalizes trailing property of SnapManager
145+
/// - Parameters:
146+
/// - trailingView: View who will be shown as the trailingView
147+
/// - constant: Constant value to apply constraint with (default 0)
148+
/// - Returns: SnapManager holding all the values associated with constraints
149+
@discardableResult
150+
public func snap(trailingView: UIView, constant: CGFloat = 0) -> SnapManager {
151+
guard let selfView = selfView else {
152+
print("SnapLayout Error - Cannot apply constraint upon a view that is not retained")
153+
return SnapManager()
154+
}
155+
return selfView.snap(trailingView: trailingView, constant: constant)
156+
}
157+
158+
/// Applies necessary constraint to ensure calling view will be trailing and the leadingView is on the leading side.
159+
/// Initalizes trailing property of SnapManager
160+
/// - Parameters:
161+
/// - leadingView: View who will be shown as the leadingView
162+
/// - constant: Constant value to apply constraint with (default 0)
163+
/// - Returns: SnapManager holding all the values associated with constraints
164+
@discardableResult
165+
public func snap(leadingView: UIView, constant: CGFloat = 0) -> SnapManager {
166+
guard let selfView = selfView else {
167+
print("SnapLayout Error - Cannot apply constraint upon a view that is not retained")
168+
return SnapManager()
169+
}
170+
return selfView.snap(leadingView: leadingView, constant: constant)
171+
}
172+
173+
/// Applies necessary constraint to ensure calling view will be top view and the bottom view will be bottom view
174+
/// Initalizes bottom property of SnapManager
175+
/// - Parameters:
176+
/// - bottomView: View who will be shown as the bottomView
177+
/// - constant: Constant value to apply constraint with (default 0)
178+
/// - Returns: SnapManager holding all the values associated with constraints
179+
@discardableResult
180+
public func snap(bottomView: UIView, constant: CGFloat = 0) -> SnapManager {
181+
guard let selfView = selfView else {
182+
print("SnapLayout Error - Cannot apply constraint upon a view that is not retained")
183+
return SnapManager()
184+
}
185+
return selfView.snap(bottomView: bottomView, constant: constant)
186+
}
187+
188+
/// Applies necessary constraint to ensure calling view will be bottom view and the top view will be top view
189+
///
190+
/// - Parameters:
191+
/// - topView: View who will be shown as the bottomView
192+
/// - constant: Constant value to apply constraint with (default 0)
193+
/// - Returns: SnapManager holding all the values associated with constraints
194+
@discardableResult
195+
public func snap(topView: UIView, constant: CGFloat = 0) -> SnapManager {
196+
guard let selfView = selfView else {
197+
print("SnapLayout Error - Cannot apply constraint upon a view that is not retained")
198+
return SnapManager()
199+
}
200+
return selfView.snap(topView: topView, constant: constant)
201+
}
202+
100203
}

0 commit comments

Comments
 (0)