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

View File

@ -19,6 +19,7 @@ extension MetaLabel {
case recommendAccountName case recommendAccountName
case titleView case titleView
case settingTableFooter case settingTableFooter
case autoCompletion
} }
convenience init(style: Style) { convenience init(style: Style) {
@ -70,6 +71,9 @@ extension MetaLabel {
numberOfLines = 0 numberOfLines = 0
textContainer.maximumNumberOfLines = 0 textContainer.maximumNumberOfLines = 0
paragraphStyle.alignment = .center 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 self.font = font

View File

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