zl-react-native-gifted-chat
Version:
The most complete chat UI for React Native, based on 'react-native-gifted-chat'
64 lines (59 loc) • 1.47 kB
JavaScript
import React from 'react';
import {
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
export default class Send extends React.Component {
// shouldComponentUpdate(nextProps, nextState) {
// if (this.props.text.trim().length === 0 && nextProps.text.trim().length > 0 || this.props.text.trim().length > 0 && nextProps.text.trim().length === 0) {
// return true;
// }
// return false;
// }
render() {
if (this.props.text.trim().length > 0) {
return (
<TouchableOpacity
style={[styles.container, this.props.containerStyle]}
onPress={() => {
this.props.onSend({text: this.props.text.trim()}, true);
}}
>
<Text style={[styles.text, this.props.textStyle]}>{this.props.label}</Text>
</TouchableOpacity>
);
}
return <View/>;
}
}
const styles = StyleSheet.create({
container: {
height: 44,
justifyContent: 'flex-end',
},
text: {
color: '#0084ff',
fontWeight: '600',
fontSize: 17,
backgroundColor: 'transparent',
marginBottom: 12,
marginLeft: 10,
marginRight: 10,
},
});
Send.defaultProps = {
containerStyle: {},
textStyle: {},
text: '',
onSend: () => {},
label: 'Send',
};
Send.propTypes = {
containerStyle: React.PropTypes.object,
textStyle: React.PropTypes.object,
text: React.PropTypes.string,
onSend: React.PropTypes.func,
label: React.PropTypes.string,
};