How to initiate and immediately open your very first channel from noChannelsView with SwiftUI?

Viewed 36

Im using getStream ChatChannelListView to present all channels. But when there is no chats im overriding ViewFactory makeNoChannelsView with my custom noChannelsView that has button to initiate chat.

As my noChannelsView is embeded in NavigationView its destination is ChatChannel but as soon as I try to fetchOneChannel and open it, noChatsView starts transition to ChatChannel and at the middle of that transition whole noChannelsView is being replaced with ChatChannelListView and then I need to mannualy enter my chosen channel.

1 Answers

For a use-case like this you can use the ChatChannelListView and aside from your custom ViewFactory also hand it a selectedChannelId in form of a String.

Code looks like this:

var body: some View {
    ChatChannelListView(
        viewFactory: MyViewFactory(),
        selectedChannelId: "channel-id"
    )
}

In order to make this dynamic, you can use a @Binding for the selectedChannelId and update this once the channel is created in order to directly show the Channel UI.

Let me know if you still have questions, we are also recommending this technique for deep linking as you can see in our documentation.

Best, Stefan

Related