From a7b2a7df71d322f73eadd5d423592610607b802c Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 29 Dec 2020 11:56:40 -0500 Subject: [PATCH] Don't try to re-replace emojis unnecessarily --- Tusker/Views/ContentTextView.swift | 8 +++++++- Tusker/Views/EmojiLabel.swift | 4 ++++ Tusker/Views/Status/BaseStatusTableViewCell.swift | 5 ++++- Tusker/Views/Status/TimelineStatusTableViewCell.swift | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Tusker/Views/ContentTextView.swift b/Tusker/Views/ContentTextView.swift index 42e83cab..0777b83a 100644 --- a/Tusker/Views/ContentTextView.swift +++ b/Tusker/Views/ContentTextView.swift @@ -22,6 +22,8 @@ class ContentTextView: LinkTextView { var defaultFont: UIFont = .systemFont(ofSize: 17) var defaultColor: UIColor = .label + private(set) var hasEmojis = false + // The link range currently being previewed private var currentPreviewedLinkRange: NSRange? // The preview created in the previewForHighlighting method, so that we can use the same one in previewForDismissing. @@ -49,7 +51,11 @@ class ContentTextView: LinkTextView { // MARK: - Emojis func setEmojis(_ emojis: [Emoji]) { - guard !emojis.isEmpty else { return } + guard !emojis.isEmpty else { + hasEmojis = false + return + } + hasEmojis = true let emojiImages = MultiThreadDictionary(name: "ContentTextView Emoji Images") diff --git a/Tusker/Views/EmojiLabel.swift b/Tusker/Views/EmojiLabel.swift index 04944ca2..f7e7e690 100644 --- a/Tusker/Views/EmojiLabel.swift +++ b/Tusker/Views/EmojiLabel.swift @@ -11,6 +11,8 @@ import Pachyderm class EmojiLabel: UILabel, BaseEmojiLabel { + private(set) var hasEmojis = false + var emojiIdentifier: String? var emojiRequests: [ImageCache.Request] = [] var emojiFont: UIFont { font } @@ -22,6 +24,7 @@ class EmojiLabel: UILabel, BaseEmojiLabel { self.emojiIdentifier = identifier emojiRequests.forEach { $0.cancel() } emojiRequests = [] + hasEmojis = true replaceEmojis(in: attributedText.string, emojis: emojis, identifier: identifier) { [weak self] (newAttributedText) in guard let self = self, self.emojiIdentifier == identifier else { return } @@ -35,6 +38,7 @@ class EmojiLabel: UILabel, BaseEmojiLabel { emojiIdentifier = nil emojiRequests.forEach { $0.cancel() } emojiRequests = [] + hasEmojis = false } } diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 6438ca66..7e7af319 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -147,6 +147,7 @@ class BaseStatusTableViewCell: UITableViewCell { let account = status.account self.accountID = account.id updateUI(account: account) + contentTextView.setTextFrom(status: status) updateGrayscaleableUI(account: account, status: status) updateUIForPreferences(account: account, status: status) @@ -274,7 +275,9 @@ class BaseStatusTableViewCell: UITableViewCell { } } - contentTextView.setTextFrom(status: status) + if contentTextView.hasEmojis { + contentTextView.setTextFrom(status: status) + } displayNameLabel.updateForAccountDisplayName(account: account) } diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.swift b/Tusker/Views/Status/TimelineStatusTableViewCell.swift index 91d81623..de214453 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.swift @@ -98,6 +98,7 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { super.updateGrayscaleableUI(account: account, status: status) if let rebloggerID = rebloggerID, + reblogLabel.hasEmojis, let reblogger = mastodonController.persistentContainer.account(for: rebloggerID) { updateRebloggerLabel(reblogger: reblogger) }