Skip to content

Commit f05af47

Browse files
updated the docs
1 parent bda2bf1 commit f05af47

File tree

8 files changed

+107
-43
lines changed

8 files changed

+107
-43
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ struct MessageView<Factory: ViewFactory>: View {
2424
factory.makeCustomAttachmentViewType(
2525
for: message,
2626
isFirst: isFirst,
27-
availableWidth: contentWidth
27+
availableWidth: contentWidth,
28+
scrolledId: $scrolledId
2829
)
2930
} else if messageTypeResolver.isDeleted(message: message) {
3031
factory.makeDeletedMessageView(

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ extension ViewFactory {
228228
public func makeCustomAttachmentViewType(
229229
for message: ChatMessage,
230230
isFirst: Bool,
231-
availableWidth: CGFloat
231+
availableWidth: CGFloat,
232+
scrolledId: Binding<String?>
232233
) -> some View {
233234
EmptyView()
234235
}

Sources/StreamChatSwiftUI/ViewFactory.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ public protocol ViewFactory: AnyObject {
206206
func makeCustomAttachmentViewType(
207207
for message: ChatMessage,
208208
isFirst: Bool,
209-
availableWidth: CGFloat
209+
availableWidth: CGFloat,
210+
scrolledId: Binding<String?>
210211
) -> CustomAttachmentViewType
211212

212213
associatedtype GiphyBadgeViewType: View
Loading
Loading

StreamChatSwiftUITests/Tests/Utils/ViewFactory_Tests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ class ViewFactory_Tests: XCTestCase {
253253
let view = viewFactory.makeCustomAttachmentViewType(
254254
for: message,
255255
isFirst: true,
256-
availableWidth: 300
256+
availableWidth: 300,
257+
scrolledId: .constant(nil)
257258
)
258259

259260
// Then

docusaurus/docs/iOS/swiftui/components/attachments.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ class CustomFactory: ViewFactory {
5757
func makeMessageTextView(
5858
for message: ChatMessage,
5959
isFirst: Bool,
60-
availableWidth: CGFloat
60+
availableWidth: CGFloat,
61+
scrolledId: Binding<String?>
6162
) -> some View {
6263
CustomMessageTextView(
6364
message: message,
64-
isFirst: isFirst
65+
isFirst: isFirst,
66+
scrolledId: scrolledId
6567
)
6668
}
6769

@@ -146,7 +148,8 @@ Next, in our `CustomFactory`, we need to return the new view we have created abo
146148
func makeCustomAttachmentViewType(
147149
for message: ChatMessage,
148150
isFirst: Bool,
149-
availableWidth: CGFloat
151+
availableWidth: CGFloat,
152+
scrolledId: Binding<String?>
150153
) -> some View {
151154
CustomAttachmentView(
152155
message: message,

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

Lines changed: 93 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ The reactions overlay view (shown on long press of a message), also provides acc
4242
public func supportedMessageActions(
4343
for message: ChatMessage,
4444
channel: ChatChannel,
45-
onDismiss: @escaping () -> Void,
45+
onFinish: @escaping (MessageActionInfo) -> Void,
4646
onError: @escaping (Error) -> Void
4747
) -> [MessageAction] {
4848
MessageAction.defaultActions(
49-
factory: self,
50-
for: message,
51-
channel: channel,
52-
chatClient: chatClient,
53-
onDismiss: onDismiss,
54-
onError: onError
55-
)
49+
factory: self,
50+
for: message,
51+
channel: channel,
52+
chatClient: chatClient,
53+
onFinish: onFinish,
54+
onError: onError
55+
)
5656
}
5757

5858
extension MessageAction {
@@ -61,23 +61,24 @@ extension MessageAction {
6161
for message: ChatMessage,
6262
channel: ChatChannel,
6363
chatClient: ChatClient,
64-
onDismiss: @escaping () -> Void,
64+
onFinish: @escaping (MessageActionInfo) -> Void,
6565
onError: @escaping (Error) -> Void
6666
) -> [MessageAction] {
6767
var messageActions = [MessageAction]()
6868

69+
let replyAction = replyAction(
70+
for: message,
71+
channel: channel,
72+
onFinish: onFinish
73+
)
74+
messageActions.append(replyAction)
75+
6976
if !message.isPartOfThread {
70-
var replyThread = MessageAction(
71-
title: L10n.Message.Actions.threadReply,
72-
iconName: "icn_thread_reply",
73-
action: onDismiss,
74-
confirmationPopup: nil,
75-
isDestructive: false
77+
let replyThread = threadReplyAction(
78+
factory: factory,
79+
for: message,
80+
channel: channel
7681
)
77-
78-
let destination = factory.makeMessageThreadDestination()
79-
replyThread.navigationDestination = AnyView(destination(channel, message))
80-
8182
messageActions.append(replyThread)
8283
}
8384

@@ -86,7 +87,7 @@ extension MessageAction {
8687
for: message,
8788
channel: channel,
8889
chatClient: chatClient,
89-
onDismiss: onDismiss,
90+
onFinish: onFinish,
9091
onError: onError
9192
)
9293

@@ -96,7 +97,7 @@ extension MessageAction {
9697
for: message,
9798
channel: channel,
9899
chatClient: chatClient,
99-
onDismiss: onDismiss,
100+
onFinish: onFinish,
100101
onError: onError
101102
)
102103

@@ -106,11 +107,54 @@ extension MessageAction {
106107
return messageActions
107108
}
108109

110+
// MARK: - private
111+
112+
private static func replyAction(
113+
for message: ChatMessage,
114+
channel: ChatChannel,
115+
onFinish: @escaping (MessageActionInfo) -> Void
116+
) -> MessageAction {
117+
let replyAction = MessageAction(
118+
title: L10n.Message.Actions.inlineReply,
119+
iconName: "icn_inline_reply",
120+
action: {
121+
onFinish(
122+
MessageActionInfo(
123+
message: message,
124+
identifier: "inlineReply"
125+
)
126+
)
127+
},
128+
confirmationPopup: nil,
129+
isDestructive: false
130+
)
131+
132+
return replyAction
133+
}
134+
135+
private static func threadReplyAction<Factory: ViewFactory>(
136+
factory: Factory,
137+
for message: ChatMessage,
138+
channel: ChatChannel
139+
) -> MessageAction {
140+
var replyThread = MessageAction(
141+
title: L10n.Message.Actions.threadReply,
142+
iconName: "icn_thread_reply",
143+
action: {},
144+
confirmationPopup: nil,
145+
isDestructive: false
146+
)
147+
148+
let destination = factory.makeMessageThreadDestination()
149+
replyThread.navigationDestination = AnyView(destination(channel, message))
150+
return replyThread
151+
}
152+
109153
private static func deleteMessageAction(
110154
for message: ChatMessage,
111155
channel: ChatChannel,
112156
chatClient: ChatClient,
113-
onDismiss: @escaping () -> Void,
157+
onFinish: @escaping (MessageActionInfo) -> Void,
114158
onError: @escaping (Error) -> Void
115159
) -> MessageAction {
116160
let messageController = chatClient.messageController(
@@ -123,7 +167,12 @@ extension MessageAction {
123167
if let error = error {
124168
onError(error)
125169
} else {
126-
onDismiss()
170+
onFinish(
171+
MessageActionInfo(
172+
message: message,
173+
identifier: "delete"
174+
)
175+
)
127176
}
128177
}
129178
}
@@ -149,7 +198,7 @@ extension MessageAction {
149198
for message: ChatMessage,
150199
channel: ChatChannel,
151200
chatClient: ChatClient,
152-
onDismiss: @escaping () -> Void,
201+
onFinish: @escaping (MessageActionInfo) -> Void,
153202
onError: @escaping (Error) -> Void
154203
) -> MessageAction {
155204
let messageController = chatClient.messageController(
@@ -162,7 +211,12 @@ extension MessageAction {
162211
if let error = error {
163212
onError(error)
164213
} else {
165-
onDismiss()
214+
onFinish(
215+
MessageActionInfo(
216+
message: message,
217+
identifier: "flag"
218+
)
219+
)
166220
}
167221
}
168222
}
@@ -183,24 +237,25 @@ extension MessageAction {
183237

184238
return flagMessage
185239
}
240+
}
186241
```
187242

188243
Alternatively, you can swap the whole `MessageActionsView` with your own implementation, by implementing the `makeMessageActionsView` method in the `ViewFactory`.
189244

190245
```swift
191246
public func makeMessageActionsView(
192-
for message: ChatMessage,
193-
channel: ChatChannel,
194-
onDismiss: @escaping () -> Void,
195-
onError: @escaping (Error) -> Void
247+
for message: ChatMessage,
248+
channel: ChatChannel,
249+
onFinish: @escaping (MessageActionInfo) -> Void,
250+
onError: @escaping (Error) -> Void
196251
) -> some View {
197252
let messageActions = supportedMessageActions(
198253
for: message,
199254
channel: channel,
200-
onDismiss: onDismiss,
255+
onFinish: onFinish,
201256
onError: onError
202257
)
203-
258+
204259
return MessageActionsView(messageActions: messageActions)
205260
}
206261
```
@@ -209,17 +264,19 @@ Additionally, you can swap the whole `ReactionsOverlayView` with your own implem
209264

210265
```swift
211266
public func makeReactionsOverlayView(
212-
channel: ChatChannel,
213-
currentSnapshot: UIImage,
214-
messageDisplayInfo: MessageDisplayInfo,
215-
onBackgroundTap: @escaping () -> Void
267+
channel: ChatChannel,
268+
currentSnapshot: UIImage,
269+
messageDisplayInfo: MessageDisplayInfo,
270+
onBackgroundTap: @escaping () -> Void,
271+
onActionExecuted: @escaping (MessageActionInfo) -> Void
216272
) -> some View {
217273
ReactionsOverlayView(
218274
factory: self,
219275
channel: channel,
220276
currentSnapshot: currentSnapshot,
221277
messageDisplayInfo: messageDisplayInfo,
222-
onBackgroundTap: onBackgroundTap
278+
onBackgroundTap: onBackgroundTap,
279+
onActionExecuted: onActionExecuted
223280
)
224281
}
225282
```

0 commit comments

Comments
 (0)