Last active
February 19, 2016 10:24
-
-
Save cornedor/e4d77e5742bdeedccb04 to your computer and use it in GitHub Desktop.
Wrapper around React Native's TextInput to make getting the text easier.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { | |
Component, | |
PropTypes, | |
TextInput as NativeTextInput | |
} from 'react-native'; | |
/** | |
* Wrapper for the native TextInput which adds getValue() | |
**/ | |
class TextInput extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
text: '', | |
}; | |
this.onChange = this._onChange.bind(this); | |
} | |
getValue() { | |
return this.state.text; | |
} | |
_onChange(text) { | |
this.setState({ text }); | |
if (this.props.onChangeText !== undefined) { | |
this.props.onChangeText(text); | |
} | |
} | |
render() { | |
return ( | |
<NativeTextInput {...this.props} onChangeText={this.onChange} /> | |
); | |
} | |
} | |
TextInput.propTypes = { | |
onChangeText: PropTypes.func, | |
}; | |
export default TextInput; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment