Skip to content

Commit 5fc1b8d

Browse files
Add participant actions in channel info view (#982)
1 parent 4e4438e commit 5fc1b8d

14 files changed

+838
-47
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
### ✅ Added
77
- Opens the `commandsHandler` and makes the mention methods public [#979](https://github.com/GetStream/stream-chat-swiftui/pull/979)
88
- Opens `MarkdownFormatter` so that it can be customised [#978](https://github.com/GetStream/stream-chat-swiftui/pull/978)
9+
- Add participant actions in channel info view [#982](https://github.com/GetStream/stream-chat-swiftui/pull/982)
910

1011
### 🐞 Fixed
1112
- Fix openChannel not working when searching or another chat shown [#975](https://github.com/GetStream/stream-chat-swiftui/pull/975)

Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/ChatChannelInfoView.swift

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ public struct ChatChannelInfoView<Factory: ViewFactory>: View, KeyboardReadable
2020

2121
public init(
2222
factory: Factory = DefaultViewFactory.shared,
23+
viewModel: ChatChannelInfoViewModel? = nil,
2324
channel: ChatChannel,
2425
shownFromMessageList: Bool = false
2526
) {
2627
_viewModel = StateObject(
27-
wrappedValue: ChatChannelInfoViewModel(channel: channel)
28+
wrappedValue: viewModel ?? ChatChannelInfoViewModel(channel: channel)
2829
)
2930
self.factory = factory
3031
self.shownFromMessageList = shownFromMessageList
@@ -52,7 +53,8 @@ public struct ChatChannelInfoView<Factory: ViewFactory>: View, KeyboardReadable
5253
ChatInfoParticipantsView(
5354
factory: factory,
5455
participants: viewModel.displayedParticipants,
55-
onItemAppear: viewModel.onParticipantAppear(_:)
56+
onItemAppear: viewModel.onParticipantAppear(_:),
57+
selectedParticipant: $viewModel.selectedParticipant
5658
)
5759
}
5860

@@ -84,14 +86,10 @@ public struct ChatChannelInfoView<Factory: ViewFactory>: View, KeyboardReadable
8486
viewModel.leaveGroupAlertShown = true
8587
}
8688
.alert(isPresented: $viewModel.leaveGroupAlertShown) {
87-
let title = viewModel.leaveButtonTitle
88-
let message = viewModel.leaveConversationDescription
89-
let buttonTitle = viewModel.leaveButtonTitle
90-
91-
return Alert(
92-
title: Text(title),
93-
message: Text(message),
94-
primaryButton: .destructive(Text(buttonTitle)) {
89+
Alert(
90+
title: Text(viewModel.leaveButtonTitle),
91+
message: Text(viewModel.leaveConversationDescription),
92+
primaryButton: .destructive(Text(viewModel.leaveButtonTitle)) {
9593
viewModel.leaveConversationTapped {
9694
presentationMode.wrappedValue.dismiss()
9795
if shownFromMessageList {
@@ -106,11 +104,11 @@ public struct ChatChannelInfoView<Factory: ViewFactory>: View, KeyboardReadable
106104
}
107105
}
108106
.overlay(
109-
viewModel.addUsersShown ?
107+
popupShown ?
110108
Color.black.opacity(0.3).edgesIgnoringSafeArea(.all) : nil
111109
)
112-
.blur(radius: viewModel.addUsersShown ? 6 : 0)
113-
.allowsHitTesting(!viewModel.addUsersShown)
110+
.blur(radius: popupShown ? 6 : 0)
111+
.allowsHitTesting(!popupShown)
114112

115113
if viewModel.addUsersShown {
116114
VStack {
@@ -131,6 +129,17 @@ public struct ChatChannelInfoView<Factory: ViewFactory>: View, KeyboardReadable
131129
)
132130
}
133131
}
132+
133+
if let selectedParticipant = viewModel.selectedParticipant {
134+
ParticipantInfoView(
135+
participant: selectedParticipant,
136+
actions: viewModel.participantActions(for: selectedParticipant)
137+
) {
138+
withAnimation {
139+
viewModel.selectedParticipant = nil
140+
}
141+
}
142+
}
134143
}
135144
.toolbarThemed {
136145
ToolbarItem(placement: .principal) {
@@ -170,4 +179,8 @@ public struct ChatChannelInfoView<Factory: ViewFactory>: View, KeyboardReadable
170179
.dismissKeyboardOnTap(enabled: viewModel.keyboardShown)
171180
.background(Color(colors.background).edgesIgnoringSafeArea(.bottom))
172181
}
182+
183+
private var popupShown: Bool {
184+
viewModel.addUsersShown || viewModel.selectedParticipant != nil
185+
}
173186
}

0 commit comments

Comments
 (0)