Imagine a view with some @Binding
variables:
init(isEditing: Binding<Bool>, text: Binding<Bool>)
How can we have the selection
working with an internal @State
if it is not provided in the initializer?
init(text: Binding<Bool>)
This is how to make TextField become first responder in SwiftUI
Note that I know we can pass a constant
like:
init(isEditing: Binding<Bool> = .constant(false), text: Binding<Bool>)
But!
This will kill the dynamicity of the variable and it won't work as desire. Imagine re-inventing the isFirstResponder
of the UITextField
.
- It can't be
.constant(false)
. The keyboard will be gone on each view update. - It can't be
.constant(true)
. The view will take the keyboard on each view update.
Maybe! Apple is doing it somehow with TabView
.