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

@ -44,6 +44,8 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
override var canBecomeFirstResponder: Bool {
return true
}
private var reloadCoalescingQueue = CoalescingQueue(name: "Reload Visible", interval: 0.5)
override func viewDidLoad() {
@ -113,16 +115,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
return
}
var node: Node? = nil
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)
queueReloadAllVisible()
}
@objc func faviconDidBecomeAvailable(_ note: Notification) {
@ -840,6 +833,14 @@ private extension MasterFeedViewController {
return ""
}
func queueReloadAllVisible() {
reloadCoalescingQueue.add(self, #selector(reloadQueuedAllVisible))
}
@objc func reloadQueuedAllVisible() {
reloadAllVisibleCells()
}
func configureCellsForRepresentedObject(_ representedObject: AnyObject) {
applyToCellsForRepresentedObject(representedObject, configure)
}