A gesture password component for React Native (web). It supports both iOS, Android and Web since it's written in pure JavaScript.
一个React Native的手势密码组件,纯JavaScript实现,因此同时支持iOS、安卓和Web平台。
npm install react-native-gesture-password --save
npm install prop-types --save
All properties bellow are optional.
The message text you want to show. NOTE: If you leave this blank, no message appears for any state changes.
Can be 'normal', 'right' or 'wrong'.
The gesture password don't validate your password. You should do that yourself, and tell the result by status.
Styles for the gesture password view.
Style for the text element in the view.
Use this color to render the default circle color.
Use this color to render when status !== 'wrong'.
Use this color to render when status === 'wrong'.
True for transparent line.
The active circles will be reset automatically after you give an interval.
Allow cross the circles(eg: 1 -> 7 -> 4), default is false.
Event raised when user touch a number circle.
Event raised when user finish input a password.
Event raised after the reset interval has cleared circles. Can be used to reset message.
Other components that you want to display.
Control whether to draw outer and inner circle, true default.
var React = require('react');
var {
AppRegistry,
} = require('react-native');
var PasswordGesture = require('react-native-gesture-password');
var Password1 = '';
var AppDemo = React.createClass({
// Example for check password
onEnd: function(password) {
if (password == '123') {
this.setState({
status: 'right',
message: 'Password is right, success.'
});
// your codes to close this view
} else {
this.setState({
status: 'wrong',
message: 'Password is wrong, try again.'
});
}
},
onStart: function() {
this.setState({
status: 'normal',
message: 'Please input your password.'
});
},
onReset: function() {
this.setState({
status: 'normal',
message: 'Please input your password (again).'
});
},
// Example for set password
/*
onEnd: function(password) {
if ( Password1 === '' ) {
// The first password
Password1 = password;
this.setState({
status: 'normal',
message: 'Please input your password secondly.'
});
} else {
// The second password
if ( password === Password1 ) {
this.setState({
status: 'right',
message: 'Your password is set to ' + password
});
Password1 = '';
// your codes to close this view
} else {
this.setState({
status: 'wrong',
message: 'Not the same, try again.'
});
}
}
},
onStart: function() {
if ( Password1 === '') {
this.setState({
message: 'Please input your password.'
});
} else {
this.setState({
message: 'Please input your password secondly.'
});
}
},
*/
getInitialState: function() {
return {
message: 'Please input your password.',
status: 'normal'
}
},
render: function() {
return (
<PasswordGesture
ref='pg'
status={this.state.status}
message={this.state.message}
onStart={() => this.onStart()}
onEnd={(password) => this.onEnd(password)}
/>
);
}
});
AppRegistry.registerComponent('AppDemo', () => AppDemo);
- Prettier: best practices for Format documents
- Performance: Increase performance by using React hooks
- Declaration
- Readme: this package work with react-native-web well
(@hosseinmd)
Rewrite with ES6 for React-Native@v0.25+ support
Add outerCircle and innerCircle properties
TextStyle and onReset event. (@caledhwa)
Manage the adaptation to landscape orientation. (@jujumoz)
Add the allowCross property.
Improve the performance for real device.
Rewrite in pure javascript, for Android support.
This old version(<0.1.0) is at the branch native. I won't update that unless fix bugs.
If you have suggestions or bug reports, feel free to send pull request or create new issue.