From a9ea8bec8ab0a285330fed1033596221ef5e5a2b Mon Sep 17 00:00:00 2001 From: Matheus Oliveira Date: Thu, 19 Apr 2018 17:57:46 -0300 Subject: [PATCH] #166 - New styles for generic input Co-authored-by: Matheus Oliveira Co-authored-by: Gustavo Sabino --- src/Styles/GeneralStyles.js | 17 +++++++++++++++++ src/components/GenericField.js | 28 ++++++++++++++++++---------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/Styles/GeneralStyles.js b/src/Styles/GeneralStyles.js index 15d2fa9..c16e21c 100644 --- a/src/Styles/GeneralStyles.js +++ b/src/Styles/GeneralStyles.js @@ -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, diff --git a/src/components/GenericField.js b/src/components/GenericField.js index 50892eb..877ad39 100644 --- a/src/components/GenericField.js +++ b/src/components/GenericField.js @@ -1,6 +1,7 @@ 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 { @@ -8,7 +9,7 @@ export default class GenericField extends Component { super(props); this.state = { - styleInUse: styles.InputFieldStyle, + styleInUse: styles.genericViewSection, errorTextArea: , text: '', }; @@ -22,12 +23,12 @@ export default class GenericField extends Component { handleValidText() { this.setState({ errorTextArea: }); - this.setState({ styleInUse: [styles.InputFieldStyle, { borderColor: '#80FF80', borderWidth: 2 }] }); + this.setState({ styleInUse: [styles.InputFieldStyle, { borderColor: '#80FF80', backgroundColor: '#d1ffd1', borderWidth: 2 }] }); } handleInvalidText() { this.setState({ errorTextArea: {this.props.errorMessage} }); - this.setState({ styleInUse: [styles.InputFieldStyle, { borderColor: '#FF9999', borderWidth: 2 }] }); + this.setState({ styleInUse: [styles.InputFieldStyle, { borderColor: '#FF9999', backgroundColor: '#ffd6d6', borderWidth: 2 }] }); } validateText(text, regexTest) { @@ -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(); @@ -55,15 +59,19 @@ export default class GenericField extends Component { return ( {this.props.header.toUpperCase().trim()} - this.handleInput(text)} - /> + + + this.handleInput(text)} + /> + {this.state.errorTextArea} - ); }