Skip to content

Instantly share code, notes, and snippets.

@cardoso
Last active February 4, 2021 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cardoso/3e3b7852a57129119e1d113337baa3f0 to your computer and use it in GitHub Desktop.
Save cardoso/3e3b7852a57129119e1d113337baa3f0 to your computer and use it in GitHub Desktop.
import SwiftUI
import StreamChat
struct MessageView: View {
let message: ChatMessage
var background: some View {
if (message.isSentByCurrentUser) {
return Color.blue.opacity(0.25)
} else {
return Color.gray.opacity(0.25)
}
}
var title: some View {
if message.isSentByCurrentUser {
return Text("")
} else {
return Text(message.author.id).font(.footnote)
}
}
var body: some View {
HStack {
if message.isSentByCurrentUser { Spacer() }
VStack(alignment: .leading) {
title
Text(message.text)
.padding(8)
.background(background)
.cornerRadius(24)
}
if !message.isSentByCurrentUser { Spacer() }
}.frame(maxWidth: .infinity)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment