From de8e448f0a84970a9dad90edd2fd0ea5e29b1d50 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Mon, 7 Nov 2022 02:48:58 -0600 Subject: [PATCH] Respond to sidebar Feed name updates --- iOS/MasterFeed/MasterFeedViewController.swift | 14 ++++++++++++++ iOS/SceneCoordinator.swift | 14 +++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index f8307cf20..62c594872 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -71,6 +71,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner, Ma NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(configureContextMenu(_:)), name: .ActiveExtensionPointsDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil) refreshControl = UIRefreshControl() refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged) @@ -139,6 +140,13 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner, Ma } } + @objc func displayNameDidChange(_ note: Notification) { + guard let object = note.object as? AnyObject else { + return + } + reloadCell(for: object) + } + @objc func contentSizeCategoryDidChange(_ note: Notification) { resetEstimatedRowHeight() tableView.reloadData() @@ -831,6 +839,12 @@ private extension MasterFeedViewController { completion(cell as! MasterFeedTableViewCell, indexPath) } } + + private func reloadCell(for object: AnyObject) { + guard let indexPath = coordinator.indexPathFor(object) else { return } + tableView.reloadRows(at: [indexPath], with: .none) + restoreSelectionIfNecessary(adjustScroll: false) + } private func reloadAllVisibleCells(completion: (() -> Void)? = nil) { guard let indexPaths = tableView.indexPathsForVisibleRows else { return } diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index c5a227042..a251350fd 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -619,6 +619,13 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, Logging { return shadowTable[indexPath.section].feedNodes[indexPath.row].node } + func indexPathFor(_ object: AnyObject) -> IndexPath? { + guard let node = treeController.rootNode.descendantNodeRepresentingObject(object) else { + return nil + } + return indexPathFor(node) + } + func indexPathFor(_ node: Node) -> IndexPath? { for i in 0.. IndexPath? { - guard let node = treeController.rootNode.descendantNodeRepresentingObject(object) else { - return nil - } - return indexPathFor(node) - } - func setTimelineFeed(_ feed: Feed?, animated: Bool, completion: (() -> Void)? = nil) { timelineFeed = feed