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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* eslint-disable react/no-multi-comp */
  2. import { useIsFocused } from '@react-navigation/native';
  3. import React, { useEffect } from 'react';
  4. import { translate } from '../../../base/i18n';
  5. import JitsiScreen from '../../../base/modal/components/JitsiScreen';
  6. import { connect } from '../../../base/redux';
  7. import { TabBarLabelCounter } from '../../../mobile/navigation/components/TabBarLabelCounter';
  8. import { closeChat } from '../../actions.native';
  9. import AbstractChat, {
  10. type Props as AbstractProps,
  11. _mapStateToProps
  12. } from '../AbstractChat';
  13. import ChatInputBar from './ChatInputBar';
  14. import MessageContainer from './MessageContainer';
  15. import MessageRecipient from './MessageRecipient';
  16. import styles from './styles';
  17. type Props = AbstractProps & {
  18. /**
  19. * Default prop for navigating between screen components(React Navigation).
  20. */
  21. navigation: Object,
  22. /**
  23. * Default prop for navigating between screen components(React Navigation).
  24. */
  25. route: Object
  26. };
  27. /**
  28. * Implements a React native component that renders the chat window (modal) of
  29. * the mobile client.
  30. */
  31. class Chat extends AbstractChat<Props> {
  32. /**
  33. * Implements React's {@link Component#render()}.
  34. *
  35. * @inheritdoc
  36. */
  37. render() {
  38. const { _messages, route } = this.props;
  39. const privateMessageRecipient = route?.params?.privateMessageRecipient;
  40. return (
  41. <JitsiScreen
  42. disableForcedKeyboardDismiss = { true }
  43. hasBottomTextInput = { true }
  44. hasTabNavigator = { true }
  45. style = { styles.chatContainer }>
  46. <MessageContainer messages = { _messages } />
  47. <MessageRecipient privateMessageRecipient = { privateMessageRecipient } />
  48. <ChatInputBar onSend = { this._onSendMessage } />
  49. </JitsiScreen>
  50. );
  51. }
  52. _onSendMessage: (string) => void;
  53. }
  54. export default translate(connect(_mapStateToProps)(props => {
  55. const { _nbUnreadMessages, dispatch, navigation, t } = props;
  56. const unreadMessagesNr = _nbUnreadMessages > 0;
  57. const isFocused = useIsFocused();
  58. useEffect(() => {
  59. navigation?.setOptions({
  60. tabBarLabel: () => (
  61. <TabBarLabelCounter
  62. activeUnreadNr = { unreadMessagesNr }
  63. isFocused = { isFocused }
  64. label = { t('chat.tabs.chat') }
  65. nbUnread = { _nbUnreadMessages } />
  66. )
  67. });
  68. return () => isFocused && dispatch(closeChat());
  69. }, [ isFocused, _nbUnreadMessages ]);
  70. return (
  71. <Chat { ...props } />
  72. );
  73. }));