From cc5657b8e03bcc698cfa63a8948148f5acc72eae Mon Sep 17 00:00:00 2001 From: martinmitrevski Date: Wed, 19 Jun 2024 09:58:23 +0200 Subject: [PATCH] Fixed dismissing the channel when leaving a group --- .../ChatChannel/ChannelInfo/ChatChannelInfoView.swift | 3 +-- Sources/StreamChatSwiftUI/ChatChannel/ChatChannelView.swift | 5 +++++ .../ChatChannelList/ChatChannelListViewModel.swift | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/ChatChannelInfoView.swift b/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/ChatChannelInfoView.swift index 3825dc80..95f27a44 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/ChatChannelInfoView.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/ChatChannelInfoView.swift @@ -84,10 +84,9 @@ public struct ChatChannelInfoView: View, KeyboardReadable { message: Text(message), primaryButton: .destructive(Text(buttonTitle)) { viewModel.leaveConversationTapped { + presentationMode.wrappedValue.dismiss() if shownFromMessageList { notifyChannelDismiss() - } else { - presentationMode.wrappedValue.dismiss() } } }, diff --git a/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelView.swift b/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelView.swift index 8d236de9..17f994c1 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelView.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelView.swift @@ -159,6 +159,11 @@ public struct ChatChannelView: View, KeyboardReadable { .onReceive(keyboardWillChangePublisher, perform: { visible in keyboardShown = visible }) + .onReceive(NotificationCenter.default.publisher( + for: NSNotification.Name(dismissChannel) + ), perform: { _ in + presentationMode.wrappedValue.dismiss() + }) .onAppear { viewModel.onViewAppear() if utils.messageListConfig.becomesFirstResponderOnOpen { diff --git a/Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListViewModel.swift b/Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListViewModel.swift index 41e8b25c..2b9c523d 100644 --- a/Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListViewModel.swift @@ -435,7 +435,7 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController } } -private let dismissChannel = "io.getstream.dismissChannel" +internal let dismissChannel = "io.getstream.dismissChannel" private let hideTabBarNotification = "io.getstream.hideTabBar"