4

I am working with a navigationView with swiftUI. My problem is whenever I go to another view with a Navlink and the observedObject of the root of my navigationView changes, my interface come back to the root view also.

So my question is : Is there a way to tell the observedObject Of the root of the navigationView to stop updating the UI when I navigate to a navLink ?

The root of my navigationView: listChatViewModel is an Observable object and recentMessages is a Published Property

NavigationView{

            ScrollView(.vertical, showsIndicators: false){
                VStack(spacing : 6){
                    //Recent
                    ForEach(listChatViewModel.recentMessages){recentMessage in
                        NavigationLink(destination: ChatView(ChatViewModel(myUserId : self.session.session!.uid, userId : recentMessage.senderProfile!.user_id))) {
                            RecentCellView(recentMessage: recentMessage)
                        }
                    }
                    .padding()

                }

            }
            .navigationBarTitle("Chat", displayMode: .inline)
            .navigationBarItems(leading:
                Image("logo_black").resizable().frame(width: 32.0, height: 32.0)
            )
        }

When I am in the ChatView and that the recentMessages property updates, this make me go back to the root view

sofiane_dv
  • 71
  • 7
  • It sounds like problem not in ObservedObject but in depending views configuration. Would you show your root view code? – Asperi Mar 21 '20 at 09:00
  • 1
    I think you may want to check this out https://stackoverflow.com/questions/58302913/swiftui-navigationlink-pops-immediately-if-used-within-foreach/58305884#58305884 – gujci Mar 21 '20 at 09:47

0 Answers0