Skip to content

Instantly share code, notes, and snippets.

@iosdevie
Created June 9, 2021 08:17
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 iosdevie/415728c7de0e111dd3c02bbee18db092 to your computer and use it in GitHub Desktop.
Save iosdevie/415728c7de0e111dd3c02bbee18db092 to your computer and use it in GitHub Desktop.
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