Don't try to re-replace emojis unnecessarily
This commit is contained in:
parent
41403c84f9
commit
a7b2a7df71
|
@ -22,6 +22,8 @@ class ContentTextView: LinkTextView {
|
||||||
var defaultFont: UIFont = .systemFont(ofSize: 17)
|
var defaultFont: UIFont = .systemFont(ofSize: 17)
|
||||||
var defaultColor: UIColor = .label
|
var defaultColor: UIColor = .label
|
||||||
|
|
||||||
|
private(set) var hasEmojis = false
|
||||||
|
|
||||||
// The link range currently being previewed
|
// The link range currently being previewed
|
||||||
private var currentPreviewedLinkRange: NSRange?
|
private var currentPreviewedLinkRange: NSRange?
|
||||||
// The preview created in the previewForHighlighting method, so that we can use the same one in previewForDismissing.
|
// 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
|
// MARK: - Emojis
|
||||||
func setEmojis(_ emojis: [Emoji]) {
|
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")
|
let emojiImages = MultiThreadDictionary<String, UIImage>(name: "ContentTextView Emoji Images")
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ import Pachyderm
|
||||||
|
|
||||||
class EmojiLabel: UILabel, BaseEmojiLabel {
|
class EmojiLabel: UILabel, BaseEmojiLabel {
|
||||||
|
|
||||||
|
private(set) var hasEmojis = false
|
||||||
|
|
||||||
var emojiIdentifier: String?
|
var emojiIdentifier: String?
|
||||||
var emojiRequests: [ImageCache.Request] = []
|
var emojiRequests: [ImageCache.Request] = []
|
||||||
var emojiFont: UIFont { font }
|
var emojiFont: UIFont { font }
|
||||||
|
@ -22,6 +24,7 @@ class EmojiLabel: UILabel, BaseEmojiLabel {
|
||||||
self.emojiIdentifier = identifier
|
self.emojiIdentifier = identifier
|
||||||
emojiRequests.forEach { $0.cancel() }
|
emojiRequests.forEach { $0.cancel() }
|
||||||
emojiRequests = []
|
emojiRequests = []
|
||||||
|
hasEmojis = true
|
||||||
|
|
||||||
replaceEmojis(in: attributedText.string, emojis: emojis, identifier: identifier) { [weak self] (newAttributedText) in
|
replaceEmojis(in: attributedText.string, emojis: emojis, identifier: identifier) { [weak self] (newAttributedText) in
|
||||||
guard let self = self, self.emojiIdentifier == identifier else { return }
|
guard let self = self, self.emojiIdentifier == identifier else { return }
|
||||||
|
@ -35,6 +38,7 @@ class EmojiLabel: UILabel, BaseEmojiLabel {
|
||||||
emojiIdentifier = nil
|
emojiIdentifier = nil
|
||||||
emojiRequests.forEach { $0.cancel() }
|
emojiRequests.forEach { $0.cancel() }
|
||||||
emojiRequests = []
|
emojiRequests = []
|
||||||
|
hasEmojis = false
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,6 +147,7 @@ class BaseStatusTableViewCell: UITableViewCell {
|
||||||
let account = status.account
|
let account = status.account
|
||||||
self.accountID = account.id
|
self.accountID = account.id
|
||||||
updateUI(account: account)
|
updateUI(account: account)
|
||||||
|
contentTextView.setTextFrom(status: status)
|
||||||
updateGrayscaleableUI(account: account, status: status)
|
updateGrayscaleableUI(account: account, status: status)
|
||||||
updateUIForPreferences(account: account, status: status)
|
updateUIForPreferences(account: account, status: status)
|
||||||
|
|
||||||
|
@ -274,7 +275,9 @@ class BaseStatusTableViewCell: UITableViewCell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if contentTextView.hasEmojis {
|
||||||
contentTextView.setTextFrom(status: status)
|
contentTextView.setTextFrom(status: status)
|
||||||
|
}
|
||||||
|
|
||||||
displayNameLabel.updateForAccountDisplayName(account: account)
|
displayNameLabel.updateForAccountDisplayName(account: account)
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,7 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
|
||||||
super.updateGrayscaleableUI(account: account, status: status)
|
super.updateGrayscaleableUI(account: account, status: status)
|
||||||
|
|
||||||
if let rebloggerID = rebloggerID,
|
if let rebloggerID = rebloggerID,
|
||||||
|
reblogLabel.hasEmojis,
|
||||||
let reblogger = mastodonController.persistentContainer.account(for: rebloggerID) {
|
let reblogger = mastodonController.persistentContainer.account(for: rebloggerID) {
|
||||||
updateRebloggerLabel(reblogger: reblogger)
|
updateRebloggerLabel(reblogger: reblogger)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue