2017-08-09 13:12:00 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-11-13 12:49:19 +00:00
|
|
|
import { View, TextInput, StyleSheet, SafeAreaView } from 'react-native';
|
2017-08-10 20:09:54 +00:00
|
|
|
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
|
|
import ImagePicker from 'react-native-image-picker';
|
|
|
|
import RocketChat from '../lib/rocketchat';
|
2017-08-09 13:12:00 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
textBox: {
|
|
|
|
paddingTop: 1,
|
2017-08-10 20:09:54 +00:00
|
|
|
borderTopWidth: 1,
|
|
|
|
borderTopColor: '#ccc',
|
2017-11-13 12:49:19 +00:00
|
|
|
backgroundColor: '#fff'
|
|
|
|
},
|
|
|
|
safeAreaView: {
|
2017-08-10 20:09:54 +00:00
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center'
|
2017-08-09 13:12:00 +00:00
|
|
|
},
|
|
|
|
textBoxInput: {
|
|
|
|
height: 40,
|
2017-08-11 18:18:09 +00:00
|
|
|
alignSelf: 'stretch',
|
2017-08-09 13:12:00 +00:00
|
|
|
backgroundColor: '#fff',
|
2017-08-10 20:09:54 +00:00
|
|
|
flexGrow: 1
|
|
|
|
},
|
|
|
|
fileButton: {
|
|
|
|
color: '#aaa',
|
|
|
|
paddingLeft: 23,
|
|
|
|
paddingRight: 20,
|
|
|
|
paddingTop: 10,
|
|
|
|
paddingBottom: 10,
|
|
|
|
fontSize: 20
|
2017-08-09 13:12:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default class MessageBox extends React.PureComponent {
|
|
|
|
static propTypes = {
|
2017-08-10 20:09:54 +00:00
|
|
|
onSubmit: PropTypes.func.isRequired,
|
|
|
|
rid: PropTypes.string.isRequired
|
2017-08-09 13:12:00 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 18:18:09 +00:00
|
|
|
submit(message) {
|
|
|
|
const text = message;
|
|
|
|
if (text.trim() === '') {
|
2017-08-09 13:12:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-08-22 01:24:41 +00:00
|
|
|
if (this.component) {
|
|
|
|
this.component.setNativeProps({ text: '' });
|
|
|
|
}
|
2017-08-11 18:18:09 +00:00
|
|
|
this.props.onSubmit(text);
|
|
|
|
}
|
2017-08-09 13:12:00 +00:00
|
|
|
|
2017-08-10 20:09:54 +00:00
|
|
|
addFile = () => {
|
|
|
|
const options = {
|
|
|
|
customButtons: [{
|
|
|
|
name: 'import', title: 'Import File From'
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
ImagePicker.showImagePicker(options, (response) => {
|
|
|
|
if (response.didCancel) {
|
|
|
|
console.log('User cancelled image picker');
|
|
|
|
} else if (response.error) {
|
|
|
|
console.log('ImagePicker Error: ', response.error);
|
|
|
|
} else if (response.customButton) {
|
|
|
|
console.log('User tapped custom button: ', response.customButton);
|
|
|
|
} else {
|
|
|
|
const fileInfo = {
|
|
|
|
name: response.fileName,
|
|
|
|
size: response.fileSize,
|
|
|
|
type: response.type || 'image/jpeg',
|
|
|
|
// description: '',
|
|
|
|
store: 'Uploads'
|
|
|
|
};
|
2017-08-15 19:28:46 +00:00
|
|
|
RocketChat.sendFileMessage(this.props.rid, fileInfo, response.data);
|
2017-08-10 20:09:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-09 13:12:00 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={styles.textBox}>
|
2017-11-13 12:49:19 +00:00
|
|
|
<SafeAreaView style={styles.safeAreaView}>
|
|
|
|
<Icon style={styles.fileButton} name='add-circle-outline' onPress={this.addFile} />
|
|
|
|
<TextInput
|
|
|
|
ref={component => this.component = component}
|
|
|
|
style={styles.textBoxInput}
|
|
|
|
returnKeyType='send'
|
|
|
|
onSubmitEditing={event => this.submit(event.nativeEvent.text)}
|
|
|
|
blurOnSubmit={false}
|
|
|
|
placeholder='New message'
|
|
|
|
underlineColorAndroid='transparent'
|
|
|
|
defaultValue=''
|
|
|
|
/>
|
|
|
|
</SafeAreaView>
|
2017-08-09 13:12:00 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|