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