React Native学习React-Native 开发阵营登录

React Native 之 手势密码

2018-01-31  本文已影响583人  IT界的段子手
手势密码效果图


import {
    StyleSheet,
    View,
    Text,
    TextInput,
    Alert
} from "react-native";

import PasswordGesture from './gesturePassword/index'
let Password1 = '';

export default class GesturePassword extends BaseComponent {
    constructor(props) {
        super(props);
        this.state = {
            message: '请绘制解锁图案',
            status: 'normal',
            timeOut: 300,
        }
    }

    render() {
        const {state}=this.props.navigation;
        return (
            <View>
                <NavigationBar rightText="" rightClick={() => {
                }}>{state.params.gesturePawText}</NavigationBar>
                <PasswordGesture
                    ref='pg'
                    status={this.state.status}
                    message={this.state.message}
                    onStart={() => this.onStart()}
                    onEnd={(password) => this.onEnd(password)}
                    innerCircle={true}
                    outerCircle={true}
                    interval={this.state.timeOut}
                />
            </View>
        )
    }

    onEnd(password) {
        const {timeOut}=this.state;
        if (Password1 === '') {
            // The first password
            Password1 = password;
            if (timeOut) {
                this.time = setTimeout(() => {
                    this.setState({
                        status: 'normal',
                        message: '请再次绘制解锁图案',
                    });
                }, timeOut)
            }
        } else {
            // The second password
            if (password === Password1) {
                this.setState({
                    status: 'right',
                    message: '您的密码是' + password,
                });

                Password1 = '';
            } else {
                this.setState({
                    status: 'wrong',
                    message: '密码错误, 请再次输入.',
                });
            }
        }
    }

    onStart() {
        if (Password1 === '') {
            this.setState({
                message: '请绘制解锁图案',
            });
        } else {
            this.setState({
                message: '请再次绘制解锁图案',
            });
        }
        if (this.state.timeOut) {
            clearTimeout(this.time);
        }
    }
}

重置手势密码效果图

重置的流程:

流程图

(眼尖的同学可能看出了两幅图样式不太一致,因为第一幅图还没正式开发 ... )

上一篇下一篇

猜你喜欢

热点阅读