Skip to content

Best way to handle isSecureTextEntry #72

@moyoteg

Description

@moyoteg

I created this ViewModifier but when initially shown the text is not presented as isSecureTextEntry == true even though isSecure is true. Any idea why?! thanks! 😄

struct SecureToggle: ViewModifier {

        @State public var isSecure: Bool = true
        
        public func body(content: Content) -> some View {
            
            HStack {
                content
                    .introspectTextField { (textfield) in
                        textfield.isSecureTextEntry = isSecure
                    }
                
                Spacer()
                
                Button(action: {
                    self.isSecure.toggle()
                }) {
                    Image(systemName: isSecure ? "eye.slash":"eye")
                        .foregroundColor(Color.Nikola.lightBlue)
                }
                .padding()
            }
        }
        
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting-replyThis issue needs more information.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions