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.

LocalVideoMenu.js 3.9KB

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