Skip to content

Commit

Permalink
fga-eps-mds#166 - New styles for generic input
Browse files Browse the repository at this point in the history
Co-authored-by: Matheus Oliveira <matheus_oliveira30@hotmail.com>
Co-authored-by: Gustavo Sabino <gustavo.sabino.contact@gmail.com>
  • Loading branch information
matheusoliveira30 and SabinoGs committed Apr 19, 2018
1 parent 2e89a90 commit a9ea8be
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
17 changes: 17 additions & 0 deletions src/Styles/GeneralStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ const { height } = Dimensions.get('window');
const { width } = Dimensions.get('window');

const styles = {

genericViewSection: {
flex: 1,
flexDirection: 'row',
padding: 10,
marginTop: 1,
backgroundColor: '#FAFAFA',
justifyContent: 'flex-start',
alignItems: 'center',
borderRadius: 7,
marginBottom: 10,
borderWidth: 1,
borderColor: 'gray',
},
genericInputBox: {
marginBotom: 10,
},
bigButton: {
paddingVertical: 20,
borderWidth: 1,
Expand Down
28 changes: 18 additions & 10 deletions src/components/GenericField.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Text, View, TextInput } from 'react-native';
import { FontAwesome } from '@expo/vector-icons';
import styles from '../Styles/GeneralStyles';

export default class GenericField extends Component {
constructor(props) {
super(props);

this.state = {
styleInUse: styles.InputFieldStyle,
styleInUse: styles.genericViewSection,
errorTextArea: <Text />,
text: '',
};
Expand All @@ -22,12 +23,12 @@ export default class GenericField extends Component {

handleValidText() {
this.setState({ errorTextArea: <Text /> });
this.setState({ styleInUse: [styles.InputFieldStyle, { borderColor: '#80FF80', borderWidth: 2 }] });
this.setState({ styleInUse: [styles.InputFieldStyle, { borderColor: '#80FF80', backgroundColor: '#d1ffd1', borderWidth: 2 }] });
}

handleInvalidText() {
this.setState({ errorTextArea: <Text>{this.props.errorMessage}</Text> });
this.setState({ styleInUse: [styles.InputFieldStyle, { borderColor: '#FF9999', borderWidth: 2 }] });
this.setState({ styleInUse: [styles.InputFieldStyle, { borderColor: '#FF9999', backgroundColor: '#ffd6d6', borderWidth: 2 }] });
}

validateText(text, regexTest) {
Expand All @@ -45,6 +46,9 @@ export default class GenericField extends Component {
// setStateValue is the function in props at the component creation
this.props.setStateValue(this.state.text);
this.handleValidText();
} else if (!isTextValid && text === '') {
// This case is for empty text
this.setState({ styleInUse: styles.genericViewSection });
} else {
console.warn('Invalido');
this.handleInvalidText();
Expand All @@ -55,15 +59,19 @@ export default class GenericField extends Component {
return (
<View>
<Text> {this.props.header.toUpperCase().trim()} </Text>
<TextInput
style={this.state.styleInUse}
placeholder={this.props.placeholderMessage.trim()}
value={this.state.test}
onChangeText={text => this.handleInput(text)}
/>
<View style={this.state.styleInUse}>
<FontAwesome name="user-circle" style={styles.icon} size={26} color="black" />
<TextInput
style={styles.InputStyle}
placeholder={this.props.placeholderMessage.trim()}
placeholderTextColor="#565454"
value={this.state.test}
underlineColorAndroid="transparent"
onChangeText={text => this.handleInput(text)}
/>
</View>

{this.state.errorTextArea}

</View>
);
}
Expand Down

0 comments on commit a9ea8be

Please sign in to comment.