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.

SharedVideoMenu.tsx 4.0KB

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