Javascript React Native:TextInput元素上的onContentSizeChange事件在Android上不起作用
我在Android设备上遇到TextInput事件“onContentSizeChange”问题。 事实上,当我键入消息时,直到行尾和文本进入下一行时才触发。TextInput的高度没有更新 例如:Javascript React Native:TextInput元素上的onContentSizeChange事件在Android上不起作用,javascript,android,react-native,Javascript,Android,React Native,我在Android设备上遇到TextInput事件“onContentSizeChange”问题。 事实上,当我键入消息时,直到行尾和文本进入下一行时才触发。TextInput的高度没有更新 例如: return ( <TextInput {...this.props} multiline={Boolean(true)} onChangeText={(text) => { this.setState({t
return (
<TextInput
{...this.props}
multiline={Boolean(true)}
onChangeText={(text) => {
this.setState({text})
}}
onContentSizeChange={(event) => {
this.setState({height: event.nativeEvent.contentSize.height})
}}
style={[ additionalStyles, {height: this.state.height}, {fontSize: config.defaultFontSize} ]}
value={this.state.text}
underlineColorAndroid={'rgba(0,0,0,0)'}
/>
)
返回(
{
this.setState({text})
}}
onContentSizeChange={(事件)=>{
this.setState({height:event.nativeEvent.contentSize.height})
}}
样式={[additionalStyles,{height:this.state.height},{fontSize:config.defaultFontSize}]}
值={this.state.text}
underlineColorAndroid={'rgba(0,0,0,0')}
/>
)
有人知道为什么会这样吗
注意:帮助使用onChange而不是onContentSizeChange,请参见。这看起来将在即将发布的版本中修复。目前还不清楚,几周前才修复,但可能是0.46。试试内容大小更改
onContentSizeChange={e=>{
let inputH = Math.max(e.nativeEvent.contentSize.height, 35)
if(inputH>120) inputH =100
setIputHeight(inputH)
}}
帮助使用onChange而不是onContentSizeChange,谢谢!