This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
SecureField A SwiftUI SecureField component for password input.
Recommended version:
~56.0.26
Expo UI SecureField matches the official SwiftUI SecureField API and provides a text field that masks user input for passwords and other sensitive text.
Installation
- npx expo install @expo/ui
- yarn expo install @expo/ui
- pnpm expo install @expo/ui
- bun expo install @expo/ui
If you are installing this in an existing React Native app , make sure to install expo in your project.
Usage
Basic secure field
BasicSecureFieldExample.tsx import { useState } from 'react' ;
import { Host , SecureField } from '@expo/ui/swift-ui' ;
export default function BasicSecureFieldExample ( ) {
const [ password, setPassword] = useState ( '' ) ;
return (
< Host matchContents >
< SecureField placeholder = " Password" onTextChange = { setPassword} />
</ Host >
) ;
}
Submit handling
Use the submitLabel and onSubmit modifiers to handle form submission from the keyboard.
SecureFieldSubmitExample.tsx import { useState } from 'react' ;
import { Host , SecureField } from '@expo/ui/swift-ui' ;
import { submitLabel, onSubmit } from '@expo/ui/swift-ui/modifiers' ;
export default function SecureFieldSubmitExample ( ) {
const [ password, setPassword] = useState ( '' ) ;
return (
< Host matchContents >
< SecureField
placeholder = " Password"
onTextChange = { setPassword}
modifiers = { [ submitLabel ( 'done' ) , onSubmit ( ( ) => console . log ( 'Login submitted' ) ) ] }
/>
</ Host >
) ;
}
Imperative ref
Use a ref to imperatively set text, focus, or blur the secure field.
ImperativeSecureFieldExample.tsx import { useRef } from 'react' ;
import { Host , SecureField , SecureFieldRef , Button , HStack , VStack } from '@expo/ui/swift-ui' ;
import { buttonStyle } from '@expo/ui/swift-ui/modifiers' ;
export default function ImperativeSecureFieldExample ( ) {
const ref = useRef < SecureFieldRef> ( null ) ;
return (
< Host matchContents >
< VStack >
< SecureField ref = { ref} placeholder = " Password" />
< HStack spacing = { 12 } >
< Button
modifiers = { [ buttonStyle ( 'bordered' ) ] }
onPress = { ( ) => ref. current ?. focus ( ) }
label = " Focus"
/>
< Button
modifiers = { [ buttonStyle ( 'bordered' ) ] }
onPress = { ( ) => ref. current ?. blur ( ) }
label = " Blur"
/>
< Button
modifiers = { [ buttonStyle ( 'bordered' ) ] }
onPress = { ( ) => ref. current ?. setText ( 'secret123' ) }
label = " Set Text"
/>
</ HStack >
</ VStack >
</ Host >
) ;
}
API
import { SecureField } from '@expo/ui/swift-ui' ;
No API data file found, sorry!