fix: auto completion title label not display custom emoji issue

This commit is contained in:
CMK 2021-08-04 15:47:29 +08:00
parent 0186be609f
commit 9a8653f39c
4 changed files with 30 additions and 12 deletions

View File

@ -7,6 +7,7 @@
import UIKit
import MastodonSDK
import MastodonMeta
enum AutoCompleteSection: Equatable, Hashable {
case main
@ -48,7 +49,8 @@ extension AutoCompleteSection {
extension AutoCompleteSection {
private static func configureHashtag(cell: AutoCompleteTableViewCell, hashtag: Mastodon.Entity.Tag) {
cell.titleLabel.text = "#" + hashtag.name
let metaContent = PlaintextMetaContent(string: "#" + hashtag.name)
cell.titleLabel.configure(content: metaContent)
cell.subtitleLabel.text = {
let count = (hashtag.history ?? [])
.sorted(by: { $0.day > $1.day })
@ -61,23 +63,29 @@ extension AutoCompleteSection {
}
private static func configureHashtag(cell: AutoCompleteTableViewCell, hashtagName: String) {
cell.titleLabel.text = "#" + hashtagName
let metaContent = PlaintextMetaContent(string: "#" + hashtagName)
cell.titleLabel.configure(content: metaContent)
cell.subtitleLabel.text = " "
cell.avatarImageView.isHidden = true
}
private static func configureAccount(cell: AutoCompleteTableViewCell, account: Mastodon.Entity.Account) {
cell.titleLabel.text = {
guard !account.displayName.isEmpty else { return account.username }
return account.displayName
}()
let mastodonContent = MastodonContent(content: account.displayNameWithFallback, emojis: account.emojiMeta)
do {
let metaContent = try MastodonMetaContent.convert(document: mastodonContent)
cell.titleLabel.configure(content: metaContent)
} catch {
let metaContent = PlaintextMetaContent(string: account.displayNameWithFallback)
cell.titleLabel.configure(content: metaContent)
}
cell.subtitleLabel.text = "@" + account.acct
cell.avatarImageView.isHidden = false
cell.configure(with: AvatarConfigurableViewConfiguration(avatarImageURL: URL(string: account.avatar)))
}
private static func configureEmoji(cell: AutoCompleteTableViewCell, emoji: Mastodon.Entity.Emoji, isFirst: Bool) {
cell.titleLabel.text = ":" + emoji.shortcode + ":"
let metaContent = PlaintextMetaContent(string: ":" + emoji.shortcode + ":")
cell.titleLabel.configure(content: metaContent)
// FIXME: handle spacer enter to complete emoji
// cell.subtitleLabel.text = isFirst ? L10n.Scene.Compose.AutoComplete.spaceToAdd : " "
cell.subtitleLabel.text = " "

View File

@ -19,6 +19,14 @@ extension Mastodon.Entity.Account: Hashable {
}
}
extension Mastodon.Entity.Account {
var displayNameWithFallback: String {
return !displayName.isEmpty ? displayName : username
}
}
extension Mastodon.Entity.Account {
public func avatarImageURL() -> URL? {
let string = UserDefaults.shared.preferredStaticAvatar ? avatarStatic ?? avatar : avatar

View File

@ -19,6 +19,7 @@ extension MetaLabel {
case recommendAccountName
case titleView
case settingTableFooter
case autoCompletion
}
convenience init(style: Style) {
@ -70,6 +71,9 @@ extension MetaLabel {
numberOfLines = 0
textContainer.maximumNumberOfLines = 0
paragraphStyle.alignment = .center
case .autoCompletion:
font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 22)
textColor = Asset.Colors.brandBlue.color
}
self.font = font

View File

@ -7,6 +7,7 @@
import UIKit
import FLAnimatedImage
import MetaTextKit
final class AutoCompleteTableViewCell: UITableViewCell {
@ -30,11 +31,8 @@ final class AutoCompleteTableViewCell: UITableViewCell {
let avatarImageView = FLAnimatedImageView()
let titleLabel: UILabel = {
let label = UILabel()
label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 22)
label.textColor = Asset.Colors.brandBlue.color
label.text = "Title"
let titleLabel: MetaLabel = {
let label = MetaLabel(style: .autoCompletion)
return label
}()