Appears that it's well known issue/feature that still exists.
Stack Overflow - https://stackoverflow.com/questions/63934037/swiftui-navigationlink-cell-in-a-form-stays-highlighted-after-detail-pop/67282150#67282150
The problem for me was that I had other SwiftUI view located between NavigationView and List and that issue arises. Don't know why, but if that view would be moved below List then the row is deselected without problem when returning from child view. But I found solution that fixed this behaviour.
Added to that SwiftUI view that is between NavigationView and List, .zIndex() modifier that must be higher than for the List and now rows is deselected correctly.
struct MostPopularView: View {
var body: some View {
VStack(alignment: .leading, spacing: 20) {
SelectPeriodView()
.padding(.horizontal)
.onChange(of: mostPopularViewModel.selectedPeriod, perform: { _ in
self.loadData()
})
.zIndex(1.0)
List(mostPopularViewModel.articles) { article in
NavigationLink(
destination: ArticleView(article: article),
label: {ArticleListItem(article: article)})
}
}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: