Search code examples
react-nativereact-native-textinput

ReactNative TextInput' onChangeText is not called


I want onTextChange to be triggered when I set text to it through state changes. I am building my on screen number keyboard to enter a pin code, and I want to catch text changes on TextInput when user presses these keys.

this.setState({text})

My TextInput looks like this:

<TextInput
  editable={false}
  onChangeText={text => Alert.alert(text)}
  secureTextEntry={true}
  value={this.state.text}

UPD: I found somehow related question, but it too doesn't have an answer: TextInput not working as expected when programmatically entering text


Solution

  • I ended up using onContentSizeChange, which gets called when text changes. I did find that some TextInput methods doesn't work properly when text is set programmatically.