Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ public struct ParticipantAvatarStack: View {
self.participants = participants
}

private var visibleParticipants: [UserInfo] {
Array(participants.prefix(3))
}

private var overflowCount: Int {
// This will be used if we need to show +N indicator in the future
max(0, participants.count - 3)
}

public var body: some View {
HStack(spacing: -overlap) {
ForEach(Array(participants.enumerated()), id: \.element.id) { index, participant in
ForEach(Array(visibleParticipants.enumerated()), id: \.element.id) { index, participant in
UserAvatar(
user: participant.user,
size: avatarSize
Expand All @@ -29,9 +33,22 @@ public struct ParticipantAvatarStack: View {
.strokeBorder(Color.white.opacity(0.3), lineWidth: 1)
)
.shadow(color: .black.opacity(0.1), radius: 1, x: 0, y: 0.5)
.zIndex(Double(participants.count - index))
.zIndex(Double(index))
}

if self.overflowCount > 0 {
Text("+\(self.overflowCount, format: .number.notation(.compactName))")
.font(.system(size: 6, design: .rounded).weight(.semibold).width(.compressed))
.foregroundStyle(.white)
.frame(width: self.avatarSize, height: self.avatarSize)
.background(.accent.gradient, in: .circle)
.overlay(
Circle()
.strokeBorder(Color.white.opacity(0.3), lineWidth: 1)
)
.shadow(color: .black.opacity(0.1), radius: 1, x: 0, y: 0.5)
.zIndex(Double(4))
}
}
.padding(.horizontal, 8)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ private struct ParticipantsButton: View {
}

private var buttonWidth: CGFloat {
let count = visibleParticipants.count
let width = CGFloat(count) * 24 - CGFloat(max(0, count - 1)) * 6 + 8
let count = self.visibleParticipants.count == 3 ? 4 : self.visibleParticipants.count
let width = CGFloat(count) * 24 - CGFloat(max(0, count - 1)) * 6
return max(32, width)
}

Expand All @@ -415,7 +415,7 @@ private struct ParticipantsButton: View {
.frame(width: buttonWidth)
.opacity(0)
.overlay {
ParticipantAvatarStack(participants: visibleParticipants)
ParticipantAvatarStack(participants: self.participants)
}
}
}
Expand Down