From what I can see of your code, when you pop back from a navigation link, your ContentView gets rebuilt. The first thing done in ContentView is to create new list data. So, you are creating a new List and since it is new, it has no "remembered" scroll position, so it seems to scroll to the top. The truth is, it has nothing else to display except from the top. In addition, none of your NavigationLink (item views) has an .id so the list has no way of tracking where you are, even if it was smart enough to track.
The new .scrollPosition($savedPosition) could help, but for some reason, it only seems to work with a ScrollView directly, and not within a container with an embedded ScrollView (i.e., `List).
So, some suggestions:
Do not create the data for your List inside your ContentView. Create it onAppear on within the init() and save it in a @State. The List should pick up where it left off (I haven't tried this with your example, but I think that's the standard behavior I've seen). Even if this doesn't work, the following suggestions should help (iOS 17+)...
Add .id(item) to your ``NavigationLink`. Let it be trackable!
Add a @State variable for savedPosition (of type String?) , change your List to a ScrollView { LazyVStack { ForEach { .... } } } and attach a .savedPosition to the ScrollView (iOS 17+):
ScrollView {
LazyVStack {
ForEach($items, id: \.self) {
NavigationLink {
Text(item)
} label: {
Text(item)
}
.id(item)
}
}
.scrollTargetLayout()
}
.scrollPosition($savedPosition)