4.0.0-alpha.1.1 • Published 5 years ago

@quanle94/react-native-otp-inputs v4.0.0-alpha.1.1

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

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 versioninstallation
>= 0.53.0 < 0.57.0yarn add react-native-otp-inputs@1.1.0
<= 0.57.0yarn add react-native-otp-inputs@3.2.2
<= 0.59.0yarn add react-native-otp-inputs

Migration to v4

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

MethodTypeRequiredDefaultDescription
autoCapitalizestringfalse'none'
clearTextOnFocusbooleanfalsefalse
handleChangefunctiontrueconsole.logReturns otp code.
keyboardTypestringtrue'phone-pad'
numberOfInputsnumbertrue (1..6)4Inputs count to render.
secureTextEntrybooleanfalsefalse
selectTextOnFocusbooleanfalsetrue iOS Only
testIDPrefixstringfalseotpInput-\${inputIndex}Prefix for testID.
isRTLbooleanfalsefalsePreferably I18nManager.isRTL.
placeholderstringfalsenonePlaceholder for the input boxes.
stylesstyle (object)falsedefaultApplied to whole container.
focusStylesstyle (object)falsedefaultApplied to the input on focus.
inputStylesstyle(object)falsedefaultApplied to single input.
inputContainerStylesstyle (object)falsedefaultApplied to each input container.
...restTextInputPropsTextInput

Methods

Those can be called on ref:

MethodDescription
resetReset 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.