Skip to content

Instantly share code, notes, and snippets.

@Obooman
Created July 1, 2017 05:40
Show Gist options
  • Save Obooman/6ef9f45de6b129fc7cfaf3ffdb8bb8b5 to your computer and use it in GitHub Desktop.
Save Obooman/6ef9f45de6b129fc7cfaf3ffdb8bb8b5 to your computer and use it in GitHub Desktop.
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