You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Chat.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // @flow
  2. import React from 'react';
  3. import { KeyboardAvoidingView, SafeAreaView } from 'react-native';
  4. import { translate } from '../../../base/i18n';
  5. import { HeaderWithNavigation, SlidingView } from '../../../base/react';
  6. import { connect } from '../../../base/redux';
  7. import AbstractChat, {
  8. _mapDispatchToProps,
  9. _mapStateToProps,
  10. type Props
  11. } from '../AbstractChat';
  12. import ChatInputBar from './ChatInputBar';
  13. import MessageContainer from './MessageContainer';
  14. import styles from './styles';
  15. /**
  16. * Implements a React native component that renders the chat window (modal) of
  17. * the mobile client.
  18. */
  19. class Chat extends AbstractChat<Props> {
  20. /**
  21. * Instantiates a new instance.
  22. *
  23. * @inheritdoc
  24. */
  25. constructor(props: Props) {
  26. super(props);
  27. this._onClose = this._onClose.bind(this);
  28. }
  29. /**
  30. * Implements React's {@link Component#render()}.
  31. *
  32. * @inheritdoc
  33. */
  34. render() {
  35. return (
  36. <SlidingView
  37. onHide = { this._onClose }
  38. position = 'bottom'
  39. show = { this.props._isOpen } >
  40. <KeyboardAvoidingView
  41. behavior = 'padding'
  42. style = { styles.chatContainer }>
  43. <HeaderWithNavigation
  44. headerLabelKey = 'chat.title'
  45. onPressBack = { this._onClose } />
  46. <SafeAreaView style = { styles.backdrop }>
  47. <MessageContainer messages = { this.props._messages } />
  48. <ChatInputBar onSend = { this.props._onSendMessage } />
  49. </SafeAreaView>
  50. </KeyboardAvoidingView>
  51. </SlidingView>
  52. );
  53. }
  54. _onClose: () => boolean
  55. /**
  56. * Closes the chat window.
  57. *
  58. * @returns {boolean}
  59. */
  60. _onClose() {
  61. if (this.props._isOpen) {
  62. this.props._onToggleChat();
  63. return true;
  64. }
  65. return false;
  66. }
  67. }
  68. export default translate(connect(_mapStateToProps, _mapDispatchToProps)(Chat));