From 53561896541cfa3136dc989a8849568d920b88e8 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 16 Jun 2020 08:32:01 -0500 Subject: [PATCH 1/3] Optimize unread count look up --- iOS/SceneCoordinator.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index ed1ae50e2..e60437e98 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -626,7 +626,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { func unreadCountFor(_ node: Node) -> Int { // The coordinator supplies the unread count for the currently selected feed - if let feed = timelineFeed, let selectedNode = rootNode.descendantNodeRepresentingObject(feed as AnyObject), selectedNode == node { + if node.representedObject === timelineFeed as AnyObject { return unreadCount } if let unreadCountProvider = node.representedObject as? UnreadCountProvider { From b3c0fac5d37c880b8020cb133085b9e516fdcb61 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 18 Jun 2020 16:16:30 -0500 Subject: [PATCH 2/3] Save the previous feed instead of relying on the currentFeedIndexPath which may have been reset. Issue #2139 --- iOS/SceneCoordinator.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index e60437e98..6a4430469 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -70,11 +70,14 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { private var expandedTable = Set() private var readFilterEnabledTable = [FeedIdentifier: Bool]() private var shadowTable = [[Node]]() + + private(set) var preSearchTimelineFeed: Feed? private var lastSearchString = "" private var lastSearchScope: SearchScope? = nil private var isSearching: Bool = false private var savedSearchArticles: ArticleArray? = nil private var savedSearchArticleIds: Set? = nil + var isTimelineViewControllerPending = false var isArticleViewControllerPending = false @@ -830,6 +833,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { func beginSearching() { isSearching = true + preSearchTimelineFeed = timelineFeed savedSearchArticles = articles savedSearchArticleIds = Set(articles.map { $0.articleID }) setTimelineFeed(nil, animated: true) @@ -837,9 +841,9 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } func endSearching() { - if let ip = currentFeedIndexPath, let node = nodeFor(ip), let feed = node.representedObject as? Feed { + if let oldTimelineFeed = preSearchTimelineFeed { emptyTheTimeline() - timelineFeed = feed + timelineFeed = oldTimelineFeed masterTimelineViewController?.reinitializeArticles(resetScroll: true) replaceArticles(with: savedSearchArticles!, animated: true) } else { @@ -848,6 +852,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { lastSearchString = "" lastSearchScope = nil + preSearchTimelineFeed = nil savedSearchArticleIds = nil savedSearchArticles = nil isSearching = false From d453a9433089acbc09d76375fea38f44444d0c0d Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 18 Jun 2020 17:37:29 -0500 Subject: [PATCH 3/3] Make unread and star animations cancel on cell reuse. Issue #2054 --- .../Cell/MasterTimelineTableViewCell.swift | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift b/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift index aa964b218..55183f29b 100644 --- a/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift +++ b/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift @@ -23,6 +23,9 @@ class MasterTimelineTableViewCell: VibrantTableViewCell { return NonIntrinsicImageView(image: AppAssets.timelineStarImage) }() + private var unreadIndicatorPropertyAnimator: UIViewPropertyAnimator? + private var starViewPropertyAnimator: UIViewPropertyAnimator? + var cellData: MasterTimelineCellData! { didSet { updateSubviews() @@ -35,7 +38,12 @@ class MasterTimelineTableViewCell: VibrantTableViewCell { } override func prepareForReuse() { + unreadIndicatorPropertyAnimator?.stopAnimation(true) + unreadIndicatorPropertyAnimator = nil unreadIndicatorView.isHidden = true + + starViewPropertyAnimator?.stopAnimation(true) + starViewPropertyAnimator = nil starView.isHidden = true } @@ -184,10 +192,15 @@ private extension MasterTimelineTableViewCell { func updateUnreadIndicator() { if !unreadIndicatorView.isHidden && cellData.read && !cellData.starred { - UIView.animate(withDuration: 0.66, animations: { self.unreadIndicatorView.alpha = 0 }) { _ in - self.unreadIndicatorView.isHidden = true - self.unreadIndicatorView.alpha = 1 + unreadIndicatorPropertyAnimator = UIViewPropertyAnimator(duration: 0.66, curve: .easeInOut) { [weak self] in + self?.unreadIndicatorView.alpha = 0 } + unreadIndicatorPropertyAnimator?.addCompletion { [weak self] _ in + self?.unreadIndicatorView.isHidden = true + self?.unreadIndicatorView.alpha = 1 + self?.unreadIndicatorPropertyAnimator = nil + } + unreadIndicatorPropertyAnimator?.startAnimation() } else { showOrHideView(unreadIndicatorView, cellData.read || cellData.starred) } @@ -195,10 +208,15 @@ private extension MasterTimelineTableViewCell { func updateStarView() { if !starView.isHidden && cellData.read && !cellData.starred { - UIView.animate(withDuration: 0.66, animations: { self.starView.alpha = 0 }) { _ in - self.starView.isHidden = true - self.starView.alpha = 1 + starViewPropertyAnimator = UIViewPropertyAnimator(duration: 0.66, curve: .easeInOut) { [weak self] in + self?.starView.alpha = 0 } + starViewPropertyAnimator?.addCompletion { [weak self] _ in + self?.starView.isHidden = true + self?.starView.alpha = 1 + self?.starViewPropertyAnimator = nil + } + starViewPropertyAnimator?.startAnimation() } else { showOrHideView(starView, !cellData.starred) }