I am building a chatting app: I have InboxView
and MessagesView
, to put it simply both are listening to a @Published
variable called chats
. When user sends a message in MessagesView
, the ranking of inbox changes and because InboxView
is listening to updates to chats @Published
variable it redraws its views, regardless if the view is hidden! I am assuming this is some SwiftUI eager drawing optimization. Cool.
Now the problem is that InboxView
has a List
of NavigationLink
s, which means during this redraw the NavigationLink
somehow resets its state and navigates the user back! Or even worse, pushes the user back to the same chat, again. You can see an example setup here, but what's missing is the data source.
I can't rely on onAppear
or onDisappear
because they are called as if the user navigates back to the view, so InboxView
thinks it's being presented!