Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
enum CurrentField{
case field1
case field2
}
struct TextFieldFocus: View {
@State var field1 = ""
@State var field2 = ""
@FocusState var activeState: CurrentField?
var body: some View {
VStack{
TextField("Email", text: $field1)
.focused($activeState, equals: .field1)
.submitLabel(.continue)
SecureField("Password", text: $field2)
.focused($activeState, equals: .field2)
.submitLabel(.send)
Button("Goto Email") {
activeState = .field1
}
Button("Goto Password") {
activeState = .field2
}
}
.padding()
.textFieldStyle(.roundedBorder)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment