-
Notifications
You must be signed in to change notification settings - Fork 0
/
PasswordBox.js
111 lines (98 loc) · 3.33 KB
/
PasswordBox.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import React, {
Component,
PropTypes,
Text,
TextInput,
TouchableWithoutFeedback,
View,
Image
} from 'react-native';
import {styles} from './TextBox.style.js';
import Theme from '../../config/theme';
import {Icons} from '../symbols/Icons';
const propTypes = {
autoFocus: PropTypes.bool,
editable: PropTypes.bool,
hideIconButton: PropTypes.bool,
header: PropTypes.string,
highlightColor: PropTypes.string,
onFocus: PropTypes.func,
onBlur: PropTypes.func
};
const defaultProps = {
editable: true,
hideIconButton: true,
highlightColor: Theme.colors.highlight,
icon: Icons.Clear
};
export default class PasswordBox extends Component {
constructor(props) {
super(props);
this.state = {
value: this.props.value,
focus: this.props.autoFocus ? true : false,
showPassword: false
};
}
onChangeText(text) {
this.setState({value: text});
this.props.onChangeText && this.props.onChangeText(text);
}
onFocus() {
if (this.props.editable) {
this.setState({focus: true});
}
this.props.onFocus && this.props.onFocus();
}
onBlur() {
if (this.props.editable) {
this.setState({focus: false});
}
this.props.onBlur && this.props.onBlur();
}
render() {
const {header, hideIconButton, editable, highlightColor, ...other} = this.props;
const {focus, value, showPassword} = this.state;
let clear = null;
if ((!hideIconButton || focus) && editable && value) {
clear = (
<TouchableWithoutFeedback
onPressIn ={() => {
this.setState({showPassword: true});
}}
onPressOut={() => {
this.setState({showPassword: false})
}}
>
<Image source={Icons.View} style={styles.boxIcon} />
</TouchableWithoutFeedback>
);
}
return (
<View style={[styles.container, this.props.style]}>
{
header &&
(<Text style={styles.header}>{header}</Text>)
}
<View style={[styles.inputBox,
{borderColor: focus ? highlightColor : Theme.colors.foregroundDisable}]}>
<TextInput underlineColorAndroid="transparent"
{...other}
editable={editable}
style={[styles.textInput, {color: editable ? Theme.colors.foreground
: Theme.colors.foregroundDisable}]}
value={value}
placeholderTextColor={Theme.colors.placeholder}
secureTextEntry={!showPassword}
onChangeText={(text) => this.onChangeText(text)}
onFocus={this.onFocus.bind(this)}
onBlur={this.onBlur.bind(this)}
/>
{clear}
</View>
</View>
);
}
}
PasswordBox.propTypes = propTypes;
PasswordBox.defaultProps = defaultProps;