|
| 1 | +# react-native-confirmation-code-input |
| 2 | +A react-native confirmation code input for both IOS and Android |
| 3 | + |
| 4 | +## Features |
| 5 | +- A user-friendly component for inputting confirmation code |
| 6 | +- Extended from [<TextInput/>](https://facebook.github.io/react-native/docs/textinput.html) component, so you can use its props |
| 7 | +- Built-in type of code input: underline, box, circle |
| 8 | +- Set position: center, left, right, fill width |
| 9 | +- Set size and active color, inactive color |
| 10 | +- Easy to customize style, use base style from TextInput component |
| 11 | +- Check code on finish or return code for async checking |
| 12 | +- Clear code on fail |
| 13 | +- Use React Native ES6 |
| 14 | +## Screenshots |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +```sh |
| 24 | +npm install react-native-confirmation-code-input --save |
| 25 | +``` |
| 26 | + |
| 27 | +## Usage |
| 28 | +### Basic |
| 29 | +Import this module: |
| 30 | +```javascript |
| 31 | +import CodeInput from 'react-native-confirmation-code-input'; |
| 32 | +``` |
| 33 | +Use as a component and style it: |
| 34 | +```javascript |
| 35 | + |
| 36 | +render() { |
| 37 | + return ( |
| 38 | + <CodeInput |
| 39 | + ref="codeInputRef1" |
| 40 | + secureTextEntry |
| 41 | + className={'border-b'} |
| 42 | + space={5} |
| 43 | + size={30} |
| 44 | + inputPosition='left' |
| 45 | + onFulfill={(code) => this._onFulfill(code)} |
| 46 | + /> |
| 47 | + |
| 48 | + <CodeInput |
| 49 | + ref="codeInputRef2" |
| 50 | + secureTextEntry |
| 51 | + compareWithCode='AsDW2' |
| 52 | + activeColor='rgba(49, 180, 4, 1)' |
| 53 | + inactiveColor='rgba(49, 180, 4, 1.3)' |
| 54 | + autoFocus={false} |
| 55 | + ignoreCase={true} |
| 56 | + inputPosition='center' |
| 57 | + size={50} |
| 58 | + onFulfill={(isValid) => this._onFinishCheckingCode1(isValid)} |
| 59 | + containerStyle={{ marginTop: 30 }} |
| 60 | + codeInputStyle={{ borderWidth: 1.5 }} |
| 61 | + /> |
| 62 | + |
| 63 | + <CodeInput |
| 64 | + ref="codeInputRef2" |
| 65 | + keyboardType="numeric" |
| 66 | + codeLength={5} |
| 67 | + className='border-circle' |
| 68 | + compareWithCode='12345' |
| 69 | + autoFocus={false} |
| 70 | + codeInputStyle={{ fontWeight: '800' }} |
| 71 | + onFulfill={(isValid, code) => this._onFinishCheckingCode2(isValid, code)} |
| 72 | + /> |
| 73 | + ) |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +### Customization |
| 78 | + |
| 79 | +### Properties |
| 80 | +This component uses the same props as [<TextInput/>](https://facebook.github.io/react-native/docs/textinput.html). Below are additional props for this component: |
| 81 | + |
| 82 | +Prop | Type | Default | Description |
| 83 | +---------- | ------- | ---------- | ----------------------- |
| 84 | +`codeLength` | number | 5 | length of confirmation code -> number of cells |
| 85 | +`compareWithCode` | string | | code to compare. if null, onFulfill callback return inputted code to check later |
| 86 | +`inputPosition` | string | `center` | position of code input in its container |
| 87 | +`size` | number | 40 | size of input cells |
| 88 | +`space` | number | 8 | space between 2 cells |
| 89 | +`className` | string | `border-box` | Some built-in classname: `border-box`, `border-circle`, `border-b`, `border-b-t`, `border-l-r` |
| 90 | +`cellBorderWidth` | number | 1.0 | width of cell borders |
| 91 | +`activeColor` | string | `rgba(255, 255, 255, 1)` | color of cells when active |
| 92 | +`inactiveColor` | string | `rgba(255, 255, 255, 0.2)` | color of cells when inactive |
| 93 | +`ignoreCase` | boolean | `false` | ignore case when checking code |
| 94 | +`autoFocus` | boolean | `true` | auto focus on code input |
| 95 | +`codeInputStyle` | style object | | custom style for code input |
| 96 | +`containerStyle` | style object | | custom style for code input container |
| 97 | +`onFulfill` | function | | callback function called when fulfilling code. If `compareWithCode` is null -> return `(code)` in callback, else return `(isValid, code)`. **Required** |
| 98 | + |
| 99 | +## Example |
| 100 | +See [EXAMPLE](example) |
| 101 | + |
| 102 | +## License |
| 103 | + |
| 104 | +react-native-confirmation-code-input is released under the MIT license. See [LICENSE](LICENSE) for details. |
| 105 | + |
| 106 | +Any question or support will welcome. |
0 commit comments