Don't animate the disclosure icon until it has been added to the view hierarchy. Issue #1717

This commit is contained in:
Maurice Parker 2020-01-30 13:44:31 -07:00
parent 6454330c8b
commit 13a1ef0605

View File

@ -42,7 +42,6 @@ class MasterFeedTableViewSectionHeader: UITableViewHeaderFooterView {
set { set {
if titleView.text != newValue { if titleView.text != newValue {
titleView.text = newValue titleView.text = newValue
setNeedsDisplay()
setNeedsLayout() setNeedsLayout()
} }
} }
@ -50,7 +49,7 @@ class MasterFeedTableViewSectionHeader: UITableViewHeaderFooterView {
var disclosureExpanded = false { var disclosureExpanded = false {
didSet { didSet {
updateExpandedState() updateExpandedState(animate: true)
updateUnreadCountView() updateUnreadCountView()
} }
} }
@ -116,19 +115,22 @@ private extension MasterFeedTableViewSectionHeader {
func commonInit() { func commonInit() {
addSubviewAtInit(unreadCountView) addSubviewAtInit(unreadCountView)
addSubviewAtInit(titleView) addSubviewAtInit(titleView)
updateExpandedState()
addSubviewAtInit(disclosureView) addSubviewAtInit(disclosureView)
updateExpandedState(animate: false)
addBackgroundView() addBackgroundView()
addSubviewAtInit(topSeparatorView) addSubviewAtInit(topSeparatorView)
addSubviewAtInit(bottomSeparatorView) addSubviewAtInit(bottomSeparatorView)
} }
func updateExpandedState() { func updateExpandedState(animate: Bool) {
if !isLastSection && self.disclosureExpanded { if !isLastSection && self.disclosureExpanded {
self.bottomSeparatorView.isHidden = false self.bottomSeparatorView.isHidden = false
} }
let duration = animate ? 0.3 : 0.0
UIView.animate( UIView.animate(
withDuration: 0.3, withDuration: duration,
animations: { animations: {
if self.disclosureExpanded { if self.disclosureExpanded {
self.disclosureView.transform = CGAffineTransform(rotationAngle: 1.570796) self.disclosureView.transform = CGAffineTransform(rotationAngle: 1.570796)