Fix flickering that happens when unread counts come in to fast

This commit is contained in:
Maurice Parker 2021-10-24 12:45:45 -05:00
parent 5f4409ca1f
commit 877391ec6b

View File

@ -45,6 +45,8 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
return true return true
} }
private var reloadCoalescingQueue = CoalescingQueue(name: "Reload Visible", interval: 0.5)
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
@ -113,16 +115,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
return return
} }
var node: Node? = nil queueReloadAllVisible()
if let coordinator = representedObject as? SceneCoordinator, let feed = coordinator.timelineFeed {
node = coordinator.rootNode.descendantNodeRepresentingObject(feed as AnyObject)
} else {
node = coordinator.rootNode.descendantNodeRepresentingObject(representedObject as AnyObject)
}
guard let unreadCountNode = node, let indexPath = coordinator.indexPathFor(unreadCountNode) else { return }
tableView.reloadRows(at: [indexPath], with: .none)
restoreSelectionIfNecessary(adjustScroll: false)
} }
@objc func faviconDidBecomeAvailable(_ note: Notification) { @objc func faviconDidBecomeAvailable(_ note: Notification) {
@ -840,6 +833,14 @@ private extension MasterFeedViewController {
return "" return ""
} }
func queueReloadAllVisible() {
reloadCoalescingQueue.add(self, #selector(reloadQueuedAllVisible))
}
@objc func reloadQueuedAllVisible() {
reloadAllVisibleCells()
}
func configureCellsForRepresentedObject(_ representedObject: AnyObject) { func configureCellsForRepresentedObject(_ representedObject: AnyObject) {
applyToCellsForRepresentedObject(representedObject, configure) applyToCellsForRepresentedObject(representedObject, configure)
} }