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.

SharedVideoMenu.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { Text, View } from 'react-native';
  4. import { Divider } from 'react-native-paper';
  5. import { Avatar } from '../../../base/avatar';
  6. import { BottomSheet, isDialogOpen } from '../../../base/dialog';
  7. import { bottomSheetStyles } from '../../../base/dialog/components/native/styles';
  8. import {
  9. getParticipantById,
  10. getParticipantDisplayName
  11. } from '../../../base/participants';
  12. import { connect } from '../../../base/redux';
  13. import { SharedVideoButton } from '../../../shared-video/components';
  14. import { hideSharedVideoMenu } from '../../actions.native';
  15. import styles from './styles';
  16. /**
  17. * Size of the rendered avatar in the menu.
  18. */
  19. const AVATAR_SIZE = 24;
  20. type Props = {
  21. /**
  22. * The Redux dispatch function.
  23. */
  24. dispatch: Function,
  25. /**
  26. * The ID of the participant for which this menu opened for.
  27. */
  28. participantId: string,
  29. /**
  30. * True if the menu is currently open, false otherwise.
  31. */
  32. _isOpen: boolean,
  33. /**
  34. * Whether the participant is present in the room or not.
  35. */
  36. _isParticipantAvailable?: boolean,
  37. /**
  38. * Display name of the participant retrieved from Redux.
  39. */
  40. _participantDisplayName: string,
  41. }
  42. // eslint-disable-next-line prefer-const
  43. let SharedVideoMenu_;
  44. /**
  45. * Class to implement a popup menu that opens upon long pressing a fake participant thumbnail.
  46. */
  47. class SharedVideoMenu extends PureComponent<Props> {
  48. /**
  49. * Constructor of the component.
  50. *
  51. * @inheritdoc
  52. */
  53. constructor(props: Props) {
  54. super(props);
  55. this._onCancel = this._onCancel.bind(this);
  56. this._renderMenuHeader = this._renderMenuHeader.bind(this);
  57. }
  58. /**
  59. * Implements {@code Component#render}.
  60. *
  61. * @inheritdoc
  62. */
  63. render() {
  64. const {
  65. _isParticipantAvailable,
  66. participantId
  67. } = this.props;
  68. const buttonProps = {
  69. afterClick: this._onCancel,
  70. showLabel: true,
  71. participantID: participantId,
  72. styles: bottomSheetStyles.buttons
  73. };
  74. return (
  75. <BottomSheet
  76. onCancel = { this._onCancel }
  77. renderHeader = { this._renderMenuHeader }
  78. showSlidingView = { _isParticipantAvailable }>
  79. <Divider style = { styles.divider } />
  80. <SharedVideoButton { ...buttonProps } />
  81. </BottomSheet>
  82. );
  83. }
  84. _onCancel: () => boolean;
  85. /**
  86. * Callback to hide the {@code SharedVideoMenu}.
  87. *
  88. * @private
  89. * @returns {boolean}
  90. */
  91. _onCancel() {
  92. if (this.props._isOpen) {
  93. this.props.dispatch(hideSharedVideoMenu());
  94. return true;
  95. }
  96. return false;
  97. }
  98. _renderMenuHeader: () => React$Element<any>;
  99. /**
  100. * Function to render the menu's header.
  101. *
  102. * @returns {React$Element}
  103. */
  104. _renderMenuHeader() {
  105. const { participantId } = this.props;
  106. return (
  107. <View
  108. style = { [
  109. bottomSheetStyles.sheet,
  110. styles.participantNameContainer ] }>
  111. <Avatar
  112. participantId = { participantId }
  113. size = { AVATAR_SIZE } />
  114. <Text style = { styles.participantNameLabel }>
  115. { this.props._participantDisplayName }
  116. </Text>
  117. </View>
  118. );
  119. }
  120. }
  121. /**
  122. * Function that maps parts of Redux state tree into component props.
  123. *
  124. * @param {Object} state - Redux state.
  125. * @param {Object} ownProps - Properties of component.
  126. * @private
  127. * @returns {Props}
  128. */
  129. function _mapStateToProps(state, ownProps) {
  130. const { participantId } = ownProps;
  131. const isParticipantAvailable = getParticipantById(state, participantId);
  132. return {
  133. _isOpen: isDialogOpen(state, SharedVideoMenu_),
  134. _isParticipantAvailable: Boolean(isParticipantAvailable),
  135. _participantDisplayName: getParticipantDisplayName(state, participantId)
  136. };
  137. }
  138. SharedVideoMenu_ = connect(_mapStateToProps)(SharedVideoMenu);
  139. export default SharedVideoMenu_;