Skip to content

Commit 4b960cd

Browse files
Add support for customizing AddUsersView (#911)
1 parent 5ad5910 commit 4b960cd

File tree

6 files changed

+46
-4
lines changed

6 files changed

+46
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
33

44
# Upcoming
55

6-
### 🔄 Changed
6+
### ✅ Added
7+
- Add support for customizing AddUsersView [#911)(https://github.com/GetStream/stream-chat-swiftui/pull/911)
78

89
# [4.84.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.84.0)
910
_August 07, 2025_

Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/AddUsersView.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,12 @@ public struct AddUsersView<Factory: ViewFactory>: View {
9292
.padding()
9393
}
9494
}
95+
96+
/// Options used in the add users view.
97+
public struct AddUsersOptions {
98+
public let loadedUsers: [ChatUser]
99+
100+
public init(loadedUsers: [ChatUser]) {
101+
self.loadedUsers = loadedUsers
102+
}
103+
}

Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/ChatChannelInfoView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ public struct ChatChannelInfoView<Factory: ViewFactory>: View, KeyboardReadable
124124
.accessibilityAction {
125125
viewModel.addUsersShown = false
126126
}
127-
AddUsersView(
128-
factory: factory,
129-
loadedUserIds: viewModel.participants.map(\.id),
127+
128+
factory.makeAddUsersView(
129+
options: .init(loadedUsers: viewModel.participants.map(\.chatUser)),
130130
onUserTap: viewModel.addUserTapped(_:)
131131
)
132132
}

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,13 @@ extension ViewFactory {
11431143
public func makeThreadListDividerItem() -> some View {
11441144
Divider()
11451145
}
1146+
1147+
public func makeAddUsersView(
1148+
options: AddUsersOptions,
1149+
onUserTap: @escaping (ChatUser) -> Void
1150+
) -> some View {
1151+
AddUsersView(loadedUserIds: options.loadedUsers.map(\.id), onUserTap: onUserTap)
1152+
}
11461153
}
11471154

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

Sources/StreamChatSwiftUI/ViewFactory.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,4 +1171,15 @@ public protocol ViewFactory: AnyObject {
11711171
associatedtype ThreadListDividerItem: View
11721172
/// Creates the thread list divider item.
11731173
func makeThreadListDividerItem() -> ThreadListDividerItem
1174+
1175+
associatedtype AddUsersViewType: View
1176+
/// Creates a view for adding users to a chat or channel.
1177+
/// - Parameters:
1178+
/// - options: Configuration options for the "add users" view, such as loaded user ids.
1179+
/// - onUserTap: A closure that is called when a `ChatUser` is tapped in the list.
1180+
/// - Returns: The view shown in the add users slot.
1181+
func makeAddUsersView(
1182+
options: AddUsersOptions,
1183+
onUserTap: @escaping (ChatUser) -> Void
1184+
) -> AddUsersViewType
11741185
}

StreamChatSwiftUITests/Tests/Utils/ViewFactory_Tests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,20 @@ class ViewFactory_Tests: StreamChatTestCase {
10291029
// Then
10301030
XCTAssert(view is GalleryHeaderView)
10311031
}
1032+
1033+
func test_viewFactory_makeAddUsersView() {
1034+
// Given
1035+
let viewFactory = DefaultViewFactory.shared
1036+
1037+
// When
1038+
let view = viewFactory.makeAddUsersView(
1039+
options: .init(loadedUsers: []),
1040+
onUserTap: { _ in }
1041+
)
1042+
1043+
// Then
1044+
XCTAssert(view is AddUsersView<DefaultViewFactory>)
1045+
}
10321046
}
10331047

10341048
extension ChannelAction: Equatable {

0 commit comments

Comments
 (0)