stream-chat-swiftui
stream-chat-swiftui copied to clipboard
Remove / Make-Optional the root NavigationView
What are you trying to achieve?
ChatChannelListView
has its body
content wrapped inside a NavigationView
. Without writing a completely custom ChatChannelListView
, it is currently impossible to push this view onto an existing navigation stack. It would be nice if this NavigationView
wrapping was optional.
If possible, how can you achieve this currently?
It's impossible to push the ChatChannelListView
onto any existing navigation stack in SwiftUI. If you do, SwiftUI presents all subsequently pushed content with two(!) navigation bars. Yuck! 🤮
The easiest "workaround" is to present the ChatChannelListView
as a sheet
. But that's unfortunate because chat experiences don't usually lend themselves to modal-style presentations.
Another potential workaround is to completely re-implement the entire ChatChannelListView
yourself. Also, not a great option if you're trying to plug it in and go.
What would be the better way?
I understand the importance of having the NavigationView
as the root view for ease-of-use, but it may be invaluable to provide an additional hook for ViewFactory
subclasses. Separating out the enclosed content from the NavigationView
and allowing a ViewFactory
to specify the root behavior would solve this issue while maintaining ease-of-use.
So instead of this (current implementation):
public var body: some View {
NavigationView {
channelListViewContent() // Just using this pseudo-function to stand in for the actual contents
}
}
You might have something like this:
public var body: some View {
if viewModel.embedInNavView == true {
NavigationView {
channelListViewContent()
}
} else {
channelListViewContent()
}
}
Possible solution in PR #220
GetStream Environment
GetStream Chat version: 4.22.0 GetStream Chat frameworks: StreamChat, StreamChatSwiftUI iOS version: 16.0 Swift version: 5.7 Xcode version: 14.0.1 Device: iPhone 14 Pro
Additional context
N/A
Hey @Sam-Spencer,
Thanks for reporting. As discussed, this will be handled with https://github.com/GetStream/stream-chat-swiftui/pull/220.
Best, Martin