onContentSizeChange在Android上没有触发高度变化(react-native)

Chr*_*son 8 react-native react-native-android

onContentSizeChange在Android上似乎无法正常启动.事件被触发mount,但不会在text height更改时触发.相同的代码适用于iOS:

<TextInput
  editable = {true}
  multiline = {true}
  [...]
  onContentSizeChange={(event) => {
  this.setState({height: event.nativeEvent.contentSize.height});
  }}
  style={{height: Math.max(35, this.state.height)}}
/>
Run Code Online (Sandbox Code Playgroud)

Vis*_*iya 7

https://github.com/facebook/react-native/issues/6552#issuecomment-269989962

在Android onContentSizeChange中只调用一次onChange而不是onContentSizeChange.

<TextInput
  editable = {true}
  multiline = {true}
  [...]
  onChange={(event) => {
  this.setState({height: event.nativeEvent.contentSize.height});
  }}
  style={{height: Math.max(35, this.state.height)}}
/>
Run Code Online (Sandbox Code Playgroud)

  • 这不再是一个好的解决方法,它已被弃用:https://github.com/facebook/react-native/commit/bac84ce207a0466cec95626131063751eb48b964 (2认同)