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 existingLayoutConstraints = view.snp.layoutConstraints
|
||||
|
||||
if updatingExisting && existingLayoutConstraints.count > 0 {
|
||||
|
||||
if updatingExisting {
|
||||
for layoutConstraint in layoutConstraints {
|
||||
let existingLayoutConstraint = existingLayoutConstraints.first { $0 == layoutConstraint }
|
||||
guard let updateLayoutConstraint = existingLayoutConstraint else {
|
||||
|
@ -236,7 +235,6 @@ public class Constraint {
|
|||
let updateLayoutAttribute = (updateLayoutConstraint.secondAttribute == .notAnAttribute) ? updateLayoutConstraint.firstAttribute : updateLayoutConstraint.secondAttribute
|
||||
updateLayoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: updateLayoutAttribute)
|
||||
}
|
||||
|
||||
} else {
|
||||
NSLayoutConstraint.activate(layoutConstraints)
|
||||
view.snp.add(layoutConstraints: layoutConstraints)
|
||||
|
|
|
@ -180,6 +180,11 @@ public class ConstraintMaker {
|
|||
}
|
||||
|
||||
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)
|
||||
closure(maker)
|
||||
let constraints = maker.descriptions
|
||||
|
|
Loading…
Reference in New Issue