Skip to content

Commit 7ea34ad

Browse files
[SWUI-81] Implemented copying of a message
1 parent b326ef4 commit 7ea34ad

File tree

8 files changed

+58
-6
lines changed

8 files changed

+58
-6
lines changed

Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
5555
@Published public var scrolledId: String?
5656
@Published public var listId = UUID().uuidString
5757

58-
@Published public var showScrollToLatestButton = false {
59-
didSet {
60-
isActive = !showScrollToLatestButton
61-
}
62-
}
58+
@Published public var showScrollToLatestButton = false
6359

6460
@Published public var currentDateString: String?
6561
@Published public var messages = LazyCachedMapCollection<ChatMessage>() {

Sources/StreamChatSwiftUI/ChatChannel/Reactions/MessageActions/DefaultMessageActions.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ extension MessageAction {
6363
messageActions.append(pinAction)
6464
}
6565

66+
if !message.text.isEmpty {
67+
let copyAction = copyMessageAction(
68+
for: message,
69+
onFinish: onFinish
70+
)
71+
72+
messageActions.append(copyAction)
73+
}
74+
6675
if message.isSentByCurrentUser {
6776
let editAction = editMessageAction(
6877
for: message,
@@ -124,6 +133,29 @@ extension MessageAction {
124133

125134
// MARK: - private
126135

136+
private static func copyMessageAction(
137+
for message: ChatMessage,
138+
onFinish: @escaping (MessageActionInfo) -> Void
139+
) -> MessageAction {
140+
let copyAction = MessageAction(
141+
title: L10n.Message.Actions.copy,
142+
iconName: "icn_copy",
143+
action: {
144+
UIPasteboard.general.string = message.text
145+
onFinish(
146+
MessageActionInfo(
147+
message: message,
148+
identifier: "copy"
149+
)
150+
)
151+
},
152+
confirmationPopup: nil,
153+
isDestructive: false
154+
)
155+
156+
return copyAction
157+
}
158+
127159
private static func editMessageAction(
128160
for message: ChatMessage,
129161
channel: ChatChannel,

StreamChatSwiftUITests/Tests/ChatChannel/MessageActionsViewModel_Tests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MessageActionsViewModel_Tests: StreamChatTestCase {
2424
onError: { _ in }
2525
)
2626
let viewModel = MessageActionsViewModel(messageActions: actions)
27-
let action = actions[3]
27+
let action = actions[4]
2828

2929
// When
3030
viewModel.alertAction = action
Loading
Loading

docusaurus/docs/iOS/swiftui/components/channel-list-header.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ let appearance = Appearance(colors: colors)
2727
let streamChat = StreamChat(chatClient: chatClient, appearance: appearance)
2828
```
2929

30+
By default, the SDK shows a collapsed navigation bar. If you want to use a large navigation bar that's collapsible on scrolling down, you can configure it via the `navigationBarDisplayMode` method in the `ViewFactory`.
31+
32+
```swift
33+
func navigationBarDisplayMode() -> NavigationBarItem.TitleDisplayMode {
34+
.large
35+
}
36+
```
37+
3038
## Creating Your own Header
3139

3240
In most cases, you will need to customize the navigation bar even further - either by adding branding information, like logo and text, or even additional buttons that will either push a new view, display a modal sheet or an alert.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ The message list view in the SwiftUI SDK allows several customization options. T
88

99
If you are developing an app with this use-case, you can customize the [message avatars](../custom-avatar), [reactions](../message-reactions), [theming and presentation logic](../../getting-started) and the different types of [attachments](../attachments).
1010

11+
Additionally, you can control the display of the helper views around the message (date indicators, avatars) and paddings, via the `MessageListConfig`'s properties `MessageDisplayOptions` and `MessagePaddings`. The `MessageListConfig` is part of the `Utils` class in `StreamChat`. Here's an example on how to hide the date indicators and avatars, while also increasing the horizontal padding.
12+
13+
```swift
14+
let messageDisplayOptions = MessageDisplayOptions(showAvatars: false, showMessageDate: false)
15+
let messagePaddings = MessagePaddings(horizontal: 16)
16+
let messageListConfig = MessageListConfig(
17+
messageListType: .messaging,
18+
typingIndicatorPlacement: .navigationBar,
19+
groupMessages: true,
20+
messageDisplayOptions: messageDisplayOptions,
21+
messagePaddings: messagePaddings
22+
)
23+
let utils = Utils(messageListConfig: messageListConfig)
24+
streamChat = StreamChat(chatClient: chatClient, utils: utils)
25+
```
26+
1127
However, if you are building a livestream app similar to Twitch, you will need a different type of user interface for the message views. The SwiftUI SDK allows swapping the message container view with your own implementation, without needing to implement the whole message list, the composer or the reactions. In order to do this, you need to implement the method `makeMessageContainerView` in the `ViewFactory` protocol.
1228

1329
For example, if you need a simple text message view, alligned on the left, you can do it like this:

0 commit comments

Comments
 (0)