Published
- 1 min read
react native multiline text box grow with content
The solution for this is noted below
react native multiline text box grow with content
Solution
// You can capture the size of your content with
// the onContentSizeChange() event listener.
const AutoExpandingTextInput = ({ ...props }) => {
const [text, setText] = useState('')
const [minHeight, setMinHeight] = useState()
return (
<TextInput
{...props}
multiline={true}
onChangeText={(text) => {
setText(text)
}}
onContentSizeChange={(event) => {
setMinHeight(event.nativeEvent.contentSize.height)
}}
style={[styles.default, { minHeight: minHeight }]}
value={text}
/>
)
}
Try other methods by searching on the site. That is if this doesn’t work