List row stay selected after back

Hi,

I found a case that cause a list to never deselect the row when the back button is pressed.

In the following code I modally present a list. When you select a row another list is displayed. If you select a row of the second list and you go back the row will stay selected.

This is the code:
Code Block
struct ContentView: View {
@State var modalVisible = false
var body: some View {
Button(action:{
self.modalVisible.toggle()
}) {
Text("Open modal")
}
.sheet(isPresented: $modalVisible) {
NavigationView {
List {
NavigationLink("Item", destination: List {
NavigationLink("Sub Item", destination: Text("If you go back the row will stay selected."))
})
                }
            }
        }
    }
}


Does anyone know if there is a way to force the list to deselect the row when the back button is pressed?

Thank you


We're having the same issue. The same exact cells don't have this issue elsewhere in our app when the view containing the list isn't presented modally. Very interested in seeing what the solution is.
May have a look here on how to select an item.
https://stackoverflow.com/questions/60139184/swiftui-navigationlink-macos-default-selected-state

Similar principle should allow to deselect all as well.

See also this other thread:
https://developer.apple.com/forums/thread/663562
List row stay selected after back
 
 
Q