Skip to content

Commit 1dbbc59

Browse files
Added possibility to change text color for different senders
1 parent dd25988 commit 1dbbc59

File tree

8 files changed

+23
-2
lines changed

8 files changed

+23
-2
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/FileAttachmentView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public struct FileAttachmentsContainer<Factory: ViewFactory>: View {
4444

4545
HStack {
4646
Text(message.text)
47+
.foregroundColor(textColor(for: message))
4748
.standardPadding()
4849
Spacer()
4950
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/ImageAttachmentView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public struct ImageAttachmentContainer<Factory: ViewFactory>: View {
5050
HStack {
5151
Text(message.text)
5252
.standardPadding()
53+
.foregroundColor(textColor(for: message))
5354
Spacer()
5455
}
5556
.background(Color(backgroundColor))

Sources/StreamChatSwiftUI/ChatChannel/MessageList/LinkAttachmentView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public struct LinkAttachmentContainer<Factory: ViewFactory>: View {
3838
let size = message.text.frameSize(maxWidth: width - 2 * padding)
3939
LinkTextView(
4040
text: message.text,
41-
width: width - 2 * padding
41+
width: width - 2 * padding,
42+
textColor: UIColor(textColor(for: message))
4243
)
4344
.standardPadding()
4445
.frame(width: width, height: size.height + 2 * padding)

Sources/StreamChatSwiftUI/ChatChannel/MessageList/LinkTextView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import UIKit
99
struct LinkTextView: UIViewRepresentable {
1010
var text: String
1111
var width: CGFloat
12+
var textColor: UIColor
1213

1314
func makeUIView(context: Context) -> UITextView {
1415
let textView = OnlyLinkTappableTextView()
@@ -23,6 +24,7 @@ struct LinkTextView: UIViewRepresentable {
2324
textView.font = UIFont.preferredFont(forTextStyle: .body)
2425
textView.adjustsFontForContentSizeCategory = true
2526
textView.text = text
27+
textView.textColor = textColor
2628
return textView
2729
}
2830

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListHelperViews.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,16 @@ struct TopLeftView<Content: View>: View {
123123
}
124124
}
125125
}
126+
127+
extension View {
128+
129+
func textColor(for message: ChatMessage) -> Color {
130+
@Injected(\.colors) var colors
131+
132+
if message.isSentByCurrentUser {
133+
return Color(colors.messageCurrentUserTextColor)
134+
} else {
135+
return Color(colors.messageOtherUserTextColor)
136+
}
137+
}
138+
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public struct MessageTextView<Factory: ViewFactory>: View {
125125

126126
Text(message.text)
127127
.standardPadding()
128-
.foregroundColor(Color(colors.text))
128+
.foregroundColor(textColor(for: message))
129129
.font(fonts.body)
130130
}
131131
.messageBubble(for: message, isFirst: isFirst)

Sources/StreamChatSwiftUI/ChatChannel/MessageList/QuotedMessageView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ struct QuotedMessageView: View {
106106
}
107107

108108
Text(textForMessage)
109+
.foregroundColor(textColor(for: quotedMessage))
109110
.lineLimit(3)
110111
.font(fonts.footnote)
111112

Sources/StreamChatSwiftUI/ColorPalette.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public struct ColorPalette {
7070
public lazy var messageCurrentUserBackground: [UIColor] = [background6]
7171
public lazy var messageCurrentUserEmphemeralBackground: [UIColor] = [background8]
7272
public lazy var messageOtherUserBackground: [UIColor] = [background8]
73+
public lazy var messageCurrentUserTextColor: UIColor = text
74+
public lazy var messageOtherUserTextColor: UIColor = text
7375
}
7476

7577
// Those colors are default defined stream constants, which are fallback values if you don't implement your color theme.

0 commit comments

Comments
 (0)