forked from shadowfacts/Tusker
Don't update constraints in StatusContentContainer.setCollapsed unless the state actually changes
This commit is contained in:
parent
6501343f24
commit
97c7104dbc
|
@ -42,6 +42,8 @@ class StatusContentContainer: UIView {
|
||||||
private var verticalConstraints: [NSLayoutConstraint] = []
|
private var verticalConstraints: [NSLayoutConstraint] = []
|
||||||
private var lastSubviewBottomConstraint: NSLayoutConstraint?
|
private var lastSubviewBottomConstraint: NSLayoutConstraint?
|
||||||
private var zeroHeightConstraint: NSLayoutConstraint!
|
private var zeroHeightConstraint: NSLayoutConstraint!
|
||||||
|
|
||||||
|
private var isCollapsed = false
|
||||||
|
|
||||||
override init(frame: CGRect) {
|
override init(frame: CGRect) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
|
@ -97,13 +99,20 @@ class StatusContentContainer: UIView {
|
||||||
lastSubviewBottomConstraint?.isActive = false
|
lastSubviewBottomConstraint?.isActive = false
|
||||||
// this constraint needs to have low priority so that during the collapse/expand animation, the content container is the view that shrinks/expands
|
// this constraint needs to have low priority so that during the collapse/expand animation, the content container is the view that shrinks/expands
|
||||||
lastSubviewBottomConstraint = subviews.last(where: { !$0.isHidden })!.bottomAnchor.constraint(equalTo: bottomAnchor)
|
lastSubviewBottomConstraint = subviews.last(where: { !$0.isHidden })!.bottomAnchor.constraint(equalTo: bottomAnchor)
|
||||||
lastSubviewBottomConstraint!.isActive = true
|
lastSubviewBottomConstraint!.isActive = !isCollapsed
|
||||||
lastSubviewBottomConstraint!.priority = .defaultLow
|
lastSubviewBottomConstraint!.priority = .defaultLow
|
||||||
|
|
||||||
|
zeroHeightConstraint.isActive = isCollapsed
|
||||||
|
|
||||||
super.updateConstraints()
|
super.updateConstraints()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setCollapsed(_ collapsed: Bool) {
|
func setCollapsed(_ collapsed: Bool) {
|
||||||
|
guard collapsed != isCollapsed else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
isCollapsed = collapsed
|
||||||
|
|
||||||
// ensure that we have a lastSubviewBottomConstraint
|
// ensure that we have a lastSubviewBottomConstraint
|
||||||
updateConstraintsIfNeeded()
|
updateConstraintsIfNeeded()
|
||||||
// force unwrap because the content container should always have at least one view
|
// force unwrap because the content container should always have at least one view
|
||||||
|
|
Loading…
Reference in New Issue