Skip to content

Instantly share code, notes, and snippets.

@cutiko
Created April 24, 2024 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cutiko/550ba1a6b613542eea81bf3e35d1f86d to your computer and use it in GitHub Desktop.
Save cutiko/550ba1a6b613542eea81bf3e35d1f86d to your computer and use it in GitHub Desktop.
Swift UI Dynamic focus for forms
struct ContentView: View {
@FocusState private var focusedInput: Inputs?
@State private var firstInput = ""
@State private var secondInput = ""
var body: some View {
VStack {
TextField("FIRST", text: $firstInput)
.focused($focusedInput, equals: .firstInput)
.onSubmit {
focusedInput = .secondInput
}
TextField("SECOND", text: $secondInput)
.focused($focusedInput, equals: .secondInput)
}
.padding()
}
}
private enum Inputs {
case firstInput
case secondInput
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment