I have the following code working to scroll to a given item. But the combination of ScrollView + LazyStackview doesn't give me proper selection highlighting, like a List would. So my questions are:
is there a way to scroll a List to a specific item, i.e. can I use ScrollViewReader with Lists?
is there a way to emulate the row highlighting which you press on the cell? And to abort selection in the default way by scrolling a bit?
Code Block SwiftUI struct ContentView: View { let timezones = TimeZone.knownTimeZoneIdentifiers.map { TimeZone(identifier: $0)! } var body: some View { let continents = Set(timezones.compactMap { $0.continent }).sorted() ScrollView { ScrollViewReader { value in LazyVStack(alignment: .leading, spacing: 5, pinnedViews: [.sectionHeaders]) { ForEach(continents, id: \.self) { continent in let continentTZ = timezones.filter { $0.continent == continent} Section(header: HeaderView(title: continent)) { ForEach(continentTZ) { timezone in Button(action: { // this will dismiss the selection }) { VStack { TimeZoneCell(timezone: timezone) Divider() } } } } } }.onAppear() { value.scrollTo(TimeZone.current.identifier, anchor: .center) } } }.navigationBarTitle(Text("Time Zones"), displayMode: .inline) } }