stream-chat-swiftui icon indicating copy to clipboard operation
stream-chat-swiftui copied to clipboard

Remove / Make-Optional the root NavigationView

Open Sam-Spencer opened this issue 2 years ago • 1 comments

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

Sam-Spencer avatar Oct 17 '22 21:10 Sam-Spencer

Hey @Sam-Spencer,

Thanks for reporting. As discussed, this will be handled with https://github.com/GetStream/stream-chat-swiftui/pull/220.

Best, Martin

martinmitrevski avatar Oct 18 '22 08:10 martinmitrevski