ios – The way to use @FocusState in a customized TextField
[ad_1]
I’ve this Customized View that has a Textfield
and I need to use the iOS15’s FocusState
. Since I can not entry the Textfield
immediately, I need to cross it by the init()
operate as follows. However the init
operate would not appear to compile, any clues?
struct CustomTextfieldView: View {
@Binding var textual content: String
let focusCondition: FieldType
@FocusState non-public var focusState: FieldType
enum FieldType: Hashable {
case e-mail
case password
case none
}
init(
textual content: Binding<String>,
_ focusCondition: FieldType,
_ focus: FocusState<FieldType?>,
) {
self._text = textual content
self.focusCondition = focusCondition // Error is right here
self._focusState = focus
}
var physique: some View {
HStack {
TextField(placeholder, textual content: $textual content)
.centered($focusState, equals: focusCondition)
.submitLabel(.subsequent)
Spacer()
}
} }
After which in my View, bind it collectively like this:
@FocusState var focusedField: EmailLoginState.FieldType?
CustomTextfieldView(LoginStrings.e-mail,
textual content: withViewStore.binding(.$e-mail), .username, .emailAddress, $focusedField,
focusCondition: .e-mail)
[ad_2]