Created
April 24, 2024 15:55
-
-
Save cutiko/550ba1a6b613542eea81bf3e35d1f86d to your computer and use it in GitHub Desktop.
Swift UI Dynamic focus for forms
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
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