Skip to content

Commit 7619826

Browse files
Exposed init methods for smaller components
1 parent 29f691e commit 7619826

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Composer/AddedFileAttachmentsView.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ import SwiftUI
77

88
/// View for an added file displayed in the composer input.
99
public struct AddedFileAttachmentsView: View {
10+
1011
@Injected(\.colors) private var colors
1112

1213
var addedFileURLs: [URL]
1314
var onDiscardAttachment: (String) -> Void
1415

16+
public init(addedFileURLs: [URL], onDiscardAttachment: @escaping (String) -> Void) {
17+
self.addedFileURLs = addedFileURLs
18+
self.onDiscardAttachment = onDiscardAttachment
19+
}
20+
1521
public var body: some View {
1622
VStack {
1723
ForEach(0..<addedFileURLs.count, id: \.self) { i in

Sources/StreamChatSwiftUI/ChatChannel/MessageList/FileAttachmentView.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ public struct FileAttachmentsContainer<Factory: ViewFactory>: View {
1515
var isFirst: Bool
1616
@Binding var scrolledId: String?
1717

18+
public init(
19+
factory: Factory,
20+
message: ChatMessage,
21+
width: CGFloat,
22+
isFirst: Bool,
23+
scrolledId: Binding<String?>
24+
) {
25+
self.factory = factory
26+
self.message = message
27+
self.width = width
28+
self.isFirst = isFirst
29+
_scrolledId = scrolledId
30+
}
31+
1832
public var body: some View {
1933
VStack(alignment: message.alignmentInBubble) {
2034
if let quotedMessage = utils.messageCachingUtils.quotedMessage(for: message) {
@@ -77,6 +91,12 @@ public struct FileAttachmentView: View {
7791
var width: CGFloat
7892
var isFirst: Bool
7993

94+
public init(attachment: ChatMessageFileAttachment, width: CGFloat, isFirst: Bool) {
95+
self.attachment = attachment
96+
self.width = width
97+
self.isFirst = isFirst
98+
}
99+
80100
public var body: some View {
81101
HStack {
82102
FileAttachmentDisplayView(
@@ -102,7 +122,8 @@ public struct FileAttachmentView: View {
102122
}
103123
}
104124

105-
struct FileAttachmentDisplayView: View {
125+
public struct FileAttachmentDisplayView: View {
126+
106127
@Injected(\.images) private var images
107128
@Injected(\.fonts) private var fonts
108129
@Injected(\.colors) private var colors
@@ -111,7 +132,13 @@ struct FileAttachmentDisplayView: View {
111132
var title: String
112133
var sizeString: String
113134

114-
var body: some View {
135+
public init(url: URL, title: String, sizeString: String) {
136+
self.url = url
137+
self.title = title
138+
self.sizeString = sizeString
139+
}
140+
141+
public var body: some View {
115142
HStack {
116143
Image(uiImage: previewImage)
117144
.resizable()

0 commit comments

Comments
 (0)