diff --git a/firebaseai/ChatExample/Views/MessageView.swift b/firebaseai/ChatExample/Views/MessageView.swift index b11c903e5..0ac11779c 100644 --- a/firebaseai/ChatExample/Views/MessageView.swift +++ b/firebaseai/ChatExample/Views/MessageView.swift @@ -83,24 +83,41 @@ struct ResponseTextView: View { struct MessageView: View { var message: ChatMessage + private var participantLabel: String { + message.participant == .user ? "User" : "Model" + } + 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: message.participant == .user ? .trailing : .leading, spacing: 4) { + // Sender label + Text(participantLabel) + .font(.caption2) + .fontWeight(.medium) + .foregroundColor(.secondary) + .textCase(.uppercase) + .padding(.horizontal, 8) + .padding(.vertical, 2) + .frame(maxWidth: .infinity, alignment: message.participant == .user ? .trailing : .leading) + + // 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)