Created
September 17, 2016 19:30
-
-
Save ackdav/788475f164786398fedc615b60ff6e5a to your computer and use it in GitHub Desktop.
AutoExpandingTextInput for React-Native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react' | |
import {TextInput} from 'react-native' | |
export default class AutoExpandingTextInput extends Component { | |
state: any; | |
constructor(props) { | |
super(props); | |
this.state = {text: '',tags:[], height: 0}; | |
} | |
render() { | |
return ( | |
<TextInput | |
{...this.props} | |
multiline={true} | |
onChange={(event) => { | |
this.setState({ | |
text: event.nativeEvent.text, | |
height: event.nativeEvent.contentSize.height, | |
}); | |
}} | |
style={[this.props.style, {height: Math.max(35, this.state.height)}]} | |
value={this.state.text} | |
/> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment