Created
October 23, 2023 15:44
-
-
Save kodekarim/1c12473570aeb2867cda9e6dc2e59a6c to your computer and use it in GitHub Desktop.
ScrollViewReader Auto Scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // 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