From 89e899c5d717ce68f26caa1dd40d79828a61c573 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 13 Nov 2021 11:06:17 -0600 Subject: [PATCH] Directly set the unread count on the cell instead of doing a full reload to get rid of unread count flickering --- iOS/MasterFeed/MasterFeedViewController.swift | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 5322f63d3..6e2964c2d 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -99,11 +99,11 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { @objc func unreadCountDidChange(_ note: Notification) { updateUI() - guard let representedObject = note.object else { + guard let unreadCountProvider = note.object as? UnreadCountProvider else { return } - if let account = representedObject as? Account { + if let account = unreadCountProvider as? Account { if let node = coordinator.rootNode.childNodeRepresentingObject(account) { let sectionIndex = coordinator.rootNode.indexOfChild(node)! if let headerView = tableView.headerView(forSection: sectionIndex) as? MasterFeedTableViewSectionHeader { @@ -114,15 +114,16 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { } var node: Node? = nil - if let coordinator = representedObject as? SceneCoordinator, let feed = coordinator.timelineFeed { + if let coordinator = unreadCountProvider as? SceneCoordinator, let feed = coordinator.timelineFeed { node = coordinator.rootNode.descendantNodeRepresentingObject(feed as AnyObject) } else { - node = coordinator.rootNode.descendantNodeRepresentingObject(representedObject as AnyObject) + node = coordinator.rootNode.descendantNodeRepresentingObject(unreadCountProvider as AnyObject) } guard let unreadCountNode = node, let indexPath = coordinator.indexPathFor(unreadCountNode) else { return } - tableView.reloadRows(at: [indexPath], with: .none) - restoreSelectionIfNecessary(adjustScroll: false) + if let cell = tableView.cellForRow(at: indexPath) as? MasterFeedTableViewCell { + cell.unreadCount = unreadCountProvider.unreadCount + } } @objc func faviconDidBecomeAvailable(_ note: Notification) {