Skip to content

Commit d522f16

Browse files
committed
Allow changing the attachment size and author avatar size of quoted message view
1 parent c4d7df8 commit d522f16

File tree

1 file changed

+43
-22
lines changed

1 file changed

+43
-22
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/QuotedMessageView.swift

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,60 @@ import StreamChat
66
import SwiftUI
77

88
/// Container showing the quoted message view with the user avatar.
9-
struct QuotedMessageViewContainer<Factory: ViewFactory>: View {
10-
private let avatarSize: CGFloat = 24
9+
public struct QuotedMessageViewContainer<Factory: ViewFactory>: View {
10+
public var factory: Factory
11+
public var quotedMessage: ChatMessage
12+
public var fillAvailableSpace: Bool
13+
public var forceLeftToRight: Bool
14+
@Binding public var scrolledId: String?
15+
public let attachmentSize: CGSize
16+
public let quotedAuthorAvatarSize: CGSize
1117

12-
var factory: Factory
13-
var quotedMessage: ChatMessage
14-
var fillAvailableSpace: Bool
15-
var forceLeftToRight = false
16-
@Binding var scrolledId: String?
18+
public init(
19+
factory: Factory,
20+
quotedMessage: ChatMessage,
21+
fillAvailableSpace: Bool,
22+
forceLeftToRight: Bool = false,
23+
scrolledId: Binding<String?>,
24+
attachmentSize: CGSize = CGSize(width: 36, height: 36),
25+
quotedAuthorAvatarSize: CGSize = CGSize(width: 24, height: 24)
26+
) {
27+
self.factory = factory
28+
self.quotedMessage = quotedMessage
29+
self.fillAvailableSpace = fillAvailableSpace
30+
self.forceLeftToRight = forceLeftToRight
31+
_scrolledId = scrolledId
32+
self.attachmentSize = attachmentSize
33+
self.quotedAuthorAvatarSize = quotedAuthorAvatarSize
34+
}
1735

18-
var body: some View {
36+
public var body: some View {
1937
HStack(alignment: .bottom) {
2038
if !quotedMessage.isSentByCurrentUser || forceLeftToRight {
2139
factory.makeQuotedMessageAvatarView(
2240
for: quotedMessage.authorDisplayInfo,
23-
size: CGSize(width: avatarSize, height: avatarSize)
41+
size: quotedAuthorAvatarSize
2442
)
2543

2644
QuotedMessageView(
2745
factory: factory,
2846
quotedMessage: quotedMessage,
2947
fillAvailableSpace: fillAvailableSpace,
30-
forceLeftToRight: forceLeftToRight
48+
forceLeftToRight: forceLeftToRight,
49+
attachmentSize: attachmentSize
3150
)
3251
} else {
3352
QuotedMessageView(
3453
factory: factory,
3554
quotedMessage: quotedMessage,
3655
fillAvailableSpace: fillAvailableSpace,
37-
forceLeftToRight: forceLeftToRight
56+
forceLeftToRight: forceLeftToRight,
57+
attachmentSize: attachmentSize
3858
)
3959

4060
factory.makeQuotedMessageAvatarView(
4161
for: quotedMessage.authorDisplayInfo,
42-
size: CGSize(width: avatarSize, height: avatarSize)
62+
size: quotedAuthorAvatarSize
4363
)
4464
}
4565
}
@@ -62,14 +82,13 @@ public struct QuotedMessageView<Factory: ViewFactory>: View {
6282
@Injected(\.fonts) private var fonts
6383
@Injected(\.colors) private var colors
6484
@Injected(\.utils) private var utils
65-
66-
private let attachmentWidth: CGFloat = 36
6785

6886
public var factory: Factory
6987
public var quotedMessage: ChatMessage
7088
public var fillAvailableSpace: Bool
7189
public var forceLeftToRight: Bool
72-
90+
public let attachmentSize: CGSize
91+
7392
private var messageTypeResolver: MessageTypeResolving {
7493
utils.messageTypeResolver
7594
}
@@ -78,12 +97,14 @@ public struct QuotedMessageView<Factory: ViewFactory>: View {
7897
factory: Factory,
7998
quotedMessage: ChatMessage,
8099
fillAvailableSpace: Bool,
81-
forceLeftToRight: Bool
100+
forceLeftToRight: Bool,
101+
attachmentSize: CGSize = CGSize(width: 36, height: 36)
82102
) {
83103
self.factory = factory
84104
self.quotedMessage = quotedMessage
85105
self.fillAvailableSpace = fillAvailableSpace
86106
self.forceLeftToRight = forceLeftToRight
107+
self.attachmentSize = attachmentSize
87108
}
88109

89110
public var body: some View {
@@ -97,22 +118,22 @@ public struct QuotedMessageView<Factory: ViewFactory>: View {
97118
} else if !quotedMessage.imageAttachments.isEmpty {
98119
LazyLoadingImage(
99120
source: MediaAttachment(url: quotedMessage.imageAttachments[0].imageURL, type: .image),
100-
width: attachmentWidth,
101-
height: attachmentWidth,
121+
width: attachmentSize.width,
122+
height: attachmentSize.height,
102123
resize: false
103124
)
104125
} else if !quotedMessage.giphyAttachments.isEmpty {
105126
LazyGiphyView(
106127
source: quotedMessage.giphyAttachments[0].previewURL,
107-
width: attachmentWidth
128+
width: attachmentSize.width
108129
)
109130
} else if !quotedMessage.fileAttachments.isEmpty {
110131
Image(uiImage: filePreviewImage(for: quotedMessage.fileAttachments[0].assetURL))
111132
} else if !quotedMessage.videoAttachments.isEmpty {
112133
VideoAttachmentView(
113134
attachment: quotedMessage.videoAttachments[0],
114135
message: quotedMessage,
115-
width: attachmentWidth,
136+
width: attachmentSize.width,
116137
ratio: 1.0,
117138
cornerRadius: 0
118139
)
@@ -122,11 +143,11 @@ public struct QuotedMessageView<Factory: ViewFactory>: View {
122143
.originalURL
123144
)
124145
.onDisappear(.cancel)
125-
.processors([ImageProcessors.Resize(width: attachmentWidth)])
146+
.processors([ImageProcessors.Resize(width: attachmentSize.width)])
126147
.priority(.high)
127148
}
128149
}
129-
.frame(width: hasVoiceAttachments ? nil : attachmentWidth, height: attachmentWidth)
150+
.frame(width: hasVoiceAttachments ? nil : attachmentSize.width, height: attachmentSize.height)
130151
.aspectRatio(1, contentMode: .fill)
131152
.clipShape(RoundedRectangle(cornerRadius: 8))
132153
.allowsHitTesting(false)

0 commit comments

Comments
 (0)