Skip to content

Commit 6411f02

Browse files
initial inline replies implementation
1 parent 1d4f7a7 commit 6411f02

File tree

8 files changed

+246
-55
lines changed

8 files changed

+246
-55
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/FileAttachmentView.swift

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,41 @@ public struct FileAttachmentsContainer: View {
1111
var isFirst: Bool
1212

1313
public var body: some View {
14-
VStack(spacing: 4) {
15-
ForEach(message.fileAttachments, id: \.self) { attachment in
16-
if message.text.isEmpty {
17-
FileAttachmentView(
18-
attachment: attachment,
19-
width: width,
20-
isFirst: isFirst
21-
)
22-
} else {
23-
VStack(spacing: 0) {
14+
VStack(alignment: message.alignmentInBubble) {
15+
if let quotedMessage = message.quotedMessage {
16+
QuotedMessageViewContainer(
17+
quotedMessage: quotedMessage,
18+
message: message
19+
)
20+
}
21+
22+
VStack(spacing: 4) {
23+
ForEach(message.fileAttachments, id: \.self) { attachment in
24+
if message.text.isEmpty {
2425
FileAttachmentView(
2526
attachment: attachment,
2627
width: width,
2728
isFirst: isFirst
2829
)
30+
} else {
31+
VStack(spacing: 0) {
32+
FileAttachmentView(
33+
attachment: attachment,
34+
width: width,
35+
isFirst: isFirst
36+
)
2937

30-
HStack {
31-
Text(message.text)
32-
.standardPadding()
33-
Spacer()
38+
HStack {
39+
Text(message.text)
40+
.standardPadding()
41+
Spacer()
42+
}
3443
}
3544
}
3645
}
3746
}
47+
.padding(.all, 4)
3848
}
39-
.padding(.all, 4)
4049
.messageBubble(for: message, isFirst: isFirst)
4150
}
4251
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/GiphyAttachmentView.swift

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,31 @@ public struct GiphyAttachmentView: View {
1414
let isFirst: Bool
1515

1616
public var body: some View {
17-
ZStack {
18-
if message.text.isEmpty {
19-
LazyGiphyView(
20-
source: message.giphyAttachments[0].previewURL,
21-
width: width
17+
VStack(
18+
alignment: message.alignmentInBubble,
19+
spacing: 0
20+
) {
21+
if let quotedMessage = message.quotedMessage {
22+
QuotedMessageViewContainer(
23+
quotedMessage: quotedMessage,
24+
message: message
2225
)
23-
.messageBubble(for: message, isFirst: isFirst)
24-
} else {
25-
VStack(spacing: 0) {
26-
LazyGiphyView(
27-
source: message.giphyAttachments[0].previewURL,
28-
width: width
29-
)
26+
}
27+
28+
LazyGiphyView(
29+
source: message.giphyAttachments[0].previewURL,
30+
width: width
31+
)
3032

31-
HStack {
32-
Text(message.text)
33-
.standardPadding()
34-
Spacer()
35-
}
33+
if !message.text.isEmpty {
34+
HStack {
35+
Text(message.text)
36+
.standardPadding()
37+
Spacer()
3638
}
37-
.messageBubble(for: message, isFirst: isFirst)
3839
}
3940
}
41+
.messageBubble(for: message, isFirst: isFirst)
4042
.frame(maxWidth: width)
4143
}
4244
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/ImageAttachmentView.swift

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,32 @@ public struct ImageAttachmentContainer: View {
1515
let isFirst: Bool
1616

1717
public var body: some View {
18-
if message.text.isEmpty {
18+
VStack(
19+
alignment: message.alignmentInBubble,
20+
spacing: 0
21+
) {
22+
if let quotedMessage = message.quotedMessage {
23+
QuotedMessageViewContainer(
24+
quotedMessage: quotedMessage,
25+
message: message
26+
)
27+
}
28+
1929
ImageAttachmentView(
2030
message: message,
2131
width: width
2232
)
23-
.messageBubble(for: message, isFirst: isFirst)
24-
} else {
25-
VStack(spacing: 0) {
26-
ImageAttachmentView(
27-
message: message,
28-
width: width
29-
)
30-
33+
34+
if !message.text.isEmpty {
3135
HStack {
3236
Text(message.text)
3337
.standardPadding()
3438
Spacer()
3539
}
3640
.background(Color(backgroundColor))
3741
}
38-
.messageBubble(for: message, isFirst: isFirst)
3942
}
43+
.messageBubble(for: message, isFirst: isFirst)
4044
}
4145

4246
private var backgroundColor: UIColor {
@@ -219,6 +223,8 @@ struct LazyLoadingImage: View {
219223
let source: URL
220224
let width: CGFloat
221225

226+
var resize: Bool = true
227+
222228
var body: some View {
223229
ZStack {
224230
if let image = image {
@@ -245,7 +251,7 @@ struct LazyLoadingImage: View {
245251
utils.imageLoader.loadImage(
246252
url: source,
247253
imageCDN: utils.imageCDN,
248-
resize: true,
254+
resize: resize,
249255
preferredSize: CGSize(width: width, height: 3 * width / 4),
250256
completion: { result in
251257
switch result {
@@ -260,3 +266,10 @@ struct LazyLoadingImage: View {
260266
.clipped()
261267
}
262268
}
269+
270+
extension ChatMessage {
271+
272+
var alignmentInBubble: HorizontalAlignment {
273+
.leading
274+
}
275+
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/LinkAttachmentView.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@ public struct LinkAttachmentContainer: View {
1919
private let padding: CGFloat = 8
2020

2121
public var body: some View {
22-
VStack(alignment: .leading, spacing: 0) {
22+
VStack(
23+
alignment: message.alignmentInBubble,
24+
spacing: 0
25+
) {
26+
if let quotedMessage = message.quotedMessage {
27+
QuotedMessageViewContainer(
28+
quotedMessage: quotedMessage,
29+
message: message
30+
)
31+
}
32+
2333
let size = message.text.frameSize(maxWidth: width - 2 * padding)
2434
LinkTextView(
2535
text: message.text,

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageBubble.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ public struct MessageBubbleModifier: ViewModifier {
1212
var message: ChatMessage
1313
var isFirst: Bool
1414
var injectedBackgroundColor: UIColor?
15+
var cornerRadius: CGFloat = 18
1516

1617
public func body(content: Content) -> some View {
1718
content
1819
.modifier(
1920
BubbleModifier(
2021
corners: corners,
21-
backgroundColor: Color(backgroundColor)
22+
backgroundColor: Color(backgroundColor),
23+
cornerRadius: cornerRadius
2224
)
2325
)
2426
}
@@ -56,11 +58,10 @@ public struct MessageBubbleModifier: ViewModifier {
5658
public struct BubbleModifier: ViewModifier {
5759
@Injected(\.colors) private var colors
5860

59-
private let cornerRadius: CGFloat = 18
60-
6161
var corners: UIRectCorner
6262
var backgroundColor: Color
6363
var borderColor: Color? = nil
64+
var cornerRadius: CGFloat = 18
6465

6566
public func body(content: Content) -> some View {
6667
content
@@ -108,13 +109,15 @@ extension View {
108109
public func messageBubble(
109110
for message: ChatMessage,
110111
isFirst: Bool,
111-
backgroundColor: UIColor? = nil
112+
backgroundColor: UIColor? = nil,
113+
cornerRadius: CGFloat = 18
112114
) -> some View {
113115
modifier(
114116
MessageBubbleModifier(
115117
message: message,
116118
isFirst: isFirst,
117-
injectedBackgroundColor: backgroundColor
119+
injectedBackgroundColor: backgroundColor,
120+
cornerRadius: cornerRadius
118121
)
119122
)
120123
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageView.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,23 @@ public struct MessageTextView: View {
100100
var isFirst: Bool
101101

102102
public var body: some View {
103-
Text(message.text)
104-
.standardPadding()
105-
.messageBubble(for: message, isFirst: isFirst)
106-
.foregroundColor(Color(colors.text))
107-
.font(fonts.body)
103+
VStack(
104+
alignment: message.alignmentInBubble,
105+
spacing: 0
106+
) {
107+
if let quotedMessage = message.quotedMessage {
108+
QuotedMessageViewContainer(
109+
quotedMessage: quotedMessage,
110+
message: message
111+
)
112+
}
113+
114+
Text(message.text)
115+
.standardPadding()
116+
.foregroundColor(Color(colors.text))
117+
.font(fonts.body)
118+
}
119+
.messageBubble(for: message, isFirst: isFirst)
108120
}
109121
}
110122

0 commit comments

Comments
 (0)