diff options
Diffstat (limited to 'Juick/Views/MessageView.swift')
-rw-r--r-- | Juick/Views/MessageView.swift | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Juick/Views/MessageView.swift b/Juick/Views/MessageView.swift new file mode 100644 index 0000000..ffd0f19 --- /dev/null +++ b/Juick/Views/MessageView.swift @@ -0,0 +1,51 @@ +// +// MessageView.swift +// tst +// +// Created by Vitaly Takmazov on 10.12.2019. +// Copyright © 2019 com.juick. All rights reserved. +// + +import SwiftUI +import Atributika + +struct MessageView: View { + var message: Message + let all = Style.font(UIFont.preferredFont(forTextStyle: .body)) + let link = Style("a") + .foregroundColor(.blue, .normal) + .foregroundColor(.brown, .highlighted) + let configureLabel: ((AttributedLabel) -> Void) = { label in + label.numberOfLines = 0 + label.textColor = .label + } + var body: some View { + VStack(alignment: .leading) { + HStack { + LoadableImageView(with: message.user.avatar ?? "") + .frame(width: 48, height: 48, alignment: .center) + Text(message.user.uname) + .font(.headline) + .foregroundColor(.accentColor) + .fixedSize(horizontal: true, vertical: false) + } + AttributedLabelView(attributedText: (message.text ?? "") + .style(tags: link) + .styleHashtags(link) + .styleMentions(link) + .styleLinks(link) + .styleAll(all), configureLabel: configureLabel) + .fixedSize(horizontal: true, vertical: true) + message.attachment.map { + LoadableImageView(with: $0.url).scaledToFit() + } + } + } +} + +struct MessageView_Previews: PreviewProvider { + static let msg = Message() + static var previews: some View { + MessageView(message: msg) + } +} |