Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions lib/TextField.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
import React, {Component, PropTypes} from "react";
import {View, TextInput, StyleSheet} from "react-native";
import {View, TextInput, Text, StyleSheet} from "react-native";

import Underline from './Underline';
import FloatingLabel from './FloatingLabel';
Expand Down Expand Up @@ -61,16 +61,26 @@ export default class TextField extends Component {
multiline,
...props
} = this.props;

const textInputComposedStyles = [dense ? styles.denseTextInput : styles.textInput, {
color: textColor
}, (this.state.isFocused && textFocusColor) ? {
color: textFocusColor
} : {}, (!this.state.isFocused && textBlurColor) ? {
color: textBlurColor
} : {}, inputStyle, this.state.height ? {height: this.state.height} : {}]

return (
<View style={[dense ? styles.denseWrapper : styles.wrapper, this.state.height ? {height: undefined}: {}, wrapperStyle]} ref="wrapper">
<View style={[styles.row, styles.flex]}>
{
this.props.symbol && this.props.value ?
<Text style={[textInputComposedStyles, styles.symbol]}>{this.props.symbol}</Text>
: null
}
<View style={styles.flex}>
<TextInput
style={[dense ? styles.denseTextInput : styles.textInput, {
color: textColor
}, (this.state.isFocused && textFocusColor) ? {
color: textFocusColor
} : {}, (!this.state.isFocused && textBlurColor) ? {
color: textBlurColor
} : {}, inputStyle, this.state.height ? {height: this.state.height} : {}]}
style={[textInputComposedStyles]}
multiline={multiline}
onFocus={() => {
this.setState({isFocused: true});
Expand Down Expand Up @@ -98,6 +108,8 @@ export default class TextField extends Component {
value={this.state.text}
{...props}
/>
</View>
</View>
<Underline
ref="underline"
highlightColor={highlightColor}
Expand Down Expand Up @@ -141,7 +153,8 @@ TextField.propTypes = {
labelStyle: PropTypes.object,
multiline: PropTypes.bool,
autoGrow: PropTypes.bool,
height: PropTypes.oneOfType([PropTypes.oneOf(undefined), PropTypes.number])
height: PropTypes.oneOfType([PropTypes.oneOf(undefined), PropTypes.number]),
symbol: PropTypes.string
};

TextField.defaultProps = {
Expand All @@ -158,6 +171,12 @@ TextField.defaultProps = {
};

const styles = StyleSheet.create({
flex: {
flex: 1
},
row: {
flexDirection: 'row'
},
wrapper: {
height: 72,
paddingTop: 30,
Expand All @@ -182,5 +201,12 @@ const styles = StyleSheet.create({
lineHeight: 24,
paddingBottom: 3,
textAlignVertical: 'top'
},
symbol: {
textAlignVertical: 'auto',
lineHeight: undefined,
height: undefined,
position: 'relative',
bottom: -10
}
});