From ce6f0dae6bc473780678391ac303e0214fd4e87c Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 13 Aug 2026 11:51:45 -0700 Subject: [PATCH] Stop the section header from animating its disclosure on every dequeue and remove the dead width-constraint churn in updateExpandedState. --- ...MainFeedCollectionHeaderReusableView.swift | 37 +++++++------------ .../MainFeedCollectionViewController.swift | 8 ++-- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/iOS/MainFeed/Collection View Cells/MainFeedCollectionHeaderReusableView.swift b/iOS/MainFeed/Collection View Cells/MainFeedCollectionHeaderReusableView.swift index 7fb4bac21..5dca59df8 100644 --- a/iOS/MainFeed/Collection View Cells/MainFeedCollectionHeaderReusableView.swift +++ b/iOS/MainFeed/Collection View Cells/MainFeedCollectionHeaderReusableView.swift @@ -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 } } diff --git a/iOS/MainFeed/MainFeedCollectionViewController.swift b/iOS/MainFeed/MainFeedCollectionViewController.swift index 8de5c67d6..8d5b2c7ee 100644 --- a/iOS/MainFeed/MainFeedCollectionViewController.swift +++ b/iOS/MainFeed/MainFeedCollectionViewController.swift @@ -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) } }