Update Kingfisher

This commit is contained in:
Justin Mazzocchi 2020-08-26 22:10:31 -07:00
parent 108415512f
commit ba986f9751
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
5 changed files with 12 additions and 25 deletions

View file

@ -4,22 +4,15 @@ import UIKit
import Kingfisher import Kingfisher
extension NSMutableAttributedString { extension NSMutableAttributedString {
func insert(emojis: [Emoji], onImageLoad: @escaping (() -> Void)) { func insert(emoji: [Emoji], view: UIView) {
for emoji in emojis { for emoji in emoji {
let token = ":\(emoji.shortcode):" let token = ":\(emoji.shortcode):"
while let tokenRange = string.range(of: token) { while let tokenRange = string.range(of: token) {
let attachment = NSTextAttachment() let attachment = NSTextAttachment()
let attachmentAttributedString = NSAttributedString(attachment: attachment)
replaceCharacters(in: NSRange(tokenRange, in: string), with: attachmentAttributedString) attachment.kf.setImage(with: emoji.url, attributedView: view)
replaceCharacters(in: NSRange(tokenRange, in: string), with: NSAttributedString(attachment: attachment))
KingfisherManager.shared.retrieveImage(with: emoji.url) {
guard case let .success(value) = $0 else { return }
attachment.image = value.image
onImageLoad()
}
} }
} }
} }

View file

@ -1290,7 +1290,7 @@
repositoryURL = "https://github.com/onevcat/Kingfisher"; repositoryURL = "https://github.com/onevcat/Kingfisher";
requirement = { requirement = {
kind = upToNextMajorVersion; kind = upToNextMajorVersion;
minimumVersion = 5.14.1; minimumVersion = 5.15.0;
}; };
}; };
D0DC175D24D016EA00A75C65 /* XCRemoteSwiftPackageReference "Alamofire" */ = { D0DC175D24D016EA00A75C65 /* XCRemoteSwiftPackageReference "Alamofire" */ = {

View file

@ -33,8 +33,8 @@
"repositoryURL": "https://github.com/onevcat/Kingfisher", "repositoryURL": "https://github.com/onevcat/Kingfisher",
"state": { "state": {
"branch": null, "branch": null,
"revision": "1339ebea9498ef6c3fc75cc195d7163d7c7167f9", "revision": "175eeb4618b0a6ef4d69a7409b6a74ddd235a093",
"version": "5.14.1" "version": "5.15.0"
} }
} }
] ]

View file

@ -17,7 +17,7 @@ struct CustomEmojiText: UIViewRepresentable {
let label = UILabel() let label = UILabel()
label.font = UIFont.preferredFont(forTextStyle: textStyle) 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) attributedText.resizeAttachments(toLineHeight: label.font.lineHeight)
label.attributedText = attributedText label.attributedText = attributedText

View file

@ -94,18 +94,14 @@ class StatusTableViewCell: UITableViewCell {
[.font: contentFont as Any, [.font: contentFont as Any,
.foregroundColor: UIColor.label], .foregroundColor: UIColor.label],
range: contentRange) range: contentRange)
mutableContent.insert(emojis: viewModel.contentEmoji) { [weak self] in mutableContent.insert(emoji: viewModel.contentEmoji, view: contentTextView)
self?.contentTextView.setNeedsDisplay()
}
mutableContent.resizeAttachments(toLineHeight: contentFont.lineHeight) mutableContent.resizeAttachments(toLineHeight: contentFont.lineHeight)
contentTextView.attributedText = mutableContent contentTextView.attributedText = mutableContent
contentTextView.isHidden = contentTextView.text == "" contentTextView.isHidden = contentTextView.text == ""
mutableDisplayName.insert(emojis: viewModel.displayNameEmoji) { displayNameLabel.setNeedsDisplay() } mutableDisplayName.insert(emoji: viewModel.displayNameEmoji, view: displayNameLabel)
mutableDisplayName.resizeAttachments(toLineHeight: displayNameLabel.font.lineHeight) mutableDisplayName.resizeAttachments(toLineHeight: displayNameLabel.font.lineHeight)
displayNameLabel.attributedText = mutableDisplayName displayNameLabel.attributedText = mutableDisplayName
mutableSpoilerText.insert(emojis: viewModel.contentEmoji) { [weak self] in mutableSpoilerText.insert(emoji: viewModel.contentEmoji, view: spoilerTextLabel)
self?.spoilerTextLabel.setNeedsDisplay()
}
mutableSpoilerText.resizeAttachments(toLineHeight: spoilerTextLabel.font.lineHeight) mutableSpoilerText.resizeAttachments(toLineHeight: spoilerTextLabel.font.lineHeight)
spoilerTextLabel.attributedText = mutableSpoilerText spoilerTextLabel.attributedText = mutableSpoilerText
spoilerTextLabel.isHidden = !viewModel.sensitive || spoilerTextLabel.text == "" spoilerTextLabel.isHidden = !viewModel.sensitive || spoilerTextLabel.text == ""
@ -156,9 +152,7 @@ class StatusTableViewCell: UITableViewCell {
NSLocalizedString("status.reblogged-by", comment: ""), NSLocalizedString("status.reblogged-by", comment: ""),
viewModel.rebloggedByDisplayName) viewModel.rebloggedByDisplayName)
let mutableMetaText = NSMutableAttributedString(string: metaText) let mutableMetaText = NSMutableAttributedString(string: metaText)
mutableMetaText.insert(emojis: viewModel.rebloggedByDisplayNameEmoji) { [weak self] in mutableMetaText.insert(emoji: viewModel.rebloggedByDisplayNameEmoji, view: metaLabel)
self?.metaLabel.setNeedsDisplay()
}
mutableMetaText.resizeAttachments(toLineHeight: metaLabel.font.lineHeight) mutableMetaText.resizeAttachments(toLineHeight: metaLabel.font.lineHeight)
metaLabel.attributedText = mutableMetaText metaLabel.attributedText = mutableMetaText
metaIcon.image = UIImage( metaIcon.image = UIImage(