Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,19 @@ Prop | Type | Default | description
-----|------|---------|------------
label | string | | This string appears as the label.
highlightColor | string | | This string represents the hex code, rgb, or rgba color of the textInput label and underline when it is active/focused on.
keepHighlightColor | bool | false | If true will keep the highlight color active.
labelFontFamily | string | | Adds a custom font to the label.
textInputFontFamily | string | | Adds a custom font to the text input.
duration | number | `200` | A number representing the duration of floating label and underline animations in milliseconds.
labelColor | string | `#9E9E9E` | This string represents the hex code, rgb, or rgba color of the textInput label when it is inactive.
borderColor | string | `#E0E0E0` | This string represents the hex code, rgb, or rgba color of the textInput underline when it is inactive.
dense | bool | `false` | If true, it will render the "dense" input field which is smaller in height and has smaller font sizes. You can view more [here](https://www.google.com/design/spec/components/text-fields.html#text-fields-labels).
multiline | bool | `false` | If true, it will allow multiline text input
height | number | `false` | A number representing the initial height of the textInput
autoGrow | bool | `false` | If true enables autogrow of the textInput
underlineColorAndroid | string | `rgba(0,0,0,0)` | This sets the default underline color on Android to transparent ([Issue #1](https://github.com/evblurbs/react-native-md-textinput/issues/1)).

## TODO

- [ ] Support multi-line TextInput fields
- [ ] Support character limit
- [ ] Add option for dark theme
9 changes: 2 additions & 7 deletions examples/FloatingLabel/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
* that demos the react-native-md-textinput
*/
'use strict';
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
ScrollView
} from 'react-native';
import React, {Component} from "react";
import {AppRegistry, StyleSheet, Text, ScrollView} from "react-native";

import TextField from 'react-native-md-textinput';

Expand Down
9 changes: 2 additions & 7 deletions examples/FloatingLabel/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
* that demos the react-native-md-textinput
*/
'use strict';
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
ScrollView
} from 'react-native';
import React, {Component} from "react";
import {AppRegistry, StyleSheet, Text, ScrollView} from "react-native";

import TextField from 'react-native-md-textinput';

Expand Down
23 changes: 11 additions & 12 deletions lib/FloatingLabel.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
'use strict';
/* @flow */

import React, {
Component,
StyleSheet,
Animated,
PropTypes
} from 'react-native';
import React, {Component, PropTypes} from "react";
import {StyleSheet, Animated} from "react-native";

export default class FloatingLabel extends Component {
constructor(props: Object) {
Expand Down Expand Up @@ -60,14 +54,17 @@ export default class FloatingLabel extends Component {
let {
label,
labelColor,
highlightColor
highlightColor,
labelFontFamily,
keepHightlightColor
} = this.props;
return (
<Animated.Text
style={[{
style={[labelFontFamily ? {fontFamily: labelFontFamily} : {},
keepHightlightColor ? {color: highlightColor} : {color: labelColor},
{
fontSize: this.state.fontSize,
top: this.state.top,
color: labelColor
}, styles.labelText, this.props.isFocused && {
color: highlightColor
}]}
Expand All @@ -86,7 +83,9 @@ FloatingLabel.propTypes = {
label: PropTypes.string,
labelColor: PropTypes.string,
highlightColor: PropTypes.string,
dense: PropTypes.bool
dense: PropTypes.bool,
labelFontFamily: PropTypes.string,
keepHightlightColor: PropTypes.bool
};

const styles = StyleSheet.create({
Expand Down
71 changes: 49 additions & 22 deletions lib/TextField.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
'use strict';
/* @flow */

import React, {
Component,
View,
TextInput,
StyleSheet,
PropTypes
} from 'react-native';
import React, {Component, PropTypes} from "react";
import {View, TextInput, StyleSheet} from "react-native";

import Underline from './Underline';
import FloatingLabel from './FloatingLabel';
Expand All @@ -17,12 +10,27 @@ export default class TextField extends Component {
super(props, context);
this.state = {
isFocused: false,
text: props.value
text: props.value,
height: props.height
};
}
componentWillReceiveProps(nextProps: Object){
if(this.props.text != nextProps.value){
nextProps.value.length !== 0 ? this.refs.floatingLabel.floatLabel() : this.refs.floatingLabel.sinkLabel()
this.setState({text: nextProps.value})
}
if(this.props.height !== nextProps.height){
this.setState({height: nextProps.height});
}
}
focus() {
this.refs.input.focus();
this.refs.input.focus();
}

measureLayout(...args){
this.refs.wrapper.measureLayout(...args)
}

render() {
let {
label,
Expand All @@ -32,15 +40,21 @@ export default class TextField extends Component {
borderColor,
onFocus,
onBlur,
onChangeText,
onChange,
value,
dense,
multiline,
autoGrow,
textInputFontFamily,
labelFontFamily,
keepHightlightColor,
...props
} = this.props;
return (
<View style={dense ? styles.denseWrapper : styles.wrapper} ref="wrapper">
<TextInput
style={dense ? styles.denseTextInput : styles.textInput}
style={[textInputFontFamily ? {fontFamily: textInputFontFamily} : {}, dense ? styles.denseTextInput : styles.textInput, this.state.height ? {height: this.state.height} : {}]}
multiline={this.props.multiline}
onFocus={() => {
this.setState({isFocused: true});
this.refs.floatingLabel.floatLabel();
Expand All @@ -53,9 +67,13 @@ export default class TextField extends Component {
this.refs.underline.shrinkLine();
onBlur && onBlur();
}}
onChangeText={(text) => {
this.setState({text});
onChangeText && onChangeText(text);
onChange={(event) => {
if(autoGrow){
this.setState({text: event.nativeEvent.text, height: event.nativeEvent.contentSize.height});
}else{
this.setState({text: event.nativeEvent.text});
}
onChange && onChange(event);
}}
ref="input"
value={this.state.text}
Expand All @@ -76,6 +94,8 @@ export default class TextField extends Component {
highlightColor={highlightColor}
duration={duration}
dense={dense}
keepHightlightColor={keepHightlightColor}
labelFontFamily={labelFontFamily}
hasValue={(this.state.text.length) ? true : false}
/>
</View>
Expand All @@ -89,9 +109,14 @@ TextField.propTypes = {
highlightColor: PropTypes.string,
onFocus: PropTypes.func,
onBlur: PropTypes.func,
onChangeText: PropTypes.func,
onChange: PropTypes.func,
value: PropTypes.string,
dense: PropTypes.bool
dense: PropTypes.bool,
multiline: PropTypes.bool,
autoGrow: PropTypes.bool,
textInputFontFamily: PropTypes.string,
labelFontFamily: PropTypes.string,
keepHightlightColor: PropTypes.bool
};

TextField.defaultProps = {
Expand All @@ -100,26 +125,28 @@ TextField.defaultProps = {
borderColor: '#E0E0E0',
value: '',
dense: false,
underlineColorAndroid: 'rgba(0,0,0,0)'
underlineColorAndroid: 'rgba(0,0,0,0)',
multiline: false,
autoGrow: false,
height: false,
keepHightlightColor: false
};

const styles = StyleSheet.create({
wrapper: {
height: 72,
paddingTop: 30,
paddingBottom: 7,
position: 'relative'
},
denseWrapper: {
height: 60,
paddingTop: 28,
paddingBottom: 4,
position: 'relative'
},
textInput: {
fontSize: 16,
height: 34,
lineHeight: 34
lineHeight: 34,
},
denseTextInput: {
fontSize: 13,
Expand Down
11 changes: 2 additions & 9 deletions lib/Underline.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
'use strict';
/* @flow */

import React, {
Component,
View,
StyleSheet,
Animated,
PropTypes
} from 'react-native';
import React, {Component, PropTypes} from "react";
import {View, StyleSheet, Animated} from "react-native";

export default class Underline extends Component {
constructor(props: Object) {
Expand Down