metatext-app-ios-iphone-ipad/Views/CustomEmojiText.swift

32 lines
919 B
Swift
Raw Normal View History

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
2021-01-12 08:33:35 +01:00
private let emojis: [Emoji]
2020-08-08 11:10:05 +02:00
private let textStyle: UIFont.TextStyle
2021-01-12 08:33:35 +01:00
init(text: String, emojis: [Emoji], textStyle: UIFont.TextStyle) {
2020-08-08 11:10:05 +02:00
attributedText = NSMutableAttributedString(string: text)
2021-01-12 08:33:35 +01:00
self.emojis = emojis
2020-08-08 11:10:05 +02:00
self.textStyle = textStyle
}
func makeUIView(context: Context) -> UILabel {
let label = UILabel()
label.font = UIFont.preferredFont(forTextStyle: textStyle)
2021-01-12 08:33:35 +01:00
attributedText.insert(emojis: emojis, 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) {
}
}