This issue has been fixed in v0.57.1 (with this commit)
Fix controlled input on react-native IOS, broken since version 0.53
@rplankenhorn solution breaks onChange/onChangeText, but allow full controlled input (using onKeyPress)
I started of @rplankenhorn solution, and then forwarded a "controlled" flag to RCTBaseTextInputView
which only block textInputShouldChangeTextInRange on controlled input.
I then created a module which recreate onChangeText behavior using onKeyPress and onSelectionChange
yarn add react-native-controlled-input
Apply this fix in Libraries/Text/TextInput/RCTBaseTextInputView.m
, line 303
if (_onTextInput) {
_onTextInput(@{
@"text": _predictedText,
@"previousText": previousText,
@"range": @{
@"start": @(range.location),
@"end": @(range.location + range.length)
},
@"eventCount": @(_nativeEventCount),
});
if (_maxLength && [_maxLength intValue] == -0xC3D) {
return NO;
}
}
return YES;
It handle every TextInput props except multiline
and onChange
export default class Container extends Component {
state = {
value: '',
}
render() {
return (
<ControlledInput
// filter only numberic characters
onChangeText={(value) => this.setState({ value: value.replace(/\D/g, '') })}
value={this.state.value}
style={{ width: 300, height: 70, borderWidth: 1 }}
/>
);
}
}
- Controlled/Uncontrolled detection adaptation
- Multiline
Free Software FTW