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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 ID of the participant for which this menu opened for.
  28. */
  29. participantId: string,
  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. // eslint-disable-next-line prefer-const
  48. let SharedVideoMenu_;
  49. /**
  50. * Class to implement a popup menu that opens upon long pressing a fake participant thumbnail.
  51. */
  52. class SharedVideoMenu extends PureComponent<Props> {
  53. /**
  54. * Constructor of the component.
  55. *
  56. * @inheritdoc
  57. */
  58. constructor(props: Props) {
  59. super(props);
  60. this._onCancel = this._onCancel.bind(this);
  61. this._renderMenuHeader = this._renderMenuHeader.bind(this);
  62. }
  63. /**
  64. * Implements {@code Component#render}.
  65. *
  66. * @inheritdoc
  67. */
  68. render() {
  69. const {
  70. _isParticipantAvailable,
  71. participantId
  72. } = this.props;
  73. const buttonProps = {
  74. afterClick: this._onCancel,
  75. showLabel: true,
  76. participantID: participantId,
  77. styles: this.props._bottomSheetStyles.buttons
  78. };
  79. return (
  80. <BottomSheet
  81. onCancel = { this._onCancel }
  82. renderHeader = { this._renderMenuHeader }
  83. showSlidingView = { _isParticipantAvailable }>
  84. <Divider style = { styles.divider } />
  85. <SharedVideoButton { ...buttonProps } />
  86. </BottomSheet>
  87. );
  88. }
  89. _onCancel: () => boolean;
  90. /**
  91. * Callback to hide the {@code SharedVideoMenu}.
  92. *
  93. * @private
  94. * @returns {boolean}
  95. */
  96. _onCancel() {
  97. if (this.props._isOpen) {
  98. this.props.dispatch(hideSharedVideoMenu());
  99. return true;
  100. }
  101. return false;
  102. }
  103. _renderMenuHeader: () => React$Element<any>;
  104. /**
  105. * Function to render the menu's header.
  106. *
  107. * @returns {React$Element}
  108. */
  109. _renderMenuHeader() {
  110. const { _bottomSheetStyles, participantId } = this.props;
  111. return (
  112. <View
  113. style = { [
  114. _bottomSheetStyles.sheet,
  115. styles.participantNameContainer ] }>
  116. <Avatar
  117. participantId = { participantId }
  118. size = { AVATAR_SIZE } />
  119. <Text style = { styles.participantNameLabel }>
  120. { this.props._participantDisplayName }
  121. </Text>
  122. </View>
  123. );
  124. }
  125. }
  126. /**
  127. * Function that maps parts of Redux state tree into component props.
  128. *
  129. * @param {Object} state - Redux state.
  130. * @param {Object} ownProps - Properties of component.
  131. * @private
  132. * @returns {Props}
  133. */
  134. function _mapStateToProps(state, ownProps) {
  135. const { participantId } = ownProps;
  136. const isParticipantAvailable = getParticipantById(state, participantId);
  137. return {
  138. _bottomSheetStyles: ColorSchemeRegistry.get(state, 'BottomSheet'),
  139. _isOpen: isDialogOpen(state, SharedVideoMenu_),
  140. _isParticipantAvailable: Boolean(isParticipantAvailable),
  141. _participantDisplayName: getParticipantDisplayName(state, participantId)
  142. };
  143. }
  144. SharedVideoMenu_ = connect(_mapStateToProps)(SharedVideoMenu);
  145. export default SharedVideoMenu_;