Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions firebaseai/ChatExample/Views/MessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,45 @@ struct ResponseTextView: View {

struct MessageView: View {
var message: ChatMessage

private var participantLabel: String {
message.participant == .user ? "USER" : "MODEL"
}

private var alignment: HorizontalAlignment {
message.participant == .user ? .trailing : .leading
}

var body: some View {
HStack {
if message.participant == .user {
Spacer()
}
MessageContentView(message: message)
.padding(10)
.background(message.participant == .system
? Color(UIColor.systemFill)
: Color(UIColor.systemBlue))
.roundedCorner(10,
corners: [
.topLeft,
.topRight,
message.participant == .system ? .bottomRight : .bottomLeft,
])
if message.participant == .system {
Spacer()
VStack(alignment: alignment, spacing: 4) {
// Sender label
Text(participantLabel)
.font(.caption2)
.fontWeight(.medium)
.foregroundColor(.secondary)
.padding(.horizontal, 8)
.padding(.vertical, 2)
.frame(maxWidth: .infinity, alignment: alignment)

// Message content
HStack {
if message.participant == .user {
Spacer()
}
MessageContentView(message: message)
.padding(10)
.background(message.participant == .system
? Color(UIColor.systemFill)
: Color(UIColor.systemBlue))
.roundedCorner(10,
corners: [
.topLeft,
.topRight,
message.participant == .system ? .bottomRight : .bottomLeft,
])
if message.participant == .system {
Spacer()
}
}
}
.listRowSeparator(.hidden)
Expand Down
Loading