From 6b6218fb39e44fccf81ce160b5060df1076af159 Mon Sep 17 00:00:00 2001 From: zx870076178 <870076178@qq.com> Date: Mon, 11 Mar 2019 20:54:15 +0800 Subject: [PATCH] Gesture password logic modified --- App.js | 2 - src/code/Assets/Assets.js | 23 +- src/code/Assets/secondary/right_menu.js | 2 +- src/code/Assets/secondary/shiyan.js | 229 ++++++------------ src/code/Profile/Profile.js | 11 +- src/code/Profile/secondary/Settings.js | 14 +- .../Profile/secondary/Settings/Gesture.js | 24 +- 7 files changed, 128 insertions(+), 177 deletions(-) diff --git a/App.js b/App.js index 60ab6cfc..1fed56ec 100644 --- a/App.js +++ b/App.js @@ -3,7 +3,6 @@ import { View, StyleSheet } from 'react-native'; -import Start from './src/code/Start' import {StackNavigator} from 'react-navigation' import Tabbed_Navigation from './src/code/Tabbed_Navigation.js' import Create_Account from './src/code/Assets/secondary/Create_Account' @@ -40,7 +39,6 @@ import {Provider} from 'mobx-react' import AppState from './src/mobx/mobx' const Polkawallet_App = StackNavigator({ - // Start:{screen:Start,navigationOptions:{header:null}}, Tabbed_Navigation:{screen:Tabbed_Navigation,navigationOptions:{header:null}}, Create_Account:{screen:Create_Account,navigationOptions:{header:null}}, Backup_Account:{screen:Backup_Account,navigationOptions:{header:null}}, diff --git a/src/code/Assets/Assets.js b/src/code/Assets/Assets.js index 9d39c310..9d57e2fc 100644 --- a/src/code/Assets/Assets.js +++ b/src/code/Assets/Assets.js @@ -14,6 +14,8 @@ import { AsyncStorage, AppState } from 'react-native'; +import {NavigationActions, StackActions} from "react-navigation"; + import Identicon from 'polkadot-identicon-react-native'; import moment from "moment/moment"; import SInfo from 'react-native-sensitive-info'; @@ -333,7 +335,13 @@ export default class Assets extends Component { } handleAppStateChange(appState){ if(appState=='background'&&this.props.rootStore.stateStore.GestureState==2){ - this.props.navigation.navigate('Gesture') + let resetAction = StackActions.reset({ + index: 0, + actions: [ + NavigationActions.navigate({ routeName: 'Gesture'}) + ] + }) + this.props.navigation.dispatch(resetAction) } } componentWillMount(){ @@ -343,7 +351,6 @@ export default class Assets extends Component { this.props.rootStore.stateStore.balanceIndex=(index) } }) - // alert(this.props.rootStore.stateStore.balances[this.props.rootStore.stateStore.balanceIndex].address) },5000) AppState.addEventListener('change', this.handleAppStateChange) AsyncStorage.getItem('Gesture').then( @@ -351,10 +358,18 @@ export default class Assets extends Component { if(result==null){ this.props.rootStore.stateStore.GestureState=0 }else{ + if(this.props.rootStore.stateStore.GestureState!=2){ + this.props.rootStore.stateStore.Gesture=result this.props.rootStore.stateStore.GestureState=2 - this.props.navigation.navigate('Gesture') + let resetAction = StackActions.reset({ + index: 0, + actions: [ + NavigationActions.navigate({ routeName: 'Gesture'}) + ] + }) + this.props.navigation.dispatch(resetAction) + } } - this.props.rootStore.stateStore.Gesture=result } ) diff --git a/src/code/Assets/secondary/right_menu.js b/src/code/Assets/secondary/right_menu.js index 6eb4aa7f..12c9c88d 100644 --- a/src/code/Assets/secondary/right_menu.js +++ b/src/code/Assets/secondary/right_menu.js @@ -204,7 +204,7 @@ export default class New extends Component { render() { return ( - { this.props.t.setState({ is:false diff --git a/src/code/Assets/secondary/shiyan.js b/src/code/Assets/secondary/shiyan.js index 76f7b3c8..86d13ce5 100644 --- a/src/code/Assets/secondary/shiyan.js +++ b/src/code/Assets/secondary/shiyan.js @@ -1,163 +1,86 @@ import React, { Component } from 'react'; import { StyleSheet, - Text, View, - ScrollView, - TouchableOpacity, - TouchableWithoutFeedback, - Image, - ListView, - Modal , -} from 'react-native'; -var Dimensions = require('Dimensions'); -const {width,height} = Dimensions.get('window'); -export default class Select extends Component { - constructor(props){ - super(props); - this.state=({ - showModal:false, - course:"语文", - }); - } - componentWillMount(){ - - } - selCourse(course){ - this.setState({ - showModal:false, - course:course, - }); + Text, + TextInput, + Alert +} from "react-native"; + +import PasswordGesture from 'react-native-gesture-password' +let Password1 = ''; + +export default class GesturePassword extends Component { + constructor(props) { + super(props); + this.state = { + message: '请绘制解锁图案', + status: 'normal', + timeOut: 300, + } } + render() { - return ( - - - {this.setState({showModal:true})}}> - {this.state.course} - - {this.setState({showModal:true})}} - hitSlop={{top: 15, left: 15, bottom: 15, right: 15}}> - - - - {}} - style={{flex:1}} - ref="modal" > - {this.setState({showModal:false})}} > - - {}}> - - > - - {this.setState({showModal:false})}}> - {this.state.course} - - {this.setState({showModal:false})}} - hitSlop={{top: 15, left: 15, bottom: 15, right: 15}}> - - - - - {this.selCourse('语文')}}/> - {this.selCourse('数学')}}/> - {this.selCourse('英语')}}/> - - - {this.selCourse('物理')}}/> - {this.selCourse('化学')}}/> - - - + this.onStart()} + onEnd={(password) => this.onEnd(password)} + innerCircle={true} + outerCircle={true} + interval={this.state.timeOut} + /> - - - - ); + ) + } + + 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: '密码错误, 请再次输入.', + }); + } + } } -} -class CourseItem extends Component{ - render(){ - return( - - - {this.props.course} - - - ) + + onStart() { + if (Password1 === '') { + this.setState({ + message: '请绘制解锁图案', + }); + } else { + this.setState({ + message: '请再次绘制解锁图案', + }); + } + if (this.state.timeOut) { + clearTimeout(this.time); + } } -} -var cols = 3; -var boxW = 70; -var vMargin = (width-cols*boxW)/(cols+1); -var hMargin = 25; -const styles = StyleSheet.create({ - arrStyle:{ - width:26, - height:26, - resizeMode:'contain', - }, - boxView:{ - justifyContent:'center', - alignItems:'center', - width:boxW, - height:boxW, - marginLeft:vMargin, - marginTop:hMargin, - borderWidth:StyleSheet.hairlineWidth, - borderColor:'#999', - borderRadius:5, - }, - courseWrap:{ - flexDirection:'row', - justifyContent:'flex-start', - borderWidth:0, - borderColor:'orange', - }, - selCourseText:{ - padding:8, - fontSize:18, - }, - blackText:{ - color:'black', - fontSize:16, - }, - arrowStyle:{ - width:20, - height:20, - }, - textWrapView:{ - paddingTop:10, - paddingBottom:10, - }, - headText:{ - fontSize:22, - }, - headStyle:{ - flexDirection:'row', - width:width, - justifyContent:"center", - alignItems:'center', - backgroundColor:'#F2F2F2', - paddingTop:15, - paddingBottom:15, - }, - container: { - flex: 1, - alignItems: 'center', - backgroundColor: '#fff', - }, - -}); +} \ No newline at end of file diff --git a/src/code/Profile/Profile.js b/src/code/Profile/Profile.js index 0e5e0eef..286c3e9b 100644 --- a/src/code/Profile/Profile.js +++ b/src/code/Profile/Profile.js @@ -11,6 +11,7 @@ import { SafeAreaView, AsyncStorage } from 'react-native'; + let Platform = require('Platform'); let ScreenWidth = Dimensions.get("screen").width; let ScreenHeight = Dimensions.get("screen").height; @@ -52,16 +53,6 @@ export default class New extends Component { this.props.navigation.navigate('About') } componentWillMount(){ - AsyncStorage.getItem('Gesture').then( - (result)=>{ - if(result==null){ - this.props.rootStore.stateStore.GestureState=0 - }else{ - this.props.rootStore.stateStore.GestureState=2 - } - this.props.rootStore.stateStore.Gesture=result - } - ) } render() { return ( diff --git a/src/code/Profile/secondary/Settings.js b/src/code/Profile/secondary/Settings.js index 9d6d809e..3f019170 100644 --- a/src/code/Profile/secondary/Settings.js +++ b/src/code/Profile/secondary/Settings.js @@ -12,7 +12,7 @@ import { Switch, Alert } from 'react-native'; - +import {NavigationActions, StackActions} from "react-navigation"; let ScreenWidth = Dimensions.get("screen").width; let ScreenHeight = Dimensions.get("screen").height; const msg = [ @@ -47,7 +47,13 @@ export default class New extends Component { Gesture(e){ this.setState({Gesture: e}); if(e){ - this.props.navigation.navigate('Gesture') + let resetAction = StackActions.reset({ + index: 0, + actions: [ + NavigationActions.navigate({ routeName: 'Gesture'}) + ] + }) + this.props.navigation.dispatch(resetAction) }else{ Alert.alert( 'Alert', @@ -55,6 +61,7 @@ export default class New extends Component { [ {text: 'Cancel', onPress: () => {this.setState({Gesture:true})}, style: 'cancel'}, {text: 'Confirm', onPress: () => { + this.props.rootStore.stateStore.GestureState=0 AsyncStorage.removeItem('Gesture').then( alert('The gesture password has been canceled.') ) @@ -70,8 +77,7 @@ export default class New extends Component { Facial_Recognition(e) { this.setState({Facial_Recognition: e}); } - componentWillMount(){ - + componentWillUpdate(){ } render() { return ( diff --git a/src/code/Profile/secondary/Settings/Gesture.js b/src/code/Profile/secondary/Settings/Gesture.js index ad73b107..43b6a28c 100644 --- a/src/code/Profile/secondary/Settings/Gesture.js +++ b/src/code/Profile/secondary/Settings/Gesture.js @@ -6,6 +6,8 @@ import { View, AsyncStorage } from 'react-native'; +import {NavigationActions, StackActions} from "react-navigation"; + import PasswordGesture from 'react-native-gesture-password'; import { observer, inject } from "mobx-react"; @inject('rootStore') @@ -42,7 +44,15 @@ export default class Gesture_Test1 extends Component{ status: 'right', message: 'Confirmed, password set successfully.' }); - setTimeout(()=>{this.props.navigation.navigate('Settings')},500) + setTimeout(()=>{ + let resetAction = StackActions.reset({ + index: 0, + actions: [ + NavigationActions.navigate({ routeName: 'Settings'}) + ] + }) + this.props.navigation.dispatch(resetAction) + },500) }else{ //确认失败 this.props.rootStore.stateStore.GestureState=0 @@ -59,7 +69,15 @@ export default class Gesture_Test1 extends Component{ status: 'right', message: 'Password is correct.' }); - setTimeout(()=>{this.props.navigation.navigate('Tabbed_Navigation')},500) + setTimeout(()=>{ + let resetAction = StackActions.reset({ + index: 0, + actions: [ + NavigationActions.navigate({ routeName: 'Tabbed_Navigation'}) + ] + }) + this.props.navigation.dispatch(resetAction) + },500) }else{ this.setState({ status: 'wrong', @@ -84,7 +102,7 @@ export default class Gesture_Test1 extends Component{ }); } componentWillMount(){ - // alert(this.props.rootStore.stateStore.Gesture==null?'Please set the gesture password':'Password') + } render() { return (