1.0.8 • Published 2 years ago

react-native-otp-input-fields-suzan v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-native-otp-input-fields

This is a component for OTP Input fields.

Installation

npm i react-native-otp-input-fields

NOTE: This package uses react-native-reanimated under the hood for animation. Please Follow the installation process of React Native Reanimated

Usage

Below are some examples to use this package

Basic Usage

import OTPInput from "react-native-otp-input-fields";

const [OTP, SetOTP] = useState("");
// Maintain a state variable

// Use it like this
<OTPInput onChangeText={SetOTP} value={OTP} />;

Password Secure Usage

import OTPInput from "react-native-otp-input-fields";

const [OTP, SetOTP] = useState("");
// Maintain a state variable

// Use it like this
<OTPInput onChangeText={SetOTP} value={OTP} secureTextEntry={true} />;

Change Colors and other styles

import OTPInput from "react-native-otp-input-fields";

const [OTP, SetOTP] = useState("");
// Maintain a state variable

// Use it like this
<OTPInput
  onChangeText={SetOTP}
  value={OTP}
  borderColor="orange"
  boxBackgroundColor="dodgerblue"
  cursorColor="orange"
  digitColor="white"
/>;

Apply Elevation and Border Radius etc.

import OTPInput from "react-native-otp-input-fields";

const [OTP, SetOTP] = useState("");
// Maintain a state variable

// Use it like this
<OTPInput
  onChangeText={SetOTP}
  value={OTP}
  boxBorderRadius={50}
  onlyBorderBottom={false}
  boxElevation={10}
/>;

Parameters

Basic Parameters

ParameterrequiredDefaultDescription
valueYESMaintain a state in parent component and use it as a controlled input
onChangeTextYESthe onChangeText function to update the state in parent component
countNO6Number of digits in the OTP
autoFocusNOfalseWhether to autofocus the first field
removeOnBackspaceNOtrueWhether to clear the previous input while pressing the backspace button on a input field
onSubmitEditingNOfunction to execute when user presses the done button on keyboard
containerWidthNOscreenWidthWidth of the Input Field Container
boxHeightNO60Height of each input field
marginNO5margin between each input field

Customization

ParameterrequiredDefaultDescription
secureTextEntryNOfalseMask the text input as password field or not
allowDigitsOnlyNOfalseAllow only digits to be entered in the text input
digitFontSizeNO25font size of the text inside input field
animateDurationNO300msDuration for the animation to complete when input field is focused
cursorColorNOblackcolor of the blinking cursor
digitColorNOblackcolor of the digit inside the field
onlyBorderBottomNOtruewhether to show border around whole box or just the border bottom
keyboardTypeNOtruetype of Keyboard from KeyboardTypeOptions in react-native
borderBottomWidthNO3width for the border bottom of box
borderColorNOblackcolor for the border of box
boxElevationNO6elevation for the input field box
maxLengthNO1Max length of each input field
inputStyleNOstyles for the TextInput component
boxHeightNO60height of each input field
boxBorderRadiusNO0border Radius of input field
boxContainerStyleNOstyles for the input containers
containerStyleNOstyles for the whole input box container (outer)
boxBackgroundColorNOwhitebackround Color of the input fields