SwiftUI NavigationView pops view by itself immediately on iOS 15

Viewed 453

I have a simple use case where a screen pushes another screen using the NavigationLink that is part of List element populated by a ForEach. The pushed screen is popped just after being pushed. This is working just fine on iOS 14.x, but not on iOS 15. Dose anyone know any workaround for this issue? Or any other solution how to fix this?

Here is a sample code:

List {
   ForEach(dataToPopulateListFrom, id: \.id) { data in
      NavigationLink(destination: SomeView()
                                    .environmentObject(someEnviorementObject)
                                    .navigationBarTitle("", displayMode: .inline)) {
         SomeOtherView()
      }
   }
}
1 Answers

I'm seeing something similar, except it's happening when trying to pop a second view onto the stack from the detail view accessed by a list.

It seems the parent view is being redrawn multiple times leading to multiple separate instances of the parent view existing. Can you try adding output to the 'onAppear' method to the view containing the list, and see if it's being called multiple times?

My experience trying to maintain a project in SwiftUI has been absolutely abysmal, something is completely broken on every minor iOS point release. To anyone considering starting a project using SwiftUI, I categorically do not recommend it.

Related