From 29b30e18019dcfdb342b88540f18e14d366585cf Mon Sep 17 00:00:00 2001 From: Haibo Yang Date: Sun, 27 Jul 2025 23:08:54 -0700 Subject: [PATCH 1/4] add user label --- .../ChatExample/Views/MessageView.swift | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/firebaseai/ChatExample/Views/MessageView.swift b/firebaseai/ChatExample/Views/MessageView.swift index b11c903e5..d04b9d0f8 100644 --- a/firebaseai/ChatExample/Views/MessageView.swift +++ b/firebaseai/ChatExample/Views/MessageView.swift @@ -84,23 +84,35 @@ struct MessageView: View { var message: ChatMessage 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(message.participant == .user ? "USER" : "MODEL") + .font(.caption2) + .fontWeight(.medium) + .foregroundColor(.secondary) + .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) From 36788d668175ee70dc8b95acb7d671b502997854 Mon Sep 17 00:00:00 2001 From: Haibo Yang Date: Sun, 27 Jul 2025 23:20:23 -0700 Subject: [PATCH 2/4] add ternary operation for better readablitity --- firebaseai/ChatExample/Views/MessageView.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/firebaseai/ChatExample/Views/MessageView.swift b/firebaseai/ChatExample/Views/MessageView.swift index d04b9d0f8..b8dd97b47 100644 --- a/firebaseai/ChatExample/Views/MessageView.swift +++ b/firebaseai/ChatExample/Views/MessageView.swift @@ -82,17 +82,25 @@ 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 { - VStack(alignment: message.participant == .user ? .trailing : .leading, spacing: 4) { + VStack(alignment: alignment, spacing: 4) { // Sender label - Text(message.participant == .user ? "USER" : "MODEL") + Text(participantLabel) .font(.caption2) .fontWeight(.medium) .foregroundColor(.secondary) .padding(.horizontal, 8) .padding(.vertical, 2) - .frame(maxWidth: .infinity, alignment: message.participant == .user ? .trailing : .leading) + .frame(maxWidth: .infinity, alignment: alignment) // Message content HStack { From c3a9fe7b7af7c2b09c0b4879fbf7f18eb0296c14 Mon Sep 17 00:00:00 2001 From: Haibo Yang Date: Mon, 28 Jul 2025 09:27:59 -0700 Subject: [PATCH 3/4] add .uppercase in user-label --- firebaseai/ChatExample/Views/MessageView.swift | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/firebaseai/ChatExample/Views/MessageView.swift b/firebaseai/ChatExample/Views/MessageView.swift index b8dd97b47..8a843ab3a 100644 --- a/firebaseai/ChatExample/Views/MessageView.swift +++ b/firebaseai/ChatExample/Views/MessageView.swift @@ -84,23 +84,20 @@ struct MessageView: View { var message: ChatMessage private var participantLabel: String { - message.participant == .user ? "USER" : "MODEL" - } - - private var alignment: HorizontalAlignment { - message.participant == .user ? .trailing : .leading + message.participant == .user ? "User" : "Model" } var body: some View { - VStack(alignment: alignment, spacing: 4) { + 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: alignment) + .frame(maxWidth: .infinity, alignment: message.participant == .user ? .trailing : .leading) // Message content HStack { From 11e376b2554a8ce8845af42072b53e25932936f2 Mon Sep 17 00:00:00 2001 From: Haibo Yang Date: Mon, 28 Jul 2025 18:11:26 -0700 Subject: [PATCH 4/4] Fix code formatting in MessageView.swift --- firebaseai/ChatExample/Views/MessageView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firebaseai/ChatExample/Views/MessageView.swift b/firebaseai/ChatExample/Views/MessageView.swift index 8a843ab3a..0ac11779c 100644 --- a/firebaseai/ChatExample/Views/MessageView.swift +++ b/firebaseai/ChatExample/Views/MessageView.swift @@ -82,7 +82,7 @@ struct ResponseTextView: View { struct MessageView: View { var message: ChatMessage - + private var participantLabel: String { message.participant == .user ? "User" : "Model" } @@ -98,7 +98,7 @@ struct MessageView: View { .padding(.horizontal, 8) .padding(.vertical, 2) .frame(maxWidth: .infinity, alignment: message.participant == .user ? .trailing : .leading) - + // Message content HStack { if message.participant == .user {