Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ public struct ChatChannelInfoView<Factory: ViewFactory>: View, KeyboardReadable

public init(
factory: Factory = DefaultViewFactory.shared,
viewModel: ChatChannelInfoViewModel? = nil,
channel: ChatChannel,
shownFromMessageList: Bool = false
) {
_viewModel = StateObject(
wrappedValue: ChatChannelInfoViewModel(channel: channel)
wrappedValue: viewModel ?? ChatChannelInfoViewModel(channel: channel)
)
self.factory = factory
self.shownFromMessageList = shownFromMessageList
Expand Down Expand Up @@ -52,7 +53,8 @@ public struct ChatChannelInfoView<Factory: ViewFactory>: View, KeyboardReadable
ChatInfoParticipantsView(
factory: factory,
participants: viewModel.displayedParticipants,
onItemAppear: viewModel.onParticipantAppear(_:)
onItemAppear: viewModel.onParticipantAppear(_:),
selectedParticipant: $viewModel.selectedParticipant
)
}

Expand Down Expand Up @@ -84,14 +86,10 @@ public struct ChatChannelInfoView<Factory: ViewFactory>: View, KeyboardReadable
viewModel.leaveGroupAlertShown = true
}
.alert(isPresented: $viewModel.leaveGroupAlertShown) {
let title = viewModel.leaveButtonTitle
let message = viewModel.leaveConversationDescription
let buttonTitle = viewModel.leaveButtonTitle

return Alert(
title: Text(title),
message: Text(message),
primaryButton: .destructive(Text(buttonTitle)) {
Alert(
title: Text(viewModel.leaveButtonTitle),
message: Text(viewModel.leaveConversationDescription),
primaryButton: .destructive(Text(viewModel.leaveButtonTitle)) {
viewModel.leaveConversationTapped {
presentationMode.wrappedValue.dismiss()
if shownFromMessageList {
Expand All @@ -106,11 +104,11 @@ public struct ChatChannelInfoView<Factory: ViewFactory>: View, KeyboardReadable
}
}
.overlay(
viewModel.addUsersShown ?
popupShown ?
Color.black.opacity(0.3).edgesIgnoringSafeArea(.all) : nil
)
.blur(radius: viewModel.addUsersShown ? 6 : 0)
.allowsHitTesting(!viewModel.addUsersShown)
.blur(radius: popupShown ? 6 : 0)
.allowsHitTesting(!popupShown)

if viewModel.addUsersShown {
VStack {
Expand All @@ -131,6 +129,17 @@ public struct ChatChannelInfoView<Factory: ViewFactory>: View, KeyboardReadable
)
}
}

if let selectedParticipant = viewModel.selectedParticipant {
ParticipantInfoView(
participant: selectedParticipant,
actions: viewModel.participantActions(for: selectedParticipant)
) {
withAnimation {
viewModel.selectedParticipant = nil
}
}
Comment on lines +134 to +141
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we create a slot here so that customers can override the ParticipantInfoView?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think we should not, we don't expose much slots here. We can in the future, if there's enough interest.

}
}
.toolbarThemed {
ToolbarItem(placement: .principal) {
Expand Down Expand Up @@ -170,4 +179,8 @@ public struct ChatChannelInfoView<Factory: ViewFactory>: View, KeyboardReadable
.dismissKeyboardOnTap(enabled: viewModel.keyboardShown)
.background(Color(colors.background).edgesIgnoringSafeArea(.bottom))
}

private var popupShown: Bool {
viewModel.addUsersShown || viewModel.selectedParticipant != nil
}
}
Loading
Loading