Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-otp-textinput

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-otp-textinput

Textview usable for OTP implementation

  • 1.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
decreased by-5.86%
Maintainers
1
Weekly downloads
 
Created
Source

REACT NATIVE OTP TEXT INPUT

React Native Component that can used for OTPs and Pins as secure pin input.

npm version npm downloads

Installation
npm i -S react-native-otp-textinput
Demo


How to Use

Check the Example react native app for usage.

Platform Support

Supports both Android and iOS.

Props

The following props are applicable for the component along with props supported by react native TextInput component

PropTypeOptionalDefaultDescription
defaultValuestringYes''Default Value that can be set based on OTP / Pin received from parent container.
handleTextChangefuncNon/acallback with concated string of all cells as argument.
handleCellTextChangefuncYesn/acallback for text change in individual cell with cell text and cell index as arguments
inputCountnumberYes4Number of Text Input Cells to be present.
tintColorstringYes#3CB371Color for Cell Border on being focused.
offTintColorstringYes#DCDCDCColor for Cell Border Border not focused.
inputCellLengthnumberYes1Number of character that can be entered inside a single cell.
containerStyleobjectYes{}style for overall container.
textInputStyleobjectYes{}style for text input.
testIDPrefixstringYes'otpinput'testID prefix, the result will be otp_input_0 until inputCount
autoFocusboolYesfalseInput should automatically get focus when the components loads
Helper Functions

Clearing and Setting values to component

// using traditional ref
clearText = () => {
    this.otpInput.clear();
}

setText = () => {
    this.otpInput.setValue("1234");
}

render() {
    return (
        <View>
            <OTPTextInput ref={e => (this.otpInput = e)} >
            <Button title="clear" onClick={this.clearText}>
        </View>
    );
}
// hooks
import React, { useRef } from 'react';

const ParentComponent = () => {
    let otpInput = useRef(null);

    const clearText = () => {
        otpInput.current.clear();
    }

    const setText = () => {
        otpInput.current.setValue("1234");
    }

    return (
        <View>
            <OTPTextInput ref={e => (otpInput = e)} >
            <Button title="clear" onClick={clearText}>
        </View>
    );
}
If you like the project

If you think I have helped you, feel free to get me coffee. 😊

Buy Me A Coffee

Keywords

FAQs

Package last updated on 04 Jun 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