Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Chat.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // @flow
  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 { closeChat } from '../../actions.any';
  8. import AbstractChat, {
  9. _mapStateToProps,
  10. type Props as AbstractProps
  11. } from '../AbstractChat';
  12. import ChatInputBar from './ChatInputBar';
  13. import MessageContainer from './MessageContainer';
  14. import MessageRecipient from './MessageRecipient';
  15. import styles from './styles';
  16. type Props = AbstractProps & {
  17. /**
  18. * Is this screen focused or not(React Navigation).
  19. */
  20. isChatScreenFocused: boolean,
  21. /**
  22. * Default prop for navigating between screen components(React Navigation).
  23. */
  24. navigation: Object,
  25. /**
  26. * Default prop for navigating between screen components(React Navigation).
  27. */
  28. route: Object
  29. };
  30. /**
  31. * Implements a React native component that renders the chat window (modal) of
  32. * the mobile client.
  33. */
  34. class Chat extends AbstractChat<Props> {
  35. /**
  36. * Implements React's {@link Component#render()}.
  37. *
  38. * @inheritdoc
  39. */
  40. render() {
  41. const { _messages, route } = this.props;
  42. const privateMessageRecipient = route.params?.privateMessageRecipient;
  43. return (
  44. <JitsiScreen
  45. hasBottomTextInput = { true }
  46. hasTabNavigator = { true }
  47. style = { styles.chatContainer }>
  48. <MessageContainer messages = { _messages } />
  49. <MessageRecipient privateMessageRecipient = { privateMessageRecipient } />
  50. <ChatInputBar onSend = { this._onSendMessage } />
  51. </JitsiScreen>
  52. );
  53. }
  54. _onSendMessage: (string) => void;
  55. }
  56. export default translate(connect(_mapStateToProps)(props => {
  57. const {
  58. _nbUnreadMessages,
  59. navigation,
  60. t
  61. } = props;
  62. const isChatScreenFocused = useIsFocused();
  63. const nrUnreadMessages
  64. = !isChatScreenFocused && _nbUnreadMessages > 0
  65. ? `(${_nbUnreadMessages})` : '';
  66. useEffect(() => {
  67. navigation.setOptions({
  68. tabBarLabel: `${t('chat.tabs.chat')} ${nrUnreadMessages}`
  69. });
  70. return () => props.dispatch(closeChat());
  71. }, [ nrUnreadMessages ]);
  72. return (
  73. <Chat
  74. { ...props }
  75. isChatScreenFocused = { isChatScreenFocused } />
  76. );
  77. }));