mirror of https://github.com/SnapKit/SnapKit
Ensure constraints get cleaned up on uninstall() and put back on install()
This commit is contained in:
parent
cf977c5a1a
commit
0b92c7ff54
|
@ -380,8 +380,9 @@ public class Constraint {
|
||||||
layoutConstraints = newLayoutConstraints
|
layoutConstraints = newLayoutConstraints
|
||||||
}
|
}
|
||||||
|
|
||||||
// add constarints
|
// add constraints
|
||||||
installOnView!.addConstraints(layoutConstraints)
|
installOnView!.addConstraints(layoutConstraints)
|
||||||
|
installOnView!.snp_installedLayoutConstraints = layoutConstraints
|
||||||
|
|
||||||
self.installedOnView = installOnView
|
self.installedOnView = installOnView
|
||||||
return layoutConstraints
|
return layoutConstraints
|
||||||
|
@ -405,6 +406,15 @@ public class Constraint {
|
||||||
if constraintsToRemove.count > 0 {
|
if constraintsToRemove.count > 0 {
|
||||||
view.removeConstraints(constraintsToRemove)
|
view.removeConstraints(constraintsToRemove)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var layoutConstraints = view.snp_installedLayoutConstraints
|
||||||
|
var layoutConstraintsToKeep = Array<LayoutConstraint>()
|
||||||
|
for layoutConstraint in layoutConstraints {
|
||||||
|
if !contains(constraintsToRemove, layoutConstraint) {
|
||||||
|
layoutConstraintsToKeep.append(layoutConstraint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
view.snp_installedLayoutConstraints = layoutConstraintsToKeep
|
||||||
}
|
}
|
||||||
self.installedOnView = nil
|
self.installedOnView = nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class ConstraintMaker {
|
||||||
|
|
||||||
var layoutConstraints = view.snp_installedLayoutConstraints
|
var layoutConstraints = view.snp_installedLayoutConstraints
|
||||||
for constraint in maker.constraints {
|
for constraint in maker.constraints {
|
||||||
layoutConstraints += constraint.install(updateExisting: true)
|
layoutConstraints += constraint.installOnView(updateExisting: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
view.snp_installedLayoutConstraints = layoutConstraints
|
view.snp_installedLayoutConstraints = layoutConstraints
|
||||||
|
|
Loading…
Reference in New Issue