I have a custom multiline TextInput which grows/expands automatically to fit its content:
import React, { useState } from 'react'
import { TextInput } from 'react-native'
export function MyInput() {
const [value, setValue] = useState('Sample')
const [height, setHeight] = useState(56)
return (
<TextInput
value={value}
onChangeText={text => {
setValue(text)
}}
onContentSizeChange={event => {
setHeight(Math.max(56, event.nativeEvent.contentSize.height))
}}
multiline
style={{
padding: '16px',
height: height + 'px'
}}
/>
)
}
However if it is already expanded to multiple lines and I delete its content, onContentSizeChange does not fire and the empty lines are not removed automatically. Any way to fix this? Thanks!