

Simple and fully modifiable OTP Input Component for React Native
source link: https://reactnativeexample.com/simple-and-fully-modifiable-otp-input-component-for-react-native/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

react-native-otp-entry
react-native-otp-entry
is a simple and highly customizable React Native component for entering OTP (One-Time Password). It provides an intuitive and user-friendly interface for inputting one-time passwords in your React Native applications.
Features
- Supports OTP input with a fixed number of digits.
- Highly customizable appearance and styling.
- Supports autofill
- Seamless integration with React Native and Expo applications.
Installation
Install react-native-otp-entry
using npm or yarn:
npm install react-native-otp-entry
# or
yarn add react-native-otp-entry
Usage
-
Import the
OTPInput
component fromreact-native-otp-entry
:import { OTPInput } from 'react-native-otp-entry';
-
Render the
OTPInputView
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" onTextChange={text => console.log(text)} containerStyle={styles.container} inputsContainerStyle={styles.inputsContainer} pinCodeContainerStyle={styles.pinCodeContainer} pinCodeTextStyle={styles.pinCodeText} focusStickStyle={styles.focusStick} focusStickBlinkingDuration={500} />
Props
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. |
focusColor |
ColorValue | The color of the input field border and stick when it is focused. |
onTextChange |
(text: string) => void | A callback function that is invoked when the OTP text changes. It receives the updated text as an argument. |
theme |
Theme | Custom styles for each element. |
focusStickBlinkingDuration |
number | The duration (in milliseconds) for the focus stick to blink. |
Theme | Type | Description |
---|---|---|
containerStyle |
ViewStyle | Custom styles for the root View . |
inputsContainerStyle |
ViewStyle | Custom styles for the container that holds the input fields. |
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. |
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.
The react-native-otp-entry
component exposes these functions with ref
:
Prop | Type | Description |
---|---|---|
clear |
() => void; | Clears the value of the OTP input. |
setValue |
(value: string) => void; | Sets the value of the OTP input. |
License
This project is licensed under the MIT License.
Contributing
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 🙂
GitHub
Recommend
-
5
react-native-datefield A simple React Native date input component. Installation yarn add react-native-d...
-
11
react-native-checkbox-flex Fully customizable, easy to use checkbox with flexible component by React Native on Android and iOS
-
13
Onboarding A simple and fully customizable React Native onboarding component A...
-
28
rnv-date-range-picker A simple and fully customizable React Native date range picker component. Installing: npm install rnv-date-range-picker yarn add rnv-date-range-picker
-
14
react-native-text-input-interactive Fully customizable, animated text input for React Native with beautiful and elegant design.
-
6
react-native-intl-phone-field React Native text input for validating international phone numbers, built on top of libphonenumber by Google using
-
7
React-Native-Custom-Switch A lightweight, fully customizable switch component for React Native. Installation npm install react-native-custom-switch Usage import CustomSwitch fr...
-
7
Input Prompt component with single input field for react native Jun 13, 2022 1 min read
-
7
📱 React Native Numeric Pad 📱 A React Native component for amount or verification code input. It easily handles both decimals and integers, and runs smoothly for both IOS and Android. The design is simple and clear with numbers, dot, and o...
-
5
react-native-toastable 🍞 Blazingly fast and fully customizable Toaster component for React Native Supports queuinge, so you can display multiple toasts in succession without having to worry about them overlapping or interferi...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK