ios – The way to use @FocusState in a customized TextField


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

    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)
} }

After which in my View, bind it collectively like this:

@FocusState var focusedField: EmailLoginState.FieldType?

 textual content: withViewStore.binding(.$e-mail), .username, .emailAddress, $focusedField, 
 focusCondition: .e-mail)


Leave a Reply

Your email address will not be published. Required fields are marked *