-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpasswordInput.js
87 lines (83 loc) · 2.64 KB
/
passwordInput.js
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
/**
* Created by wayne on 2017/6/21.
*/
import React, { Component } from 'react';
import {StyleSheet,View,TextInput,Text,TouchableHighlight } from 'react-native';
const styles = StyleSheet.create({
container: {
alignItems: 'center',
flexDirection: 'row',
borderWidth: 1,
borderColor: '#ccc',
backgroundColor: '#fff'
},
inputItem: {
height: 45,
width: 45,
justifyContent: 'center',
alignItems: 'center'
},
inputItemBorderLeftWidth: {
borderLeftWidth: 1,
borderColor: '#ccc',
},
iconStyle: {
width: 16,
height: 16,
backgroundColor: '#222',
borderRadius: 8,
},
});
export default class passwordInput extends Component{
constructor(props){
super(props);
this.state={
text: ''
}
this._onPress = this._onPress.bind(this);
}
_onPress(){
this._input.focus();
}
render(){
return(
<TouchableHighlight onPress={this._onPress} activeOpacity={1} underlayColor='transparent'>
<View style={[styles.container,this.props.style]} >
<TextInput
style={{height:45,zIndex:99,position:'absolute',width:45*6,opacity:0}}
ref={(c) => this._input = c}
maxLength={this.props.maxLength}
autoFocus={true}
keyboardType="numeric"
onChangeText={(text)=>{this.setState({text});this.props.onChange(text)}}
/>
{
this._getInputItem()
}
</View>
</TouchableHighlight>
)
}
_getInputItem(){
let inputItem = [];
let {text}=this.state;
for (let i = 0; i < parseInt(this.props.maxLength); i++) {
if (i == 0) {
inputItem.push(
<View key={i} style={[styles.inputItem,this.props.inputItemStyle]}>
{i < text.length ? <View style={[styles.iconStyle,this.props.iconStyle]}></View> : null}
</View>)
}
else {
inputItem.push(
<View key={i} style={[styles.inputItem,styles.inputItemBorderLeftWidth,this.props.inputItemStyle]}>
{i < text.length ?
<View style={[styles.iconStyle,this.props.iconStyle]}>
</View> : null}
</View>)
}
;
}
return inputItem;
}
}