2019-01-13 19:34:38 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React from 'react';
|
2019-04-25 13:17:49 +00:00
|
|
|
import { KeyboardAvoidingView, SafeAreaView } from 'react-native';
|
2019-01-13 19:34:38 +00:00
|
|
|
|
|
|
|
import { translate } from '../../../base/i18n';
|
2019-03-20 21:23:19 +00:00
|
|
|
|
2019-05-07 14:46:52 +00:00
|
|
|
import { HeaderWithNavigation, SlidingView } from '../../../base/react';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../../base/redux';
|
2019-01-13 19:34:38 +00:00
|
|
|
|
|
|
|
import AbstractChat, {
|
|
|
|
_mapDispatchToProps,
|
2019-03-20 21:23:19 +00:00
|
|
|
_mapStateToProps,
|
|
|
|
type Props
|
2019-01-13 19:34:38 +00:00
|
|
|
} from '../AbstractChat';
|
|
|
|
|
2019-04-25 13:17:49 +00:00
|
|
|
import ChatInputBar from './ChatInputBar';
|
|
|
|
import MessageContainer from './MessageContainer';
|
2019-01-13 19:34:38 +00:00
|
|
|
import styles from './styles';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a React native component that renders the chat window (modal) of
|
|
|
|
* the mobile client.
|
|
|
|
*/
|
|
|
|
class Chat extends AbstractChat<Props> {
|
2019-07-11 11:32:17 +00:00
|
|
|
/**
|
|
|
|
* Instantiates a new instance.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this._onClose = this._onClose.bind(this);
|
|
|
|
}
|
|
|
|
|
2019-01-13 19:34:38 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
return (
|
2019-03-20 21:23:19 +00:00
|
|
|
<SlidingView
|
2019-07-11 11:32:17 +00:00
|
|
|
onHide = { this._onClose }
|
2019-03-20 21:23:19 +00:00
|
|
|
position = 'bottom'
|
|
|
|
show = { this.props._isOpen } >
|
2019-04-25 13:17:49 +00:00
|
|
|
<KeyboardAvoidingView
|
|
|
|
behavior = 'padding'
|
|
|
|
style = { styles.chatContainer }>
|
2019-05-07 14:46:52 +00:00
|
|
|
<HeaderWithNavigation
|
|
|
|
headerLabelKey = 'chat.title'
|
2019-07-11 11:32:17 +00:00
|
|
|
onPressBack = { this._onClose } />
|
2019-03-20 21:23:19 +00:00
|
|
|
<SafeAreaView style = { styles.backdrop }>
|
2019-04-25 13:17:49 +00:00
|
|
|
<MessageContainer messages = { this.props._messages } />
|
|
|
|
<ChatInputBar onSend = { this.props._onSendMessage } />
|
2019-03-20 21:23:19 +00:00
|
|
|
</SafeAreaView>
|
2019-04-25 13:17:49 +00:00
|
|
|
</KeyboardAvoidingView>
|
2019-03-20 21:23:19 +00:00
|
|
|
</SlidingView>
|
2019-01-13 19:34:38 +00:00
|
|
|
);
|
|
|
|
}
|
2019-07-11 11:32:17 +00:00
|
|
|
|
|
|
|
_onClose: () => boolean
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes the chat window.
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_onClose() {
|
|
|
|
if (this.props._isOpen) {
|
|
|
|
this.props._onToggleChat();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-13 19:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps, _mapDispatchToProps)(Chat));
|