Reading time: 1 min
This recipe shows how to navigate from one text field to another using keyboard buttons in SwiftUI by combining
onSubmit. The end result looks like this:
The recipe goes as following:
- Declare an enum that holds aliases for focusable fields. In the code below, that's
Reading time: 2 min
Detecting if a text field gained or lost focus is not entirely straightforward in SwiftUI.
TextField constructor has a parameter named
onEditingChanged, but it triggers only when the user taps the return key in the virtual keyboard, not when the focus is actually lost.