Don't update constraints in StatusContentContainer.setCollapsed unless the state actually changes

This commit is contained in:
Shadowfacts 2022-12-04 11:14:19 -05:00
parent 6501343f24
commit 97c7104dbc
1 changed files with 10 additions and 1 deletions

View File

@ -43,6 +43,8 @@ class StatusContentContainer: UIView {
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