mirror of https://github.com/SnapKit/SnapKit
Rework how updateConstraints works if no existing constraints
updateConstraints will no longer allow creation of new constraints but if you call updateConstraints and there have been no previous constraints created it will re-route to makeConstraints
This commit is contained in:
parent
ac0b5829aa
commit
67271dc666
|
@ -225,8 +225,7 @@ public class Constraint {
|
||||||
let layoutConstraints = self.layoutConstraints
|
let layoutConstraints = self.layoutConstraints
|
||||||
let existingLayoutConstraints = view.snp.layoutConstraints
|
let existingLayoutConstraints = view.snp.layoutConstraints
|
||||||
|
|
||||||
if updatingExisting && existingLayoutConstraints.count > 0 {
|
if updatingExisting {
|
||||||
|
|
||||||
for layoutConstraint in layoutConstraints {
|
for layoutConstraint in layoutConstraints {
|
||||||
let existingLayoutConstraint = existingLayoutConstraints.first { $0 == layoutConstraint }
|
let existingLayoutConstraint = existingLayoutConstraints.first { $0 == layoutConstraint }
|
||||||
guard let updateLayoutConstraint = existingLayoutConstraint else {
|
guard let updateLayoutConstraint = existingLayoutConstraint else {
|
||||||
|
@ -236,7 +235,6 @@ public class Constraint {
|
||||||
let updateLayoutAttribute = (updateLayoutConstraint.secondAttribute == .notAnAttribute) ? updateLayoutConstraint.firstAttribute : updateLayoutConstraint.secondAttribute
|
let updateLayoutAttribute = (updateLayoutConstraint.secondAttribute == .notAnAttribute) ? updateLayoutConstraint.firstAttribute : updateLayoutConstraint.secondAttribute
|
||||||
updateLayoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: updateLayoutAttribute)
|
updateLayoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: updateLayoutAttribute)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
NSLayoutConstraint.activate(layoutConstraints)
|
NSLayoutConstraint.activate(layoutConstraints)
|
||||||
view.snp.add(layoutConstraints: layoutConstraints)
|
view.snp.add(layoutConstraints: layoutConstraints)
|
||||||
|
|
|
@ -180,6 +180,11 @@ public class ConstraintMaker {
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static func updateConstraints(view: ConstraintView, closure: (_ make: ConstraintMaker) -> Void) {
|
internal static func updateConstraints(view: ConstraintView, closure: (_ make: ConstraintMaker) -> Void) {
|
||||||
|
guard view.snp.layoutConstraints.count > 0 else {
|
||||||
|
self.makeConstraints(view: view, closure: closure)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let maker = ConstraintMaker(view: view)
|
let maker = ConstraintMaker(view: view)
|
||||||
closure(maker)
|
closure(maker)
|
||||||
let constraints = maker.descriptions
|
let constraints = maker.descriptions
|
||||||
|
|
Loading…
Reference in New Issue