Skip to content

Instantly share code, notes, and snippets.

@kodekarim
Created October 23, 2023 15:44
Show Gist options
  • Save kodekarim/1c12473570aeb2867cda9e6dc2e59a6c to your computer and use it in GitHub Desktop.
Save kodekarim/1c12473570aeb2867cda9e6dc2e59a6c to your computer and use it in GitHub Desktop.
ScrollViewReader Auto Scroll
//
// ContentView.swift
// autoScroll
//
// Created by abdul karim on 23/10/23.
//
import SwiftUI
struct ContentView: View {
@State var inputtext:String = ""
var body: some View {
ScrollViewReader { proxy in
VStack {
List(0..<100, id: \.self) { i in
Text("Item \(i)")
.id(i)
}
HStack {
TextField("Jump to", text: $inputtext)
.padding(.leading, 20 )
Button("Jump") {
proxy.scrollTo(Int(inputtext))
}
.padding(20)
}
}
}
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment