diff --git a/Extensions/NSMutableAttributedString+Extensions.swift b/Extensions/NSMutableAttributedString+Extensions.swift index 1800a96..57d320e 100644 --- a/Extensions/NSMutableAttributedString+Extensions.swift +++ b/Extensions/NSMutableAttributedString+Extensions.swift @@ -4,22 +4,15 @@ import UIKit import Kingfisher extension NSMutableAttributedString { - func insert(emojis: [Emoji], onImageLoad: @escaping (() -> Void)) { - for emoji in emojis { + func insert(emoji: [Emoji], view: UIView) { + for emoji in emoji { let token = ":\(emoji.shortcode):" while let tokenRange = string.range(of: token) { let attachment = NSTextAttachment() - let attachmentAttributedString = NSAttributedString(attachment: attachment) - replaceCharacters(in: NSRange(tokenRange, in: string), with: attachmentAttributedString) - - KingfisherManager.shared.retrieveImage(with: emoji.url) { - guard case let .success(value) = $0 else { return } - - attachment.image = value.image - onImageLoad() - } + attachment.kf.setImage(with: emoji.url, attributedView: view) + replaceCharacters(in: NSRange(tokenRange, in: string), with: NSAttributedString(attachment: attachment)) } } } diff --git a/Metatext.xcodeproj/project.pbxproj b/Metatext.xcodeproj/project.pbxproj index 51628b8..e64105a 100644 --- a/Metatext.xcodeproj/project.pbxproj +++ b/Metatext.xcodeproj/project.pbxproj @@ -1290,7 +1290,7 @@ repositoryURL = "https://github.com/onevcat/Kingfisher"; requirement = { kind = upToNextMajorVersion; - minimumVersion = 5.14.1; + minimumVersion = 5.15.0; }; }; D0DC175D24D016EA00A75C65 /* XCRemoteSwiftPackageReference "Alamofire" */ = { diff --git a/Metatext.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Metatext.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index c91bb53..5e51db3 100644 --- a/Metatext.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Metatext.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -33,8 +33,8 @@ "repositoryURL": "https://github.com/onevcat/Kingfisher", "state": { "branch": null, - "revision": "1339ebea9498ef6c3fc75cc195d7163d7c7167f9", - "version": "5.14.1" + "revision": "175eeb4618b0a6ef4d69a7409b6a74ddd235a093", + "version": "5.15.0" } } ] diff --git a/Views/CustomEmojiText.swift b/Views/CustomEmojiText.swift index 75f268e..370aa66 100644 --- a/Views/CustomEmojiText.swift +++ b/Views/CustomEmojiText.swift @@ -17,7 +17,7 @@ struct CustomEmojiText: UIViewRepresentable { let label = UILabel() label.font = UIFont.preferredFont(forTextStyle: textStyle) - attributedText.insert(emojis: emoji, onImageLoad: { label.setNeedsDisplay() }) + attributedText.insert(emoji: emoji, view: label) attributedText.resizeAttachments(toLineHeight: label.font.lineHeight) label.attributedText = attributedText diff --git a/Views/StatusTableViewCell.swift b/Views/StatusTableViewCell.swift index 098d9bc..fcf53c1 100644 --- a/Views/StatusTableViewCell.swift +++ b/Views/StatusTableViewCell.swift @@ -94,18 +94,14 @@ class StatusTableViewCell: UITableViewCell { [.font: contentFont as Any, .foregroundColor: UIColor.label], range: contentRange) - mutableContent.insert(emojis: viewModel.contentEmoji) { [weak self] in - self?.contentTextView.setNeedsDisplay() - } + mutableContent.insert(emoji: viewModel.contentEmoji, view: contentTextView) mutableContent.resizeAttachments(toLineHeight: contentFont.lineHeight) contentTextView.attributedText = mutableContent contentTextView.isHidden = contentTextView.text == "" - mutableDisplayName.insert(emojis: viewModel.displayNameEmoji) { displayNameLabel.setNeedsDisplay() } + mutableDisplayName.insert(emoji: viewModel.displayNameEmoji, view: displayNameLabel) mutableDisplayName.resizeAttachments(toLineHeight: displayNameLabel.font.lineHeight) displayNameLabel.attributedText = mutableDisplayName - mutableSpoilerText.insert(emojis: viewModel.contentEmoji) { [weak self] in - self?.spoilerTextLabel.setNeedsDisplay() - } + mutableSpoilerText.insert(emoji: viewModel.contentEmoji, view: spoilerTextLabel) mutableSpoilerText.resizeAttachments(toLineHeight: spoilerTextLabel.font.lineHeight) spoilerTextLabel.attributedText = mutableSpoilerText spoilerTextLabel.isHidden = !viewModel.sensitive || spoilerTextLabel.text == "" @@ -156,9 +152,7 @@ class StatusTableViewCell: UITableViewCell { NSLocalizedString("status.reblogged-by", comment: ""), viewModel.rebloggedByDisplayName) let mutableMetaText = NSMutableAttributedString(string: metaText) - mutableMetaText.insert(emojis: viewModel.rebloggedByDisplayNameEmoji) { [weak self] in - self?.metaLabel.setNeedsDisplay() - } + mutableMetaText.insert(emoji: viewModel.rebloggedByDisplayNameEmoji, view: metaLabel) mutableMetaText.resizeAttachments(toLineHeight: metaLabel.font.lineHeight) metaLabel.attributedText = mutableMetaText metaIcon.image = UIImage(