SwiftUI List .scrollPosition not working

Hi, I am trying to read in which section in a list the user is currently located and want to scroll him to a specific section. Therefore I would like to use the new .scrollPosition modifier. Best would be the ability to implement the same snapping effect from ScrollView.

So I used this snippet:

struct Item: Identifiable{
    var id: Int
    
    static func getMany() -> [Item] {
        var items = [Item]()
        for i in 0..<100 {
            items.append(Item(id: i))
        }
        return items
    }
}

struct ContentView: View {
    @State var items = Item.getMany()
    @State var scrolledID: Item.ID?
    
    var body: some View {
        NavigationStack {
            List {
                ForEach(items) { item in
                    ItemView(item: item)
                }
            }
            .scrollTargetLayout()
            .scrollPosition(id: $scrolledID)
            .navigationTitle("Hello, \(scrolledID ?? 0)")
        }
    }
}

struct ItemView: View {
    var item: Item
    var body: some View {
        Text("Hello world, \(item)")
    }
}

Doesn't work.

So I tried to place the modifiers in different places in the code to attack several different parts of the list as the "scrollTargetLayout" - but this doesn't change anything here.

Isn't the List View just the Form inside a ScrollView?! This doesn't work either. If I place the Form OR List inside a ScrollView, the contents of the list aren't displayed anymore. This seems logical, because the list is a LazyVStack rendering without a height, as it doesn't know its final height. Can we fix this somehow?

@itmhof .scrollPosition(_:anchor:) doesn't currently work with a List. Please file an enhancement request via Feedback Assistant and post the Feedback ID number here for the record.

You could use a ScrollViewReader
and use the proxy’s scrollTo(_:anchor:) to perform scrolling to a particular id in a List

@DTS Engineer thanks for your response. I will check that tomorrow. Is there a way to GET the current scrollstate using this method? it would be very important for our usecase! or is there ANY way to have a List inside a scrollview? i dont care about performance, I have only 7 items per week and the weeks are paginated differently. I just want the user to be able to select a day and SEE which day they are at!

SwiftUI List .scrollPosition not working
 
 
Q