Fix title flashing in after navigation bar is shown. Issue #1336

This commit is contained in:
Maurice Parker 2019-11-24 10:47:09 -06:00
parent b5525e1a9e
commit a052bbe74e
1 changed files with 23 additions and 10 deletions

View File

@ -13,9 +13,9 @@ import Articles
class MasterTimelineViewController: UITableViewController, UndoableCommandRunner { class MasterTimelineViewController: UITableViewController, UndoableCommandRunner {
private var titleView: MasterTimelineTitleView?
private var numberOfTextLines = 0 private var numberOfTextLines = 0
private var iconSize = IconSize.medium private var iconSize = IconSize.medium
private lazy var feedTapGestureRecognizer = UITapGestureRecognizer(target: self, action:#selector(showFeedInspector(_:)))
@IBOutlet weak var filterButton: UIBarButtonItem! @IBOutlet weak var filterButton: UIBarButtonItem!
@IBOutlet weak var markAllAsReadButton: UIBarButtonItem! @IBOutlet weak var markAllAsReadButton: UIBarButtonItem!
@ -69,6 +69,10 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
iconSize = AppDefaults.timelineIconSize iconSize = AppDefaults.timelineIconSize
resetEstimatedRowHeight() resetEstimatedRowHeight()
if let titleView = Bundle.main.loadNibNamed("MasterTimelineTitleView", owner: self, options: nil)?[0] as? MasterTimelineTitleView {
navigationItem.titleView = titleView
}
resetUI() resetUI()
applyChanges(animated: false) applyChanges(animated: false)
@ -358,7 +362,11 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
} }
@objc func webFeedIconDidBecomeAvailable(_ note: Notification) { @objc func webFeedIconDidBecomeAvailable(_ note: Notification) {
titleView?.iconView.iconImage = coordinator.timelineIconImage
if let titleView = navigationItem.titleView as? MasterTimelineTitleView {
titleView.iconView.iconImage = coordinator.timelineIconImage
}
guard let feed = note.userInfo?[UserInfoKey.webFeed] as? WebFeed else { guard let feed = note.userInfo?[UserInfoKey.webFeed] as? WebFeed else {
return return
} }
@ -389,7 +397,9 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
} }
@objc func faviconDidBecomeAvailable(_ note: Notification) { @objc func faviconDidBecomeAvailable(_ note: Notification) {
titleView?.iconView.iconImage = coordinator.timelineIconImage if let titleView = navigationItem.titleView as? MasterTimelineTitleView {
titleView.iconView.iconImage = coordinator.timelineIconImage
}
if coordinator.showIcons { if coordinator.showIcons {
queueReloadAvailableCells() queueReloadAvailableCells()
} }
@ -409,7 +419,9 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
} }
@objc func displayNameDidChange(_ note: Notification) { @objc func displayNameDidChange(_ note: Notification) {
titleView?.label.text = coordinator.timelineFeed?.nameForDisplay if let titleView = navigationItem.titleView as? MasterTimelineTitleView {
titleView.label.text = coordinator.timelineFeed?.nameForDisplay
}
} }
@objc func scrollPositionDidChange() { @objc func scrollPositionDidChange() {
@ -497,17 +509,16 @@ private extension MasterTimelineViewController {
func resetUI() { func resetUI() {
if let titleView = Bundle.main.loadNibNamed("MasterTimelineTitleView", owner: self, options: nil)?[0] as? MasterTimelineTitleView { if let titleView = navigationItem.titleView as? MasterTimelineTitleView {
self.titleView = titleView
titleView.iconView.iconImage = coordinator.timelineIconImage titleView.iconView.iconImage = coordinator.timelineIconImage
titleView.label.text = coordinator.timelineFeed?.nameForDisplay titleView.label.text = coordinator.timelineFeed?.nameForDisplay
updateTitleUnreadCount() updateTitleUnreadCount()
if coordinator.timelineFeed is WebFeed { if coordinator.timelineFeed is WebFeed {
titleView.heightAnchor.constraint(equalToConstant: 44.0).isActive = true titleView.heightAnchor.constraint(equalToConstant: 44.0).isActive = true
let tap = UITapGestureRecognizer(target: self, action:#selector(showFeedInspector(_:))) titleView.addGestureRecognizer(feedTapGestureRecognizer)
titleView.addGestureRecognizer(tap) } else {
titleView.removeGestureRecognizer(feedTapGestureRecognizer)
} }
navigationItem.titleView = titleView navigationItem.titleView = titleView
@ -544,7 +555,9 @@ private extension MasterTimelineViewController {
} }
func updateTitleUnreadCount() { func updateTitleUnreadCount() {
self.titleView?.unreadCountView.unreadCount = coordinator.unreadCount if let titleView = navigationItem.titleView as? MasterTimelineTitleView {
titleView.unreadCountView.unreadCount = coordinator.unreadCount
}
} }
func applyChanges(animated: Bool, completion: (() -> Void)? = nil) { func applyChanges(animated: Bool, completion: (() -> Void)? = nil) {