password.js
4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* Created by DEV005 on 2017/10/27.
*/
import React, {Component, PropTypes} from 'react';
import {
StyleSheet,
Image,
TouchableOpacity,
TouchableHighlight,
ScrollView,
Button,
Text,
View,
NativeModules,
TextInput,
DeviceEventEmitter
} from 'react-native';
import {xnToast} from "../../utils/utils";
import AppService from "../../service/AppService";
export default class password extends Component {
constructor(props){
super(props);
this.state = {
password:""
};
}
componentDidMount() {
let _this=this;
DeviceEventEmitter.addListener('initPassword', function(event) {
// handle event.
_this.setState({
password:"",
});
if(event=="blur"&&_this.refs.TextInput){
_this.refs.TextInput.blur();
}
});
};
// 获取焦距
autoFocus=()=>{
this.refs.TextInput.focus();
};
//改变
onChangeText=(value)=>{
let _this=this;
this.setState({
password:value,
});
if(value.length==6){
_this.props.callBack(value);
}
};
render() {
return (
<View style={styles.loginLayout}>
<View style={styles.titleLayout}><Text style={styles.titleText}>{this.props.title}</Text></View>
<TouchableOpacity style={styles.loginInput} activeOpacity={1} onPress={()=>{this.autoFocus()}}>
<View style={styles.inputItem}>{this.state.password.length>0&&<Image style={styles.inputText} source={require('../../img/password.png')} resizeMode="contain"/>}</View>
<View style={styles.inputItem}>{this.state.password.length>1&&<Image style={styles.inputText} source={require('../../img/password.png')} resizeMode="contain"/>}</View>
<View style={styles.inputItem}>{this.state.password.length>2&&<Image style={styles.inputText} source={require('../../img/password.png')} resizeMode="contain"/>}</View>
<View style={styles.inputItem}>{this.state.password.length>3&&<Image style={styles.inputText} source={require('../../img/password.png')} resizeMode="contain"/>}</View>
<View style={styles.inputItem}>{this.state.password.length>4&&<Image style={styles.inputText} source={require('../../img/password.png')} resizeMode="contain"/>}</View>
<View style={[styles.inputItem,styles.inputItemEnd]}>{this.state.password.length>5&&<Image style={styles.inputText} source={require('../../img/password.png')} resizeMode="contain"/>}</View>
</TouchableOpacity>
{this.props.toForget&&<View style={styles.linkLayout}><TouchableOpacity style={styles.link} onPress={()=>{this.props.toForget()}}><Text style={styles.linkText}>忘记密码?</Text></TouchableOpacity></View>}
<TextInput style={styles.hide} autoFocus={false} ref="TextInput" value={this.state.password}
onChangeText={(text) => {this.onChangeText(text)}} keyboardType='numeric' maxLength ={6} />
</View>
);
};
};
const styles = StyleSheet.create({
loginLayout:{
flex:1,
paddingTop:30,
paddingLeft:25,
paddingRight:25,
backgroundColor:"#eee"
},
hide:{
width:0,
height:0
},
titleLayout:{
height:30,
marginBottom:10,
},
titleText:{
fontSize:20,
color:"#000",
},
loginInput:{
flexDirection:"row",
backgroundColor:"#fff",
borderWidth:1,
borderColor:"#ddd",
borderRadius:4,
paddingTop:10,
paddingBottom:10,
height:50,
},
inputItemEnd:{
borderColor:"transparent",
},
inputItem:{
flex:1,
flexDirection:"row",
alignItems: 'center',
justifyContent: 'center',
borderColor:"#ddd",
borderRightWidth:1,
},
linkLayout:{
paddingTop:10,
flexDirection:"row",
justifyContent:"flex-end",
},
inputText:{
width:12,
height:12,
},
link:{
},
linkText:{
paddingTop:5,
paddingBottom:5,
color:"#39f",
}
});