fix show/hide password

This commit is contained in:
Guilherme Gazzo 2018-03-31 21:45:15 -03:00
parent a9225280a9
commit d63333fa22
No known key found for this signature in database
GPG Key ID: 1F85C9AD922D0829
4 changed files with 57 additions and 55 deletions

View File

@ -2,6 +2,8 @@ import React from 'react';
import { View, StyleSheet, Text, TextInput } from 'react-native'; import { View, StyleSheet, Text, TextInput } from 'react-native';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Icon from 'react-native-vector-icons/FontAwesome';
import sharedStyles from '../views/Styles'; import sharedStyles from '../views/Styles';
import { COLOR_DANGER } from '../constants/colors'; import { COLOR_DANGER } from '../constants/colors';
@ -29,46 +31,57 @@ const styles = StyleSheet.create({
inputError: { inputError: {
color: COLOR_DANGER, color: COLOR_DANGER,
borderColor: COLOR_DANGER borderColor: COLOR_DANGER
},
wrap: {
flex: 1,
position: 'relative'
},
icon: {
position: 'absolute',
right: 0,
padding: 10,
color: 'rgba(0,0,0,.45)'
} }
}); });
export default class RCTextInput extends React.PureComponent { export default class RCTextInput extends React.PureComponent {
static propTypes = { static propTypes = {
label: PropTypes.string, label: PropTypes.string,
value: PropTypes.string,
error: PropTypes.object, error: PropTypes.object,
inputProps: PropTypes.object, secureTextEntry: PropTypes.bool
inputRef: PropTypes.func,
onChangeText: PropTypes.func,
onSubmitEditing: PropTypes.func
} }
static defaultProps = { static defaultProps = {
label: 'Label', showPassword: false,
error: {} error: {}
} }
state = {
showPassword: false
}
get icon() { return <Icon name={this.state.showPassword ? 'eye-slash' : 'eye'} style={styles.icon} size={20} onPress={this.tooglePassword} />; }
tooglePassword = () => this.setState({ showPassword: !this.state.showPassword })
render() { render() {
const { const {
label, value, error, inputRef, onChangeText, onSubmitEditing, inputProps label, error, secureTextEntry, ...inputProps
} = this.props; } = this.props;
const { showPassword } = this.state;
return ( return (
<View style={styles.inputContainer}> <View style={styles.inputContainer}>
<Text style={[styles.label, error.error && styles.labelError]}> { label && <Text style={[styles.label, error.error && styles.labelError]}>{label}</Text> }
{label} <View style={styles.wrap}>
</Text> <TextInput
<TextInput style={[styles.input, error.error && styles.inputError]}
ref={inputRef} autoCorrect={false}
style={[styles.input, error.error && styles.inputError]} autoCapitalize='none'
onChangeText={onChangeText} underlineColorAndroid='transparent'
onSubmitEditing={onSubmitEditing} secureTextEntry={secureTextEntry && !showPassword}
value={value} {...inputProps}
autoCorrect={false} />
returnKeyType='next' {secureTextEntry && this.icon}
autoCapitalize='none' </View>
underlineColorAndroid='transparent'
{...inputProps}
/>
{error.error && <Text style={sharedStyles.error}>{error.reason}</Text>} {error.error && <Text style={sharedStyles.error}>{error.reason}</Text>}
</View> </View>
); );

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import Spinner from 'react-native-loading-spinner-overlay'; import Spinner from 'react-native-loading-spinner-overlay';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Keyboard, Text, TextInput, View, ScrollView, TouchableOpacity, SafeAreaView, WebView, Platform, LayoutAnimation } from 'react-native'; import { Keyboard, Text, View, ScrollView, TouchableOpacity, SafeAreaView, WebView, Platform, LayoutAnimation } from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import Icon from 'react-native-vector-icons/FontAwesome'; import Icon from 'react-native-vector-icons/FontAwesome';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons'; import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
@ -10,6 +10,7 @@ import Modal from 'react-native-modal';
import { loginSubmit, open, close } from '../actions/login'; import { loginSubmit, open, close } from '../actions/login';
import KeyboardView from '../presentation/KeyboardView'; import KeyboardView from '../presentation/KeyboardView';
import TextInput from '../containers/TextInput';
import styles from './Styles'; import styles from './Styles';
import scrollPersistTaps from '../utils/scrollPersistTaps'; import scrollPersistTaps from '../utils/scrollPersistTaps';
@ -65,7 +66,6 @@ export default class LoginView extends React.Component {
username: '', username: '',
password: '', password: '',
modalVisible: false, modalVisible: false,
showPassword: false,
oAuthUrl: '' oAuthUrl: ''
}; };
this.redirectRegex = new RegExp(`(?=.*(${ this.props.server }))(?=.*(credentialToken))(?=.*(credentialSecret))`, 'g'); this.redirectRegex = new RegExp(`(?=.*(${ this.props.server }))(?=.*(credentialToken))(?=.*(credentialSecret))`, 'g');
@ -239,21 +239,20 @@ export default class LoginView extends React.Component {
onSubmitEditing={() => { this.password.focus(); }} onSubmitEditing={() => { this.password.focus(); }}
placeholder={this.props.Accounts_EmailOrUsernamePlaceholder || 'Email or username'} placeholder={this.props.Accounts_EmailOrUsernamePlaceholder || 'Email or username'}
/> />
<View style={styles.passInput}>
<TextInput <TextInput
ref={(e) => { this.password = e; }} ref={(e) => { this.password = e; }}
style={styles.input_white} style={styles.input_white}
onChangeText={password => this.setState({ password })} onChangeText={password => this.setState({ password })}
secureTextEntry={!this.state.showPassword} secureTextEntry
autoCorrect={false} autoCorrect={false}
returnKeyType='done' returnKeyType='done'
autoCapitalize='none' autoCapitalize='none'
underlineColorAndroid='transparent' underlineColorAndroid='transparent'
onSubmitEditing={this.submit} onSubmitEditing={this.submit}
placeholder={this.props.Accounts_PasswordPlaceholder || 'Password'} placeholder={this.props.Accounts_PasswordPlaceholder || 'Password'}
/> />
<Icon name='eye' style={styles.passIcon} size={20} onPress={() => { this.setState({ showPassword: !this.state.showPassword }); }}/>
</View>
{this.renderTOTP()} {this.renderTOTP()}
<TouchableOpacity <TouchableOpacity

View File

@ -262,7 +262,7 @@ export default class RoomInfoEditView extends React.Component {
<SafeAreaView> <SafeAreaView>
<View style={sharedStyles.formContainer}> <View style={sharedStyles.formContainer}>
<RCTextInput <RCTextInput
inputRef={(e) => { this.name = e; }} ref={(e) => { this.name = e; }}
label='Name' label='Name'
value={name} value={name}
onChangeText={value => this.setState({ name: value })} onChangeText={value => this.setState({ name: value })}
@ -270,7 +270,7 @@ export default class RoomInfoEditView extends React.Component {
error={nameError} error={nameError}
/> />
<RCTextInput <RCTextInput
inputRef={(e) => { this.description = e; }} ref={(e) => { this.description = e; }}
label='Description' label='Description'
value={description} value={description}
onChangeText={value => this.setState({ description: value })} onChangeText={value => this.setState({ description: value })}
@ -278,7 +278,7 @@ export default class RoomInfoEditView extends React.Component {
inputProps={{ multiline: true }} inputProps={{ multiline: true }}
/> />
<RCTextInput <RCTextInput
inputRef={(e) => { this.topic = e; }} ref={(e) => { this.topic = e; }}
label='Topic' label='Topic'
value={topic} value={topic}
onChangeText={value => this.setState({ topic: value })} onChangeText={value => this.setState({ topic: value })}
@ -286,7 +286,7 @@ export default class RoomInfoEditView extends React.Component {
inputProps={{ multiline: true }} inputProps={{ multiline: true }}
/> />
<RCTextInput <RCTextInput
inputRef={(e) => { this.announcement = e; }} ref={(e) => { this.announcement = e; }}
label='Announcement' label='Announcement'
value={announcement} value={announcement}
onChangeText={value => this.setState({ announcement: value })} onChangeText={value => this.setState({ announcement: value })}
@ -294,7 +294,7 @@ export default class RoomInfoEditView extends React.Component {
inputProps={{ multiline: true }} inputProps={{ multiline: true }}
/> />
<RCTextInput <RCTextInput
inputRef={(e) => { this.joinCode = e; }} ref={(e) => { this.joinCode = e; }}
label='Password' label='Password'
value={joinCode} value={joinCode}
onChangeText={value => this.setState({ joinCode: value })} onChangeText={value => this.setState({ joinCode: value })}

View File

@ -32,16 +32,6 @@ export default StyleSheet.create({
justifyContent: 'center', justifyContent: 'center',
flex: 1 flex: 1
}, },
passInput: {
flex: 1,
position: 'relative'
},
passIcon: {
position: 'absolute',
right: 0,
padding: 10,
color: 'rgba(0,0,0,.45)'
},
loginLogo: { loginLogo: {
width: Dimensions.get('window').width - 150, width: Dimensions.get('window').width - 150,
height: Dimensions.get('window').width - 150, height: Dimensions.get('window').width - 150,