metatext/Views/CustomEmojiText.swift

32 lines
919 B
Swift
Raw Normal View History

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