I want to create a TextInput which can grow automatically when it has multilines.
To implement auto grow multiline text input, you can adjust the height of the text input according to the content size in the textInput.
you can use onContentSizeChange prop in TextInput and call a function to increase/decrease the height of input.
Here is the quick example code
export default class YourComponent extends Component {
constructor (props) {
super(props);
this.state = {
newValue: '',
height: 40
}
}
updateSize = (height) => {
this.setState({
height
});
}
render () {
const {newValue, height} = this.state;
let newStyle = {
height
}
return (
this.setState({value})}
style={[newStyle]}
editable
multiline
value={value}
onContentSizeChange={(e) => this.updateSize(e.nativeEvent.contentSize.height)}
/>
)
}
}
OR
You might want to use react-native-auto-grow-textinput