Skip to content

Commit 00698ef

Browse files
added docs for customizing quoted messages
1 parent f05af47 commit 00698ef

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerView.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,8 @@ public struct ComposerInputView<Factory: ViewFactory>: View {
145145
public var body: some View {
146146
VStack {
147147
if let quotedMessage = quotedMessage.wrappedValue {
148-
QuotedMessageViewContainer(
149-
quotedMessage: quotedMessage,
150-
fillAvailableSpace: true,
151-
forceLeftToRight: true,
152-
scrolledId: .constant(nil)
148+
factory.makeQuotedMessageComposerView(
149+
quotedMessage: quotedMessage
153150
)
154151
}
155152

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,17 @@ extension ViewFactory {
485485
) -> some View {
486486
QuotedMessageHeaderView(quotedMessage: quotedMessage)
487487
}
488+
489+
public func makeQuotedMessageComposerView(
490+
quotedMessage: ChatMessage
491+
) -> some View {
492+
QuotedMessageViewContainer(
493+
quotedMessage: quotedMessage,
494+
fillAvailableSpace: true,
495+
forceLeftToRight: true,
496+
scrolledId: .constant(nil)
497+
)
498+
}
488499
}
489500

490501
/// Default class conforming to `ViewFactory`, used throughout the SDK.

Sources/StreamChatSwiftUI/ViewFactory.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,11 @@ public protocol ViewFactory: AnyObject {
462462
func makeQuotedMessageHeaderView(
463463
quotedMessage: Binding<ChatMessage?>
464464
) -> QuotedMessageHeaderViewType
465+
466+
associatedtype QuotedMessageComposerViewType: View
467+
/// Creates the quoted message shown in a composer view.
468+
/// - Parameter quotedMessage: the quoted message shown in the composer input.
469+
func makeQuotedMessageComposerView(
470+
quotedMessage: ChatMessage
471+
) -> QuotedMessageComposerViewType
465472
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Message inline replies
3+
---
4+
5+
## Inline Replies Overview
6+
7+
The SwiftUI SDK has support for inline message replies. These replies are invoked either by swiping left on a message, or via long pressing a message and selecting the "Reply" action. When a message is quoted, it appears in the message composer, as an indication which message the user is replying to.
8+
9+
## Customizing the Quoted Message
10+
11+
When a message appears as quoted in the composer, you can customize two parts. First, there's a header at the top of the composer, which by default has a title and a button to remove the quoted message from the composer. To swap this view with your own implementation, you need to implement the `makeQuotedMessageHeaderView` method in the `ViewFactory`, which passes a binding of the quoted chat message.
12+
13+
```swift
14+
public func makeQuotedMessageHeaderView(
15+
quotedMessage: Binding<ChatMessage?>
16+
) -> some View {
17+
CustomQuotedMessageHeaderView(quotedMessage: quotedMessage)
18+
}
19+
```
20+
21+
The second customization that can be done is to swap the preview of the message shown in the composer. The default implementation is able to present several different attachments, such as text, image, video, gifs, links and files. The UI consists of small image and either the message text (if present), or a description for the attachment.
22+
23+
In order to swap this UI, you need to implement the `makeQuotedMessageComposerView` method in the `ViewFactory`. The method passes the quoted message as a parameter.
24+
25+
```swift
26+
public func makeQuotedMessageComposerView(
27+
quotedMessage: ChatMessage
28+
) -> some View {
29+
QuotedMessageViewContainer(
30+
quotedMessage: quotedMessage,
31+
fillAvailableSpace: true,
32+
forceLeftToRight: true,
33+
scrolledId: .constant(nil)
34+
)
35+
}
36+
```
37+
38+
39+
Finally, we need to inject the your `CustomFactory` in our view hierarchy.
40+
41+
```swift
42+
var body: some Scene {
43+
WindowGroup {
44+
ChatChannelListView(viewFactory: CustomFactory.shared)
45+
}
46+
}
47+
```

docusaurus/sidebars-ios.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
"swiftui/components/attachments",
6565
"swiftui/components/message-composer",
6666
"swiftui/components/message-reactions",
67-
"swiftui/components/message-threads"
67+
"swiftui/components/message-threads",
68+
"swiftui/components/inline-replies"
6869
]
6970
}
7071
]

0 commit comments

Comments
 (0)