Git Product home page Git Product logo

react-native-otp-inputs's Introduction

react-native-otp-inputs

CircleCI

codecov

npm npm

Demo

Demo

Description

react-native-otp-inputs is fully customizable, pure JavaScript package, that provides solution for One-time password feature with user friendly events like moving to previous input with backspace or going to next when filled in. It supports pasting and otp code into inputs

Installation

React-Native version installation
>= 0.53.0 < 0.57.0 yarn add [email protected]
<= 0.57.0 yarn add [email protected]
<= 0.59.0 yarn add react-native-otp-inputs

Android additional steps

Android setup requires react-native-keyevent package to work properly.

  1. Add react-native-keyevent to your dependencies with
yarn add react-native-keyevent
  1. If you are using react-native < 0.60.0 then follow these steps
  2. If you are using react-native >= 0.60.0 then add this to your dependencies in react-native.config.js
'react-native-keyevent': {
      platforms: {
        ios: null,
      },
    },
  1. Then follow configuration for Android here (If you have problems, check Example App configuration)

Basic usage

import React, { Component } from 'react';
import { View } from 'react-native';
import OtpInputs from 'react-native-otp-inputs';

export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>
        <OtpInputs handleChange={code => console.log(code)} numberOfInputs={6} />
      </View>
    );
  }
}

API

Method Type Required Default Description
autoCapitalize string false 'none'
clearTextOnFocus boolean false false
handleChange function true console.log Returns otp code.
keyboardType string true 'phone-pad'
numberOfInputs number true (1..6) 4 Inputs count to render.
secureTextEntry boolean false false
selectTextOnFocus boolean false true iOS Only
testIDPrefix string false otpInput-${inputIndex} Prefix for testID.
isRTL boolean false false Preferably I18nManager.isRTL.
placeholder string false none Placeholder for the input boxes.
styles style (object) false default Applied to whole container.
focusStyles style (object) false default Applied to the input on focus.
inputStyles style(object) false default Applied to single input.
inputContainerStyles style (object) false default Applied to each input container.
...restTextInputProps TextInput

Methods

Those can be called on ref:

Method Description
reset Reset inputs and returns to handleChange method empty string

Example

import React, { Component } from 'react';
import { Button, View } from 'react-native';
import OtpInputs from 'react-native-otp-inputs';

export default class App extends Component {
  otpRef = React.createRef();

  resetOTP = () => {
    this.otpRef.current.reset();
  };

  render() {
    return (
      <View style={styles.container}>
        <Button title="Reset" onPress={this.resetOTP} />
        <OtpInputs ref={this.otpRef} handleChange={code => console.log(code)} numberOfInputs={6} />
      </View>
    );
  }
}

Contributors

Great thanks to : @kantorm.

react-native-otp-inputs's People

Contributors

dependabot-preview[bot] avatar kantorm avatar pixelize avatar vish2595 avatar dependabot[bot] avatar vinitkadam avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.