2020-08-08 11:10:05 +02:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import SwiftUI
|
2020-08-31 01:33:11 +02:00
|
|
|
import struct Mastodon.Emoji
|
2020-08-08 11:10:05 +02:00
|
|
|
|
|
|
|
struct CustomEmojiText: UIViewRepresentable {
|
|
|
|
private let attributedText: NSMutableAttributedString
|
|
|
|
private let emoji: [Emoji]
|
|
|
|
private let textStyle: UIFont.TextStyle
|
|
|
|
|
|
|
|
init(text: String, emoji: [Emoji], textStyle: UIFont.TextStyle) {
|
|
|
|
attributedText = NSMutableAttributedString(string: text)
|
|
|
|
self.emoji = emoji
|
|
|
|
self.textStyle = textStyle
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeUIView(context: Context) -> UILabel {
|
|
|
|
let label = UILabel()
|
|
|
|
|
|
|
|
label.font = UIFont.preferredFont(forTextStyle: textStyle)
|
2020-08-27 07:10:31 +02:00
|
|
|
attributedText.insert(emoji: emoji, view: label)
|
2020-08-08 11:10:05 +02:00
|
|
|
attributedText.resizeAttachments(toLineHeight: label.font.lineHeight)
|
|
|
|
label.attributedText = attributedText
|
|
|
|
|
|
|
|
return label
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateUIView(_ uiView: UILabel, context: Context) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|