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 3.7KB

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