前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >React Native手势密码组件

React Native手势密码组件

作者头像
forrest23
发布2018-08-03 15:26:37
8280
发布2018-08-03 15:26:37
举报

本文原创首发于公众号:ReactNative开发圈,转载需注明出处。

这次介绍的React Native手势密码组件为react-native-gesture-password,纯JavaScript实现,同时支持iOS和安卓平台。

效果图

安装

npm install react-native-gesture-password--save

属性

所有的属性都是可选的。现在列举几个重要属性。

message (string)

给用户的提示信息,如请输入手势密码,手势密码不准确等此类消息。

status (string)

状态为:'normal', 'right' or 'wrong’.验证手势密码是否准确是需要自己在onEnd事件中来判断的。

onStart (function)

当用户开始输入手势密码时触发。

onEnd (function)

当用户结束输入手势密码时触发。

示例

代码语言:javascript
复制
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);

组件地址

详细说明和示例代码请查看GitHub:https://github.com/Spikef/react-native-gesture-password。点击阅读原文可以直接打开GitHub。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2017-11-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 ReactNative开发圈 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 效果图
  • 安装
  • 属性
    • message (string)
      • status (string)
        • onStart (function)
          • onEnd (function)
          • 示例
          • 组件地址
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档