Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting channel from list no longer navigates to that channel if parent View of ChatChannelListView updates #606

Open
lukeadamson opened this issue Sep 19, 2024 · 1 comment

Comments

@lukeadamson
Copy link

lukeadamson commented Sep 19, 2024

What did you do?

See commit lukeadamson@8bd7df2 of fork https://github.com/lukeadamson/stream-chat-swiftui

I've made a small change to your demo app which shows how to reproduce the issue. Run demo app, select a channel from the list, tap Back, tap the "Break" toolbar button, then try to select a channel. You can see the channel row highlight (as expected) when you tap it, but the app doesn't navigate to the selected channel.

CleanShot 2024-09-19 at 15 03 44

What did you expect to happen?

I expect that tapping a channel in the list will always navigate to the selected channel, even if the view which embeds the ChatChannelListView updates (re-revaluates its body for some reason).

What happened instead?

You can still select a channel in the list, but the app won't navigate to that channel.

GetStream Environment

GetStream Chat version:
See fork.

GetStream Chat frameworks: StreamChat, StreamChatSwiftUI

iOS version:
Reproduced on iOS 17 and 18

Swift version:
Default included with Xcode 16.0

Xcode version:
Xcode 16.0

Device:
Fails on the iPhone 16 Pro Simulator as well as on devices running iOS 17 and 18.

Additional context

We have an app where we've embedded the ChatChannelListView in a "Chat" tab alongside our other functionality, but when something else in our app causes a higher-level view update, the user can no longer navigate to channels in the Chat tab.

I've confirmed that the selected channel is changing (the view model updates), but the Binding that propagates that change downward to the NavigationLink appears to stop working.

@laevandus
Copy link
Contributor

Hi @lukeadamson,

Thank you for creating this issue. I have reviewed it and I will need to do changes to the SDK for making this to work. The core problem is that the default onTapItem captures the view model instances created in the view's init, not the one stored by the @StateObject.

There is a workaround which is to add .id(isBroken) (or any other custom view identity which is derived from the internal state) to theChatChannelListView for forcing SwiftUI to create a brand new view and therefore updating @StateObject stored view model.

I'll create an internal issue and include a fix for the next release. We will update this issue when a new version has been released. For now, feel free to use the workaround.

Best,
Toomas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants