Skip to content

Commit 442bdd1

Browse files
Added a factory method for customizing the composer text input view
1 parent 4d7fa3d commit 442bdd1

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
### 🐞 Fixed
77
- Fixed the text input cursor when a message is being edited
88

9+
### ✅ Added
10+
- Added a factory method for customizing the composer text input view
11+
912
# [4.31.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.31.0)
1013
_April 25, 2023_
1114

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public struct ComposerInputView<Factory: ViewFactory>: View {
311311
.cornerRadius(16)
312312
}
313313

314-
ComposerTextInputView(
314+
factory.makeComposerTextInputView(
315315
text: $text,
316316
height: $textHeight,
317317
selectedRangeLocation: $selectedRangeLocation,

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,26 @@ extension ViewFactory {
543543
}
544544
}
545545

546+
public func makeComposerTextInputView(
547+
text: Binding<String>,
548+
height: Binding<CGFloat>,
549+
selectedRangeLocation: Binding<Int>,
550+
placeholder: String,
551+
editable: Bool,
552+
maxMessageLength: Int?,
553+
currentHeight: CGFloat
554+
) -> some View {
555+
ComposerTextInputView(
556+
text: text,
557+
height: height,
558+
selectedRangeLocation: selectedRangeLocation,
559+
placeholder: placeholder,
560+
editable: editable,
561+
maxMessageLength: maxMessageLength,
562+
currentHeight: currentHeight
563+
)
564+
}
565+
546566
public func makeTrailingComposerView(
547567
enabled: Bool,
548568
cooldownDuration: Int,

Sources/StreamChatSwiftUI/ViewFactory.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,27 @@ public protocol ViewFactory: AnyObject {
536536
shouldScroll: Bool,
537537
removeAttachmentWithId: @escaping (String) -> Void
538538
) -> ComposerInputViewType
539+
540+
associatedtype ComposerTextInputViewType: View
541+
/// Creates the composer input view.
542+
/// - Parameters:
543+
/// - text: the text displayed in the input view.
544+
/// - height: the height of the view.
545+
/// - selectedRangeLocation: the selected range location of a text.
546+
/// - placeholder: the placeholder shown when there's no text.
547+
/// - editable: whether the text view should be editable.
548+
/// - maxMessageLength: the maximum allowed message length.
549+
/// - currentHeight: the current height of the view.
550+
/// - Returns: View shown in the composer text input slot.
551+
func makeComposerTextInputView(
552+
text: Binding<String>,
553+
height: Binding<CGFloat>,
554+
selectedRangeLocation: Binding<Int>,
555+
placeholder: String,
556+
editable: Bool,
557+
maxMessageLength: Int?,
558+
currentHeight: CGFloat
559+
) -> ComposerTextInputViewType
539560

540561
associatedtype TrailingComposerViewType: View
541562
/// Creates the trailing composer view.

StreamChatSwiftUITests/Tests/Utils/ViewFactory_Tests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,25 @@ class ViewFactory_Tests: StreamChatTestCase {
773773
// Then
774774
XCTAssert(view is NewMessagesIndicator)
775775
}
776+
777+
func test_viewFactory_makeComposerTextInputView() {
778+
// Given
779+
let viewFactory = DefaultViewFactory.shared
780+
781+
// When
782+
let view = viewFactory.makeComposerTextInputView(
783+
text: .constant("test"),
784+
height: .constant(40),
785+
selectedRangeLocation: .constant(0),
786+
placeholder: "Send a message",
787+
editable: true,
788+
maxMessageLength: nil,
789+
currentHeight: 40
790+
)
791+
792+
// Then
793+
XCTAssert(view is ComposerTextInputView)
794+
}
776795
}
777796

778797
extension ChannelAction: Equatable {

0 commit comments

Comments
 (0)