Skip to content

Commit 435db51

Browse files
Fixed PR remarks
1 parent b459ee6 commit 435db51

File tree

6 files changed

+30
-23
lines changed

6 files changed

+30
-23
lines changed

Sources/StreamChatSwiftUI/ChatChannel/ChannelHeader/ChatChannelHeaderViewModifier.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ public struct DefaultChatChannelHeader: ToolbarContent {
2525
chatClient.currentUserId ?? ""
2626
}
2727

28+
private var shouldShowTypingIndicator: Bool {
29+
!channel.currentlyTypingUsersFiltered(currentUserId: currentUserId).isEmpty
30+
&& utils.typingIndicatorPlacement == .navigationBar
31+
&& channel.config.typingEventsEnabled
32+
}
33+
34+
private var onlineIndicatorShown: Bool {
35+
!channel.lastActiveMembers.filter { member in
36+
member.id != chatClient.currentUserId && member.isOnline
37+
}
38+
.isEmpty
39+
}
40+
2841
public var channel: ChatChannel
2942
public var headerImage: UIImage
3043

@@ -55,19 +68,6 @@ public struct DefaultChatChannelHeader: ToolbarContent {
5568
.offset(x: 8)
5669
}
5770
}
58-
59-
private var shouldShowTypingIndicator: Bool {
60-
!channel.currentlyTypingUsersFiltered(currentUserId: currentUserId).isEmpty
61-
&& utils.typingIndicatorPlacement == .navigationBar
62-
&& channel.config.typingEventsEnabled
63-
}
64-
65-
private var onlineIndicatorShown: Bool {
66-
!channel.lastActiveMembers.filter { member in
67-
member.id != chatClient.currentUserId && member.isOnline
68-
}
69-
.isEmpty
70-
}
7171
}
7272

7373
/// The default header modifier.

Sources/StreamChatSwiftUI/ChatChannel/Composer/AttachmentPickerTypeView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public struct AttachmentPickerTypeView: View {
3333
@Binding var pickerTypeState: PickerTypeState
3434
var channelConfig: ChannelConfig?
3535

36+
private var commandsAvailable: Bool {
37+
channelConfig?.commands.count ?? 0 > 0
38+
}
39+
3640
public var body: some View {
3741
HStack(spacing: 16) {
3842
switch pickerTypeState {
@@ -45,7 +49,7 @@ public struct AttachmentPickerTypeView: View {
4549
)
4650
}
4751

48-
if channelConfig?.commands.count ?? 0 > 0 {
52+
if commandsAvailable {
4953
PickerTypeButton(
5054
pickerTypeState: $pickerTypeState,
5155
pickerType: .instantCommands,

Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerTextInputView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ struct ComposerTextInputView: UIViewRepresentable {
6363
replacementText text: String
6464
) -> Bool {
6565
guard let maxMessageLength = maxMessageLength else { return true }
66-
return textView.text.count + (text.count - range.length) <= maxMessageLength
66+
let newMessageLength = textView.text.count + (text.count - range.length)
67+
return newMessageLength <= maxMessageLength
6768
}
6869

6970
func layoutManager(

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ open class MessageComposerViewModel: ObservableObject {
240240
}
241241

242242
public var showCommandsOverlay: Bool {
243-
composerCommand != nil && channelController.channel?.config.commands.count ?? 0 > 0
243+
let commandAvailable = composerCommand != nil
244+
let configuredCommandsAvailable = channelController.channel?.config.commands.count ?? 0 > 0
245+
return commandAvailable && configuredCommandsAvailable
244246
}
245247

246248
public func change(pickerState: AttachmentPickerState) {

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListView.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
3535
utils.dateFormatter
3636
}
3737

38+
private var shouldShowTypingIndicator: Bool {
39+
!channel.currentlyTypingUsersFiltered(currentUserId: chatClient.currentUserId).isEmpty
40+
&& utils.typingIndicatorPlacement == .bottomOverlay
41+
&& channel.config.typingEventsEnabled
42+
}
43+
3844
private let scrollAreaId = "scrollArea"
3945

4046
var body: some View {
@@ -168,12 +174,6 @@ struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
168174
.modifier(HideKeyboardOnTapGesture(shouldAdd: keyboardShown))
169175
}
170176

171-
private var shouldShowTypingIndicator: Bool {
172-
!channel.currentlyTypingUsersFiltered(currentUserId: chatClient.currentUserId).isEmpty
173-
&& utils.typingIndicatorPlacement == .bottomOverlay
174-
&& channel.config.typingEventsEnabled
175-
}
176-
177177
private func showsAllData(for message: ChatMessage) -> Bool {
178178
let dateString = dateFormatter.string(from: message.createdAt)
179179
let prefix = message.author.id

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You can completely swap the leading composer view with your own implementation.
1717

1818
In order to do this, you need to implement the `makeLeadingComposerView`, which receives a binding of the `PickerTypeState`. Having the `PickerTypeState` as a parameter allows you to control the visibility of the attachment picker view. The `PickerTypeState` has two states - expanded and collapsed. If the state is collapsed, the composer is in the minimal mode (only the text input and leading and trailing areas are shown). If the enum state is expanded, it has associated value with it, which is of type `AttachmentPickerType`. This defines the type of picker which is currently displayed in the attachment picker view. The possible states are `none` (nothing is selected), `media` (media picker is selected), `giphy` (giphy commands picker is shown) and custom (for your own custom pickers).
1919

20-
Apart from the `PickerTypeState`, you also receive the `ChannelConfig` as a parameter. This config allows you to control the display of some elements from the channel response from the backend, such as enabling / disabling of the attachments, max message length, typing indicators, etc.
20+
Apart from the `PickerTypeState`, you also receive the `ChannelConfig` as a parameter. This config allows you to control the display of some elements from the channel response from the backend, such as enabling / disabling of the attachments, max message length, typing indicators, etc. More details about the available settings in the channel config can be found [here](https://getstream.io/chat/docs/ios-swift/channel_features/?language=swift).
2121

2222
Here's an example on how to provide a view for the leading composer view:
2323

0 commit comments

Comments
 (0)