Skip to content

Instantly share code, notes, and snippets.

@ackdav
Created September 17, 2016 19:30
Show Gist options
  • Save ackdav/788475f164786398fedc615b60ff6e5a to your computer and use it in GitHub Desktop.
Save ackdav/788475f164786398fedc615b60ff6e5a to your computer and use it in GitHub Desktop.
AutoExpandingTextInput for React-Native
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