Don't try to re-replace emojis unnecessarily

This commit is contained in:
Shadowfacts 2020-12-29 11:56:40 -05:00
parent 41403c84f9
commit a7b2a7df71
4 changed files with 16 additions and 2 deletions

View File

@ -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<String, UIImage>(name: "ContentTextView Emoji Images")

View File

@ -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
}
}

View File

@ -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 {
}
}
if contentTextView.hasEmojis {
contentTextView.setTextFrom(status: status)
}
displayNameLabel.updateForAccountDisplayName(account: account)
}

View File

@ -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)
}