Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

LocalVideoMenu.tsx 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import React, { PureComponent } from 'react';
  2. import { Text, TextStyle, View, ViewStyle } from 'react-native';
  3. import { connect } from 'react-redux';
  4. import { IReduxState, IStore } from '../../../app/types';
  5. import Avatar from '../../../base/avatar/components/Avatar';
  6. import { hideSheet } from '../../../base/dialog/actions';
  7. import BottomSheet from '../../../base/dialog/components/native/BottomSheet';
  8. import { bottomSheetStyles } from '../../../base/dialog/components/native/styles';
  9. import { translate } from '../../../base/i18n/functions';
  10. import {
  11. getLocalParticipant,
  12. getParticipantCount,
  13. getParticipantDisplayName
  14. } from '../../../base/participants/functions';
  15. import { ILocalParticipant } from '../../../base/participants/types';
  16. import ToggleSelfViewButton from '../../../toolbox/components/native/ToggleSelfViewButton';
  17. import ConnectionStatusButton from './ConnectionStatusButton';
  18. import DemoteToVisitorButton from './DemoteToVisitorButton';
  19. import styles from './styles';
  20. /**
  21. * Size of the rendered avatar in the menu.
  22. */
  23. const AVATAR_SIZE = 24;
  24. interface IProps {
  25. /**
  26. * The local participant.
  27. */
  28. _participant?: ILocalParticipant;
  29. /**
  30. * Display name of the participant retrieved from Redux.
  31. */
  32. _participantDisplayName: string;
  33. /**
  34. * Shows/hides the local switch to visitor button.
  35. */
  36. _showDemote: boolean;
  37. /**
  38. * The Redux dispatch function.
  39. */
  40. dispatch: IStore['dispatch'];
  41. /**
  42. * Translation function.
  43. */
  44. t: Function;
  45. }
  46. /**
  47. * Class to implement a popup menu that opens upon long pressing a thumbnail.
  48. */
  49. class LocalVideoMenu extends PureComponent<IProps> {
  50. /**
  51. * Constructor of the component.
  52. *
  53. * @inheritdoc
  54. */
  55. constructor(props: IProps) {
  56. super(props);
  57. this._onCancel = this._onCancel.bind(this);
  58. this._renderMenuHeader = this._renderMenuHeader.bind(this);
  59. }
  60. /**
  61. * Implements {@code Component#render}.
  62. *
  63. * @inheritdoc
  64. */
  65. render() {
  66. const { _participant, _showDemote } = this.props;
  67. const buttonProps = {
  68. afterClick: this._onCancel,
  69. showLabel: true,
  70. participantID: _participant?.id ?? '',
  71. styles: bottomSheetStyles.buttons
  72. };
  73. const connectionStatusButtonProps = {
  74. ...buttonProps,
  75. afterClick: undefined
  76. };
  77. return (
  78. <BottomSheet
  79. renderHeader = { this._renderMenuHeader }
  80. showSlidingView = { true }>
  81. <ToggleSelfViewButton { ...buttonProps } />
  82. { _showDemote && <DemoteToVisitorButton { ...buttonProps } /> }
  83. <ConnectionStatusButton { ...connectionStatusButtonProps } />
  84. </BottomSheet>
  85. );
  86. }
  87. /**
  88. * Function to render the menu's header.
  89. *
  90. * @returns {React$Element}
  91. */
  92. _renderMenuHeader() {
  93. const { _participant } = this.props;
  94. return (
  95. <View
  96. style = { [
  97. bottomSheetStyles.sheet,
  98. styles.participantNameContainer ] as ViewStyle[] }>
  99. <Avatar
  100. participantId = { _participant?.id }
  101. size = { AVATAR_SIZE } />
  102. <Text style = { styles.participantNameLabel as TextStyle }>
  103. { this.props._participantDisplayName }
  104. </Text>
  105. </View>
  106. );
  107. }
  108. /**
  109. * Callback to hide the {@code RemoteVideoMenu}.
  110. *
  111. * @private
  112. * @returns {boolean}
  113. */
  114. _onCancel() {
  115. this.props.dispatch(hideSheet());
  116. }
  117. }
  118. /**
  119. * Function that maps parts of Redux state tree into component props.
  120. *
  121. * @param {Object} state - Redux state.
  122. * @private
  123. * @returns {IProps}
  124. */
  125. function _mapStateToProps(state: IReduxState) {
  126. const { disableSelfDemote } = state['features/base/config'];
  127. const participant = getLocalParticipant(state);
  128. return {
  129. _participant: participant,
  130. _participantDisplayName: getParticipantDisplayName(state, participant?.id ?? ''),
  131. _showDemote: !disableSelfDemote && getParticipantCount(state) > 1
  132. };
  133. }
  134. export default translate(connect(_mapStateToProps)(LocalVideoMenu));