vn-verdnaturachat/app/components/MessageBox.js

55 lines
985 B
JavaScript
Raw Normal View History

2017-08-09 13:12:00 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import { View, TextInput, StyleSheet } from 'react-native';
const styles = StyleSheet.create({
textBox: {
paddingTop: 1,
backgroundColor: '#ccc'
},
textBoxInput: {
height: 40,
backgroundColor: '#fff',
paddingLeft: 15
}
});
export default class MessageBox extends React.PureComponent {
static propTypes = {
onSubmit: PropTypes.func.isRequired
}
constructor(props) {
super(props);
this.state = {
text: ''
};
}
submit = () => {
if (this.state.text.trim() === '') {
return;
}
2017-08-09 18:15:44 +00:00
this.props.onSubmit(this.state.text);
this.setState({ text: '' });
2017-08-09 13:12:00 +00:00
};
render() {
return (
<View style={styles.textBox}>
<TextInput
style={styles.textBoxInput}
value={this.state.text}
onChangeText={text => this.setState({ text })}
returnKeyType='send'
onSubmitEditing={this.submit}
blurOnSubmit={false}
placeholder='New message'
/>
</View>
);
}
}