Created
July 1, 2017 05:40
-
-
Save Obooman/6ef9f45de6b129fc7cfaf3ffdb8bb8b5 to your computer and use it in GitHub Desktop.
From https://stackoverflow.com/questions/33071950/how-would-i-grow-textinput-height-upon-text-wrapping
This file contains hidden or 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
class AutoExpandingTextInput extends React.Component { | |
state: any; | |
constructor(props) { | |
super(props); | |
this.state = {text: '', height: 0}; | |
} | |
render() { | |
return ( | |
<TextInput | |
{...this.props} | |
multiline={true} | |
onChange={(event) => { | |
this.setState({ | |
text: event.nativeEvent.text, | |
height: event.nativeEvent.contentSize.height, | |
}); | |
}} | |
style={[styles.default, {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