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

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