[add] TextInput support for onKeyPress

Fix #215
This commit is contained in:
Nicolas Gallagher
2016-10-27 22:17:59 -07:00
parent 1963e9109a
commit 9db3bd7e67
2 changed files with 9 additions and 0 deletions

View File

@@ -87,6 +87,11 @@ as an argument to the callback handler.
Callback that is called when the text input is focused.
**onKeyPress**: function
Callback that is called when a key is pressed. Pressed key value is passed as
an argument to the callback handler. Fires before `onChange` callbacks.
(web) **onSelectionChange**: function
Callback that is called when the text input's selection changes. The following

View File

@@ -35,6 +35,7 @@ class TextInput extends Component {
onChange: PropTypes.func,
onChangeText: PropTypes.func,
onFocus: PropTypes.func,
onKeyPress: PropTypes.func,
onSelectionChange: PropTypes.func,
placeholder: PropTypes.string,
placeholderTextColor: PropTypes.string,
@@ -87,6 +88,7 @@ class TextInput extends Component {
maxNumberOfLines,
multiline,
numberOfLines,
onKeyPress,
onLayout,
onSelectionChange,
placeholder,
@@ -139,6 +141,7 @@ class TextInput extends Component {
onBlur: this._handleBlur,
onChange: this._handleChange,
onFocus: this._handleFocus,
onKeyPress,
onSelect: onSelectionChange && this._handleSelectionChange,
readOnly: !editable,
ref: this._setInputRef,
@@ -200,6 +203,7 @@ class TextInput extends Component {
_handleChange = (e) => {
const { onChange, onChangeText } = this.props;
const text = e.target.value;
e.nativeEvent.text = text;
this.setState({ showPlaceholder: text === '' });
if (onChange) { onChange(e); }
if (onChangeText) { onChangeText(text); }