您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Chat.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // @flow
  2. import React from 'react';
  3. import { KeyboardAvoidingView, SafeAreaView } from 'react-native';
  4. import { ColorSchemeRegistry } from '../../../base/color-scheme';
  5. import { translate } from '../../../base/i18n';
  6. import { HeaderWithNavigation, SlidingView } from '../../../base/react';
  7. import { connect } from '../../../base/redux';
  8. import { StyleType } from '../../../base/styles';
  9. import AbstractChat, {
  10. _mapDispatchToProps,
  11. _mapStateToProps as _abstractMapStateToProps,
  12. type Props as AbstractProps
  13. } from '../AbstractChat';
  14. import ChatInputBar from './ChatInputBar';
  15. import MessageContainer from './MessageContainer';
  16. import MessageRecipient from './MessageRecipient';
  17. import styles from './styles';
  18. type Props = AbstractProps & {
  19. /**
  20. * The color-schemed stylesheet of the feature.
  21. */
  22. _styles: StyleType
  23. };
  24. /**
  25. * Implements a React native component that renders the chat window (modal) of
  26. * the mobile client.
  27. */
  28. class Chat extends AbstractChat<Props> {
  29. /**
  30. * Instantiates a new instance.
  31. *
  32. * @inheritdoc
  33. */
  34. constructor(props: Props) {
  35. super(props);
  36. this._onClose = this._onClose.bind(this);
  37. }
  38. /**
  39. * Implements React's {@link Component#render()}.
  40. *
  41. * @inheritdoc
  42. */
  43. render() {
  44. const { _styles } = this.props;
  45. return (
  46. <SlidingView
  47. onHide = { this._onClose }
  48. position = 'bottom'
  49. show = { this.props._isOpen } >
  50. <KeyboardAvoidingView
  51. behavior = 'padding'
  52. style = { styles.chatContainer }>
  53. <HeaderWithNavigation
  54. headerLabelKey = 'chat.title'
  55. onPressBack = { this._onClose } />
  56. <SafeAreaView style = { _styles.backdrop }>
  57. <MessageContainer messages = { this.props._messages } />
  58. <MessageRecipient />
  59. <ChatInputBar onSend = { this.props._onSendMessage } />
  60. </SafeAreaView>
  61. </KeyboardAvoidingView>
  62. </SlidingView>
  63. );
  64. }
  65. _onClose: () => boolean
  66. /**
  67. * Closes the chat window.
  68. *
  69. * @returns {boolean}
  70. */
  71. _onClose() {
  72. if (this.props._isOpen) {
  73. this.props._onToggleChat();
  74. return true;
  75. }
  76. return false;
  77. }
  78. }
  79. /**
  80. * Maps part of the redux state to the props of this component.
  81. *
  82. * @param {Object} state - The Redux state.
  83. * @returns {Props}
  84. */
  85. function _mapStateToProps(state) {
  86. return {
  87. ..._abstractMapStateToProps(state),
  88. _styles: ColorSchemeRegistry.get(state, 'Chat')
  89. };
  90. }
  91. export default translate(connect(_mapStateToProps, _mapDispatchToProps)(Chat));