diff --git a/src/components/Input.tsx b/src/components/Input.tsx index 136a57a..e5eadfd 100644 --- a/src/components/Input.tsx +++ b/src/components/Input.tsx @@ -25,25 +25,38 @@ interface State { value: string } -export default class Input extends Component { - constructor() { +interface Props { + value: string; + onSubmit: (text: string) => void; +} + +export default class Input extends Component { + constructor(props : Props) { super(); this.state = { - value: '' + value: props.value }; this.handleChange = this.handleChange.bind(this); + this.handleSubmit = this.handleSubmit.bind(this); } handleChange(value : string) { this.setState({ value }); } + handleSubmit() { + if (this.props.onSubmit) { + this.props.onSubmit(this.state.value); + } + } + render() { return ( { blurOnSubmit enablesReturnKeyAutomatically /> - - ) + ); } } diff --git a/src/views/main.tsx b/src/views/main.tsx index 2b8bf19..000eff7 100644 --- a/src/views/main.tsx +++ b/src/views/main.tsx @@ -21,11 +21,27 @@ const styles = StyleSheet.create({ }); -export default class App extends Component { +interface State { + text: string +} + +export default class App extends Component { + constructor() { + super() + this.state = { + text: '' + }; + this.handleSubmit = this.handleSubmit.bind(this); + } + + handleSubmit(text : string) { + this.setState({ text }); + } + render() { return ( - + Welcome to React Native!