Skip to content

Commit e7a02d6

Browse files
added video support for inline replies
1 parent 6411f02 commit e7a02d6

File tree

2 files changed

+72
-39
lines changed

2 files changed

+72
-39
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/QuotedMessageView.swift

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct QuotedMessageViewContainer: View {
1616

1717
var body: some View {
1818
HStack(alignment: .bottom) {
19-
if !message.isSentByCurrentUser {
19+
if !quotedMessage.isSentByCurrentUser {
2020
MessageAvatarView(
2121
author: quotedMessage.author,
2222
size: .init(width: avatarSize, height: avatarSize)
@@ -55,36 +55,40 @@ struct QuotedMessageView: View {
5555

5656
var body: some View {
5757
HStack(alignment: .top) {
58-
ZStack {
59-
if !quotedMessage.imageAttachments.isEmpty {
60-
LazyLoadingImage(
61-
source: quotedMessage.imageAttachments[0].imagePreviewURL,
62-
width: attachmentWidth,
63-
resize: false
64-
)
65-
} else if !quotedMessage.giphyAttachments.isEmpty {
66-
LazyGiphyView(
67-
source: quotedMessage.giphyAttachments[0].previewURL,
68-
width: attachmentWidth
69-
)
70-
} else if !quotedMessage.fileAttachments.isEmpty {
71-
Image(uiImage: filePreviewImage(for: quotedMessage.fileAttachments[0].assetURL))
72-
} else if !quotedMessage.videoAttachments.isEmpty {
73-
VideoAttachmentView(
74-
attachment: quotedMessage.videoAttachments[0],
75-
message: quotedMessage,
76-
width: attachmentWidth
77-
)
78-
} else if !quotedMessage.linkAttachments.isEmpty {
79-
LazyImage(source: quotedMessage.linkAttachments[0].previewURL!)
80-
.onDisappear(.reset)
81-
.processors([ImageProcessors.Resize(width: attachmentWidth)])
82-
.priority(.high)
58+
if !quotedMessage.attachmentCounts.isEmpty {
59+
ZStack {
60+
if !quotedMessage.imageAttachments.isEmpty {
61+
LazyLoadingImage(
62+
source: quotedMessage.imageAttachments[0].imagePreviewURL,
63+
width: attachmentWidth,
64+
resize: false
65+
)
66+
} else if !quotedMessage.giphyAttachments.isEmpty {
67+
LazyGiphyView(
68+
source: quotedMessage.giphyAttachments[0].previewURL,
69+
width: attachmentWidth
70+
)
71+
} else if !quotedMessage.fileAttachments.isEmpty {
72+
Image(uiImage: filePreviewImage(for: quotedMessage.fileAttachments[0].assetURL))
73+
} else if !quotedMessage.videoAttachments.isEmpty {
74+
VideoAttachmentView(
75+
attachment: quotedMessage.videoAttachments[0],
76+
message: quotedMessage,
77+
width: attachmentWidth,
78+
ratio: 1.0,
79+
cornerRadius: 0
80+
)
81+
} else if !quotedMessage.linkAttachments.isEmpty {
82+
LazyImage(source: quotedMessage.linkAttachments[0].previewURL!)
83+
.onDisappear(.reset)
84+
.processors([ImageProcessors.Resize(width: attachmentWidth)])
85+
.priority(.high)
86+
}
8387
}
88+
.frame(width: attachmentWidth, height: attachmentWidth)
89+
.aspectRatio(1, contentMode: .fill)
90+
.clipShape(RoundedRectangle(cornerRadius: 8))
8491
}
85-
.frame(width: attachmentWidth, height: attachmentWidth)
86-
.aspectRatio(1, contentMode: .fill)
87-
.clipShape(RoundedRectangle(cornerRadius: 8))
8892

8993
Text(textForMessage)
9094
.lineLimit(3)

Sources/StreamChatSwiftUI/ChatChannel/MessageList/VideoAttachmentView.swift

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,49 @@ public struct VideoAttachmentsContainer: View {
1212

1313
public var body: some View {
1414
VStack {
15-
ForEach(message.videoAttachments, id: \.self) { attachment in
16-
VideoAttachmentView(
17-
attachment: attachment,
15+
if let quotedMessage = message.quotedMessage {
16+
VStack {
17+
QuotedMessageViewContainer(
18+
quotedMessage: quotedMessage,
19+
message: message
20+
)
21+
22+
VideoAttachmentsList(
23+
message: message,
24+
width: width
25+
)
26+
}
27+
.messageBubble(for: message, isFirst: false)
28+
} else {
29+
VideoAttachmentsList(
1830
message: message,
1931
width: width
2032
)
21-
.withUploadingStateIndicator(
22-
for: attachment.uploadingState,
23-
url: attachment.videoURL
24-
)
2533
}
2634
}
2735
}
2836
}
2937

38+
public struct VideoAttachmentsList: View {
39+
40+
let message: ChatMessage
41+
let width: CGFloat
42+
43+
public var body: some View {
44+
ForEach(message.videoAttachments, id: \.self) { attachment in
45+
VideoAttachmentView(
46+
attachment: attachment,
47+
message: message,
48+
width: width
49+
)
50+
.withUploadingStateIndicator(
51+
for: attachment.uploadingState,
52+
url: attachment.videoURL
53+
)
54+
}
55+
}
56+
}
57+
3058
public struct VideoAttachmentView: View {
3159
@Injected(\.utils) private var utils
3260

@@ -37,6 +65,8 @@ public struct VideoAttachmentView: View {
3765
let attachment: ChatMessageVideoAttachment
3866
let message: ChatMessage
3967
let width: CGFloat
68+
var ratio: CGFloat = 0.75
69+
var cornerRadius: CGFloat = 24
4070

4171
@State var previewImage: UIImage?
4272
@State var error: Error?
@@ -67,8 +97,8 @@ public struct VideoAttachmentView: View {
6797
}
6898
}
6999
}
70-
.frame(width: width, height: 3 * width / 4)
71-
.cornerRadius(24)
100+
.frame(width: width, height: width * ratio)
101+
.cornerRadius(cornerRadius)
72102
.fullScreenCover(isPresented: $fullScreenShown) {
73103
VideoPlayerView(
74104
attachment: attachment,
@@ -86,6 +116,5 @@ public struct VideoAttachmentView: View {
86116
}
87117
}
88118
}
89-
.cornerRadius(24)
90119
}
91120
}

0 commit comments

Comments
 (0)