New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-native-otp-entry

Package Overview
Dependencies
Maintainers
0
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-otp-entry

A fully modifiable OTP Input Component for React Native

  • 1.8.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

react-native-otp-entry

npm version npm install size cov License

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.

Demo

Features

  • Simple and easy-to-use OTP input component.
  • Highly customizable appearance and styling.
  • Supports autofill
  • Effortlessly integrates with React Native, Expo, and React Native Web platforms.
  • Fully typed with TypeScript.
  • Fully covered with unit tests.
  • Paste functionality.

Demo

Try out React Native OTP Entry in action on Snack Expo:

Snack Expo App

or https://snack.expo.dev/@anday013/demo-react-native-otp-entry

Installation

Install react-native-otp-entry using npm or yarn:

npm install react-native-otp-entry

# or

yarn add react-native-otp-entry

Usage

  1. Import the OtpInput component from react-native-otp-entry:

    import { OtpInput } from "react-native-otp-entry";
    
  2. Render the OtpInput component in your screen/component:

    <OtpInput numberOfDigits={6} onTextChange={(text) => console.log(text)} />
    
  3. Customize the styling as per your requirements:

    <OtpInput
      numberOfDigits={6}
      focusColor="green"
      autoFocus={false}
      hideStick={true}
      placeholder="******"
      blurOnFilled={true}
      disabled={false}
      type="numeric"
      secureTextEntry={false}
      focusStickBlinkingDuration={500}
      onFocus={() => console.log("Focused")}
      onBlur={() => console.log("Blurred")}
      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,
        placeholderTextStyle: styles.placeholderText,
        filledPinCodeContainerStyle: styles.filledPinCodeContainer,
        disabledPinCodeContainerStyle: styles.disabledPinCodeContainer,
      }}
    />
    

Props

The react-native-otp-entry component accepts the following props:

PropTypeDescription
numberOfDigitsnumberThe number of digits to be displayed in the OTP entry.
themeThemeCustom styles for each element. (See below)
textInputPropsTextInputPropsExtra props passed to underlying hidden TextInput (see: https://reactnative.dev/docs/textinput)
autoFocusbooleanDefault: true. Sets autofocus.
focusColorColorValueThe color of the input field border and stick when it is focused.
placeholderstringPlaceholder value to the input.
onTextChange(text: string) => voidA callback function is invoked when the OTP text changes. It receives the updated text as an argument.
onFilled(text: string) => voidA callback function is invoked when the OTP input is fully filled. It receives a full otp code as an argument.
blurOnFilledbooleanDefault: false. Blurs (unfocuses) the input when the OTP input is fully filled.
hideStickbooleanDefault: false. Hides cursor of the focused input.
focusStickBlinkingDurationnumberThe duration (in milliseconds) for the focus stick to blink.
disabledbooleanDefault: false. Disables the input
type'alpha' | 'numeric' | 'alphanumeric'The type of input. 'alpha': letters only, 'numeric': numbers only, 'alphanumeric': letters or numbers.
secureTextEntrybooleanDefault: false. Obscures the text entered so that sensitive text like PIN stay secure.
onFocus() => voidA callback function is invoked when the OTP input is focused.
onBlur() => voidA callback function is invoked when the OTP input is blurred.
ThemeTypeDescription
containerStyleViewStyleCustom styles for the root View.
pinCodeContainerStyleViewStyleCustom styles for the container that wraps each individual digit in the OTP entry.
pinCodeTextStyleTextStyleCustom styles for the text within each individual digit in the OTP entry.
placeholderTextStyleTextStyleCustom styles for the placeholder text within each individual digit in the OTP entry.
focusStickStyleViewStyleCustom styles for the focus stick, which indicates the focused input field.
focusedPinCodeContainerStyleViewStyleCustom styles for the input field when it is focused.
filledPinCodeContainerStyleViewStyleCustom styles for the input field when it has a value.
disabledPinCodeContainerStyleViewStyleCustom 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.

Theme

Ref

The react-native-otp-entry component exposes these functions with ref:

PropTypeDescription
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.

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 :)

Support Me

If you find this project helpful and want to support my work, consider buying me a coffee! ☕

Buy Me a Coffee

Keywords

FAQs

Package last updated on 21 Dec 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc