Stop the section header from animating its disclosure on every dequeue and remove the dead width-constraint churn in updateExpandedState.

This commit is contained in:
Brent Simmons committed 2026-08-13 11:51:45 -07:00
1 parent 1c1ae6820c
commit ce6f0dae6b
2 files changed
+18 -27

No files matched your search

@@ -26,8 +26,6 @@ final class MainFeedCollectionHeaderReusableView: UICollectionReusableView {
@IBOutlet var disclosureIndicator: UIImageView!
@IBOutlet var unreadCountLabel: UILabel!
private var unreadLabelWidthConstraint: NSLayoutConstraint?
override var accessibilityLabel: String? {
get {
if unreadCount > 0 {
@@ -60,11 +58,14 @@ final class MainFeedCollectionHeaderReusableView: UICollectionReusableView {
}
}
var disclosureExpanded = true {
didSet {
updateExpandedState(animate: true)
updateUnreadCount()
}
// Mutate via setDisclosure(isExpanded:animated:) — the supplementary provider
// sets this on every dequeue and must not animate.
private(set) var disclosureExpanded = true
func setDisclosure(isExpanded: Bool, animated: Bool) {
disclosureExpanded = isExpanded
updateExpandedState(animate: animated)
updateUnreadCount(animated: animated)
}
override func awakeFromNib() {
@@ -74,8 +75,7 @@ final class MainFeedCollectionHeaderReusableView: UICollectionReusableView {
headerTitle.isAccessibilityElement = false
unreadCountLabel.isAccessibilityElement = false
disclosureIndicator.isAccessibilityElement = false
unreadLabelWidthConstraint = unreadCountLabel.widthAnchor.constraint(lessThanOrEqualToConstant: 80)
unreadLabelWidthConstraint?.isActive = true
unreadCountLabel.widthAnchor.constraint(lessThanOrEqualToConstant: 80).isActive = true
configureUI()
addTapGesture()
}
@@ -112,14 +112,6 @@ final class MainFeedCollectionHeaderReusableView: UICollectionReusableView {
}
func updateExpandedState(animate: Bool) {
if disclosureExpanded == false {
unreadLabelWidthConstraint = unreadCountLabel.widthAnchor.constraint(lessThanOrEqualToConstant: 80)
} else {
unreadLabelWidthConstraint = unreadCountLabel.widthAnchor.constraint(lessThanOrEqualToConstant: 0)
unreadLabelWidthConstraint?.isActive = false
}
let angle: CGFloat = disclosureExpanded ? 0 : -.pi / 2
let transform = CGAffineTransform(rotationAngle: angle)
let animations = {
@@ -132,15 +124,14 @@ final class MainFeedCollectionHeaderReusableView: UICollectionReusableView {
}
}
func updateUnreadCount() {
if !disclosureExpanded && unreadCount > 0 {
func updateUnreadCount(animated: Bool = true) {
let alpha: CGFloat = (!disclosureExpanded && unreadCount > 0) ? 1 : 0
if animated {
UIView.animate(withDuration: 0.3) {
self.unreadCountLabel.alpha = 1
self.unreadCountLabel.alpha = alpha
}
} else {
UIView.animate(withDuration: 0.3) {
self.unreadCountLabel.alpha = 0
}
unreadCountLabel.alpha = alpha
}
}
@@ -363,7 +363,7 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab
headerView.sectionHeaderType = .smartFeeds
headerView.headerTitle.text = SmartFeedsController.shared.nameForDisplay
headerView.unreadCount = 0
headerView.disclosureExpanded = self.coordinator.isExpanded(SmartFeedsController.shared)
headerView.setDisclosure(isExpanded: self.coordinator.isExpanded(SmartFeedsController.shared), animated: false)
return headerView
}
@@ -375,7 +375,7 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab
headerView.sectionHeaderType = .account(sectionID)
headerView.headerTitle.text = account.nameForDisplay
headerView.unreadCount = account.unreadCount
headerView.disclosureExpanded = self.coordinator.isExpanded(account)
headerView.setDisclosure(isExpanded: self.coordinator.isExpanded(account), animated: false)
headerView.addInteraction(UIContextMenuInteraction(delegate: self))
return headerView
@@ -986,10 +986,10 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab
}
if coordinator.isExpanded(containerID) {
headerView.disclosureExpanded = false
headerView.setDisclosure(isExpanded: false, animated: true)
coordinator.collapse(containerID)
} else {
headerView.disclosureExpanded = true
headerView.setDisclosure(isExpanded: true, animated: true)
coordinator.expand(containerID)
}
}