Issues with .scrollPosition in iOS17

I suppose that .scrollPosition doesn't work at current XCode version (Version 15.0 (15A240d)

Variable scrollID just does not update in any situation. Can anyone get this problem, too?

    
    @State var scrollID: TestStruct?
    
    var data: [TestStruct] = [
    TestStruct(name: "123", price: "34555"),
    TestStruct(name: "432", price: "543"),
    TestStruct(name: "423", price: "23"),
    TestStruct(name: "523", price: "543")
    ]
    
    var body: some View {
        
        VStack {
            ScrollView(.horizontal) {
                HStack {
                    ForEach (data) { item in
                        VStack {
                            Text(item.name)
                            Text(item.price)
                        }
                        .containerRelativeFrame(.horizontal)
                    }
                }
                .scrollTargetLayout()
            }
            .scrollTargetBehavior(.paging)
            .scrollPosition(id: $scrollID)
            
            Text("test: \(scrollID?.name ?? "NONE")")
        }
    }
}

struct TestStruct: Identifiable, Hashable {
    let id: String = UUID().description
    let name: String
    let price: String
}

I think you need stable identifiers. Don't use UUID() but try to create them manually (e.g. based on name)

Krajeec, thanks a lot. Your suggest helps me to resolve my problem

Issues with .scrollPosition in iOS17
 
 
Q