Skip to content

Add avatar customization in add users popup #787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

# Upcoming

### 🔄 Changed
### ✅ Added
- Add avatar customization in add users popup [#787](https://github.com/GetStream/stream-chat-swiftui/pull/787)

# [4.74.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.74.0)
_March 14, 2025_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,47 @@ import StreamChat
import SwiftUI

/// View for the add users popup.
struct AddUsersView: View {
struct AddUsersView<Factory: ViewFactory>: View {

@Injected(\.fonts) private var fonts
@Injected(\.colors) private var colors

private static let columnCount = 4
private static let itemSize: CGFloat = 64

private let columns = Array(
repeating:
GridItem(
.adaptive(minimum: itemSize),
.adaptive(minimum: 64),
alignment: .top
),
count: columnCount
count: 4
)

private let factory: Factory

@StateObject private var viewModel: AddUsersViewModel
var onUserTap: (ChatUser) -> Void

init(
factory: Factory = DefaultViewFactory.shared,
loadedUserIds: [String],
onUserTap: @escaping (ChatUser) -> Void
) {
_viewModel = StateObject(
wrappedValue: AddUsersViewModel(loadedUserIds: loadedUserIds)
)
self.onUserTap = onUserTap
self.factory = factory
}

init(
factory: Factory = DefaultViewFactory.shared,
viewModel: AddUsersViewModel,
onUserTap: @escaping (ChatUser) -> Void
) {
_viewModel = StateObject(
wrappedValue: viewModel
)
self.onUserTap = onUserTap
self.factory = factory
}

var body: some View {
Expand All @@ -57,17 +60,20 @@ struct AddUsersView: View {
onUserTap(user)
} label: {
VStack {
MessageAvatarView(
avatarURL: user.imageURL,
size: CGSize(width: Self.itemSize, height: Self.itemSize),
showOnlineIndicator: false
let itemSize: CGFloat = 64
let userDisplayInfo = UserDisplayInfo(
id: user.id,
name: user.name ?? "",
imageURL: user.imageURL,
size: CGSize(width: itemSize, height: itemSize)
)
factory.makeMessageAvatarView(for: userDisplayInfo)

Text(user.name ?? user.id)
.multilineTextAlignment(.center)
.lineLimit(2)
.font(fonts.footnoteBold)
.frame(width: Self.itemSize)
.frame(width: itemSize)
.foregroundColor(Color(colors.text))
}
.padding(.all, 8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public struct ChatChannelInfoView<Factory: ViewFactory>: View, KeyboardReadable
viewModel.addUsersShown = false
}
AddUsersView(
factory: factory,
loadedUserIds: viewModel.participants.map(\.id),
onUserTap: viewModel.addUserTapped(_:)
)
Expand Down
Loading