Skip to content

onChange/onContentSizeChange not called for <TextInput> when set text to child <Text> #13732

@huangmr

Description

@huangmr

Description

onChange/onContentSizeChange not called after setting text to child in , it only works when sets value to it directly (on IOS only).

Reproduction Steps and Sample Code

Set text props to the component doesn't trigger TextInput to expand.

An example of your code is REQUIRED

export class ExpandingTextInput extends React.Component {
  props: Props;
  state: State = {
    height: this.props.minHeight,
  };

  onContentSizeChange = (event) => {
    const height = event.nativeEvent.contentSize.height;
     this.setState({ height });
  };

  render() {
    return (
      <TextInput
        {...this.props}
        multiline
        onContentSizeChange={this. onContentSizeChange}
        style={[this.props.style, { height: this.state.height }]}
      >
        {this.props.children}
      </TextInput>
    )
  }
}

and this is how it is being used

<ExpandingTextInput {...this.props}>
      <Text>{this.props.text}</Text>
</ExpandingTextInput>

Solution

Still working on one...

Additional Information

  • React Native version: [FILL THIS OUT: Be specific, filling out "latest" here is not enough.]
  • Platform: [FILL THIS OUT: iOS, Android, or both?]
  • Development Operating System: [FILL THIS OUT: Are you developing on MacOS, Linux, or Windows?]
  • Dev tools: [FILL THIS OUT: Xcode or Android Studio version, iOS or Android SDK version, if applicable]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions