Skip to content

Commit da4b616

Browse files
Added modifier for the message composer
1 parent 176230b commit da4b616

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public struct MessageComposerView<Factory: ViewFactory>: View, KeyboardReadable
163163
.animation(nil) : nil,
164164
alignment: .bottom
165165
)
166+
.modifier(factory.makeComposerViewModifier())
166167
.alert(isPresented: $viewModel.errorShown) {
167168
Alert.defaultErrorAlert
168169
}

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ extension ViewFactory {
501501
}
502502
}
503503

504+
public func makeComposerViewModifier() -> some ViewModifier {
505+
EmptyViewModifier()
506+
}
507+
504508
public func makeAttachmentPickerView(
505509
attachmentPickerState: Binding<AttachmentPickerState>,
506510
filePickerShown: Binding<Bool>,

Sources/StreamChatSwiftUI/ViewFactory.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ public protocol ViewFactory: AnyObject {
475475
onTap: @escaping () -> Void
476476
) -> TrailingComposerViewType
477477

478+
associatedtype ComposerViewModifier: ViewModifier
479+
/// Creates the composer view modifier, that's applied to the whole composer view.
480+
func makeComposerViewModifier() -> ComposerViewModifier
481+
478482
associatedtype AttachmentPickerViewType: View
479483
/// Creates the attachment picker view.
480484
/// - Parameters:

StreamChatSwiftUITests/Tests/Utils/ViewFactory_Tests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,17 @@ class ViewFactory_Tests: StreamChatTestCase {
634634
// Then
635635
XCTAssert(modifier is MessageBubbleModifier)
636636
}
637+
638+
func test_viewFactory_makeComposerViewModifier() {
639+
// Given
640+
let viewFactory = DefaultViewFactory.shared
641+
642+
// When
643+
let modifier = viewFactory.makeComposerViewModifier()
644+
645+
// Then
646+
XCTAssert(modifier is EmptyViewModifier)
647+
}
637648
}
638649

639650
extension ChannelAction: Equatable {

docusaurus/docs/iOS/swiftui/components/message-composer.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ The message composer is the component that allows you to send messages consistin
1111
- Trailing composer view - displayed in the right part of the component. Usually used for sending the message.
1212
- Attachment picker view - component that allows you to pick several different types of attachments. The default component has three types of attachments (images and videos from the photo library, files and camera input). When an attachment is selected, by default it is added to the composer's input view. You can inject custom views (alternative pickers) in the component itself as well.
1313

14+
## Applying a Custom Modifier
15+
16+
If you want to customize the background, paddings and other styling properties of the composer view, you can apply a custom modifier by implementing the method `makeComposerViewModifier` in the `ViewFactory`. Here's an example that changes the background of the composer view.
17+
18+
```swift
19+
func makeComposerViewModifier() -> some ViewModifier {
20+
BackgroundViewModifier()
21+
}
22+
23+
struct BackgroundViewModifier: ViewModifier {
24+
25+
public func body(content: Content) -> some View {
26+
content
27+
.background(Color.red)
28+
}
29+
}
30+
```
31+
1432
## Customizing the Leading Composer View
1533

1634
You can completely swap the leading composer view with your own implementation. This might be useful if you want to change the behaviour of the attachment picker (provide a different one), or even just hide the component.

0 commit comments

Comments
 (0)