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
|
|
|
|
2019-10-15 14:08:23 +00:00
|
|
|
import { ColorSchemeRegistry } from '../../../base/color-scheme';
|
2019-01-13 19:34:38 +00:00
|
|
|
import { translate } from '../../../base/i18n';
|
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-10-15 14:08:23 +00:00
|
|
|
import { StyleType } from '../../../base/styles';
|
2019-01-13 19:34:38 +00:00
|
|
|
|
|
|
|
import AbstractChat, {
|
|
|
|
_mapDispatchToProps,
|
2019-10-15 14:08:23 +00:00
|
|
|
_mapStateToProps as _abstractMapStateToProps,
|
|
|
|
type Props as AbstractProps
|
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-10-07 12:35:04 +00:00
|
|
|
import MessageRecipient from './MessageRecipient';
|
2019-01-13 19:34:38 +00:00
|
|
|
import styles from './styles';
|
|
|
|
|
2019-10-15 14:08:23 +00:00
|
|
|
type Props = AbstractProps & {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The color-schemed stylesheet of the feature.
|
|
|
|
*/
|
|
|
|
_styles: StyleType
|
|
|
|
};
|
|
|
|
|
2019-01-13 19:34:38 +00:00
|
|
|
/**
|
|
|
|
* 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() {
|
2019-10-15 14:08:23 +00:00
|
|
|
const { _styles } = this.props;
|
|
|
|
|
2019-01-13 19:34:38 +00:00
|
|
|
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-10-15 14:08:23 +00:00
|
|
|
<SafeAreaView style = { _styles.backdrop }>
|
2019-04-25 13:17:49 +00:00
|
|
|
<MessageContainer messages = { this.props._messages } />
|
2019-10-07 12:35:04 +00:00
|
|
|
<MessageRecipient />
|
2019-04-25 13:17:49 +00:00
|
|
|
<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
|
|
|
}
|
|
|
|
|
2019-10-15 14:08:23 +00:00
|
|
|
/**
|
|
|
|
* Maps part of the redux state to the props of this component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
..._abstractMapStateToProps(state),
|
|
|
|
_styles: ColorSchemeRegistry.get(state, 'Chat')
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-13 19:34:38 +00:00
|
|
|
export default translate(connect(_mapStateToProps, _mapDispatchToProps)(Chat));
|