
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
react-native-otp-entry
Advanced tools
react-native-otp-entry
is a simple and highly customizable React Native component for entering OTP (One-Time Password) on iOS, Android, and Web. It provides an intuitive and user-friendly interface for inputting one-time passwords in your React Native applications.
Try out React Native OTP Entry in action on Snack Expo:
or https://snack.expo.dev/@anday013/demo-react-native-otp-entry
Install react-native-otp-entry
using npm or yarn:
npm install react-native-otp-entry
# or
yarn add react-native-otp-entry
Import the OtpInput
component from react-native-otp-entry
:
import { OtpInput } from "react-native-otp-entry";
Render the OtpInput
component in your screen/component:
<OtpInput numberOfDigits={6} onTextChange={(text) => console.log(text)} />
Customize the styling as per your requirements:
<OtpInput
numberOfDigits={6}
focusColor="green"
focusStickBlinkingDuration={500}
onTextChange={(text) => console.log(text)}
onFilled={(text) => console.log(`OTP is ${text}`)}
textInputProps={{
accessibilityLabel: "One-Time Password",
}}
theme={{
containerStyle: styles.container,
pinCodeContainerStyle: styles.pinCodeContainer,
pinCodeTextStyle: styles.pinCodeText,
focusStickStyle: styles.focusStick,
focusedPinCodeContainerStyle: styles.activePinCodeContainer,
}}
/>
The react-native-otp-entry
component accepts the following props:
Prop | Type | Description |
---|---|---|
numberOfDigits | number | The number of digits to be displayed in the OTP entry. |
textInputProps | TextInputProps | Extra props passed to underlying hidden TextInput (see: https://reactnative.dev/docs/textinput) |
autoFocus | boolean | Default: true. Sets autofocus. |
focusColor | ColorValue | The color of the input field border and stick when it is focused. |
onTextChange | (text: string) => void | A callback function is invoked when the OTP text changes. It receives the updated text as an argument. |
onFilled | (text: string) => void | A callback function is invoked when the OTP input is fully filled. It receives a full otp code as an argument. |
blurOnFilled | boolean | Default: false. Blurs (unfocuses) the input when the OTP input is fully filled. |
hideStick | boolean | Default: false. Hides cursor of the focused input. |
theme | Theme | Custom styles for each element. |
focusStickBlinkingDuration | number | The duration (in milliseconds) for the focus stick to blink. |
disabled | boolean | Default: false. Disables the input |
type | 'alpha' | 'numeric' | 'alphanumeric' | The type of input. 'alpha': letters only, 'numeric': numbers only, 'alphanumeric': letters or numbers. |
secureTextEntry | boolean | Default: false. Obscures the text entered so that sensitive text like PIN stay secure. |
onFocus | () => void | A callback function is invoked when the OTP input is focused. |
onBlur | () => void | A callback function is invoked when the OTP input is blurred. |
Theme | Type | Description |
---|---|---|
containerStyle | ViewStyle | Custom styles for the root View . |
pinCodeContainerStyle | ViewStyle | Custom styles for the container that wraps each individual digit in the OTP entry. |
pinCodeTextStyle | TextStyle | Custom styles for the text within each individual digit in the OTP entry. |
focusStickStyle | ViewStyle | Custom styles for the focus stick, which indicates the focused input field. |
focusedPinCodeContainerStyle | ViewStyle | Custom styles for the input field when it is focused. |
filledPinCodeContainerStyle | ViewStyle | Custom styles for the input field when it has a value. |
disabledPinCodeContainerStyle | ViewStyle | Custom styles for the input field when it is disabled. |
Note: The ViewStyle
and TextStyle
types are imported from react-native
and represent the style objects used in React Native for views and text, respectively.
Tip: If you have difficulties while applying gap
or in any other style property to set a suitable space between the OTP input containers, please set the width
in containerStyle
to 'auto'
or undefined
, as it is been set to '100%'
by default.
The react-native-otp-entry
component exposes these functions with ref
:
Prop | Type | Description |
---|---|---|
clear | () => void; | Clears the value of the OTP input. |
focus | () => void; | Focus of the OTP input. |
setValue | (value: string) => void; | Sets the value of the OTP input. |
This project is licensed under the MIT License.
Contributions are welcome! Please feel free to open issues or submit pull requests.
If you find a bug or have any feature requests, please open an issue :)
If you find this project helpful and want to support my work, consider buying me a coffee! ☕
FAQs
A fully modifiable OTP Input Component for React Native
The npm package react-native-otp-entry receives a total of 56,904 weekly downloads. As such, react-native-otp-entry popularity was classified as popular.
We found that react-native-otp-entry demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.