A react-native confirmation code field compatible with iOS, Android and Web Platforms (based on this project Migration Guide)
- 🔮 Simple. Easy to use;
- 🍎 Support "fast paste SMS-code" on iOS. And custom code paste for Android;
- 🚮 Clearing part of the code by clicking on the cell;
- ⚡
blur()
andfocus()
methods; - 🛠 Extendable and hackable;
- 🤓 Readable changelog.
- API documentation
- Examples
- Live demos iOS / Android, react-native-web
yarn add react-native-confirmation-code-field
# or
npm install react-native-confirmation-code-field
import React, { Component } from 'react';
import CodeInput from 'react-native-confirmation-code-field';
class App extends Component {
handlerOnFulfill = code => console.log(code);
render() {
return <CodeInput onFulfill={this.handlerOnFulfill} />;
}
}
Paste code can helpful for Android platform when you can read SMS.
import React, { Component, createRef } from 'react';
import CodeInput from 'react-native-confirmation-code-field';
class App extends Component {
handlerOnFulfill = code => {
if (isValidCode(code)) {
console.log(code);
} else {
this.clearCode();
}
};
field = createRef();
clearCode() {
const { current } = this.field;
if (current) {
current.clear();
}
}
pasteCode() {
const { current } = this.field;
if (current) {
current.handlerOnTextChange(value);
}
}
render() {
return <CodeInput ref={this.field} onFulfill={this.handlerOnFulfill} />;
}
}
This component consists of:
- Container
<View {...containerProps}/>
; - Render the "Cells" for the text code inside the container ("Cells" is
<TextInput {...cellProps} />
); - And over this render invisible
<TextInput {...inputProps}/>
; - "Cursor" inside cell is simulated component