mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-24 17:20:59 +00:00
Update Kingfisher
This commit is contained in:
parent
108415512f
commit
ba986f9751
5 changed files with 12 additions and 25 deletions
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1290,7 +1290,7 @@
|
|||
repositoryURL = "https://github.com/onevcat/Kingfisher";
|
||||
requirement = {
|
||||
kind = upToNextMajorVersion;
|
||||
minimumVersion = 5.14.1;
|
||||
minimumVersion = 5.15.0;
|
||||
};
|
||||
};
|
||||
D0DC175D24D016EA00A75C65 /* XCRemoteSwiftPackageReference "Alamofire" */ = {
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue