@FocusState
In practice, this will most often be associated with users clicking on TextFields. In this video, we will first learn what Focus State is and then review a few real-world implementations! As a bonus, we will also check out Apple's documentation on this new feature.
Setup
There’s no systematic way to click the textfield other than clicking the text field.
FocuseState
We create a boolean of usernameInFocus
We bind the variable with the TextField, so whenever the text field is triggered, the boolean value switches.
Button to switch the FocusState
by adding a toggle function to switch the boolean value, now we can open up the keyboard by clicking the button.
Showing keyboard by .onAppear
Means, after 0.5 seconds, usernameInFocus turns to true
Change the focus state
constant usernameIsValid is not empty (!username.isEmpty)
if those two constants are true (constants aren’t empty), then print “SIGN UP”)
if only the username isn’t empty, open the password, and vice versa