Skip to content

Commit fae1496

Browse files
Enabled injecting view model in the message composer
1 parent f41b15b commit fae1496

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerModels.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ public struct AddedAsset: Identifiable, Equatable {
2525
public let url: URL
2626
public let type: AssetType
2727
public var extraData: [String: Any] = [:]
28+
29+
public init(
30+
image: UIImage,
31+
id: String,
32+
url: URL,
33+
type: AssetType,
34+
extraData: [String: Any] = [:]
35+
) {
36+
self.image = image
37+
self.id = id
38+
self.url = url
39+
self.type = type
40+
self.extraData = extraData
41+
}
2842
}
2943

3044
/// Type of asset added to the composer.

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public struct MessageComposerView<Factory: ViewFactory>: View, KeyboardReadable
2121

2222
public init(
2323
viewFactory: Factory,
24+
viewModel: MessageComposerViewModel? = nil,
2425
channelController: ChatChannelController,
2526
messageController: ChatMessageController?,
2627
quotedMessage: Binding<ChatMessage?>,
@@ -30,7 +31,7 @@ public struct MessageComposerView<Factory: ViewFactory>: View, KeyboardReadable
3031
factory = viewFactory
3132
channelConfig = channelController.channel?.config
3233
_viewModel = StateObject(
33-
wrappedValue: ViewModelsFactory.makeMessageComposerViewModel(
34+
wrappedValue: viewModel ?? ViewModelsFactory.makeMessageComposerViewModel(
3435
with: channelController,
3536
messageController: messageController
3637
)

0 commit comments

Comments
 (0)