Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onContentSizeChange not firing on height change on Android (react-native)

onContentSizeChange doesn't seem to fire properly on Android. Event is fired on mount, but isn't fired on text height change. Identical code works fine for iOS:

<TextInput
  editable = {true}
  multiline = {true}
  [...]
  onContentSizeChange={(event) => {
  this.setState({height: event.nativeEvent.contentSize.height});
  }}
  style={{height: Math.max(35, this.state.height)}}
/>
like image 920
Christopher Gilson Avatar asked Jan 16 '17 06:01

Christopher Gilson


1 Answers

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

In Android onContentSizeChange is called only once use onChange instead of onContentSizeChange.

Code

<TextInput
  editable = {true}
  multiline = {true}
  [...]
  onChange={(event) => {
  this.setState({height: event.nativeEvent.contentSize.height});
  }}
  style={{height: Math.max(35, this.state.height)}}
/>
like image 94
Vishwesh Jainkuniya Avatar answered Nov 19 '22 22:11

Vishwesh Jainkuniya