Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RaiseHandButton.tsx 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import React, { Component } from 'react';
  2. import { Text } from 'react-native-paper';
  3. import { connect } from 'react-redux';
  4. import { createToolbarEvent } from '../../../analytics/AnalyticsEvents';
  5. import { sendAnalytics } from '../../../analytics/functions';
  6. import { IReduxState } from '../../../app/types';
  7. import { RAISE_HAND_ENABLED } from '../../../base/flags/constants';
  8. import { getFeatureFlag } from '../../../base/flags/functions';
  9. import { translate } from '../../../base/i18n/functions';
  10. import { raiseHand } from '../../../base/participants/actions';
  11. import {
  12. getLocalParticipant,
  13. hasRaisedHand
  14. } from '../../../base/participants/functions';
  15. import { ILocalParticipant } from '../../../base/participants/types';
  16. import { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  17. import Button from '../../../base/ui/components/native/Button';
  18. import { BUTTON_TYPES } from '../../../base/ui/constants.native';
  19. import styles from './styles';
  20. /**
  21. * The type of the React {@code Component} props of {@link RaiseHandButton}.
  22. */
  23. interface IProps extends AbstractButtonProps {
  24. /**
  25. * Whether this button is enabled or not.
  26. */
  27. _enabled: boolean;
  28. /**
  29. * The local participant.
  30. */
  31. _localParticipant?: ILocalParticipant;
  32. /**
  33. * Whether the participant raused their hand or not.
  34. */
  35. _raisedHand: boolean;
  36. /**
  37. * Used to close the overflow menu after raise hand is clicked.
  38. */
  39. onCancel: Function;
  40. }
  41. /**
  42. * An implementation of a button to raise or lower hand.
  43. */
  44. class RaiseHandButton extends Component<IProps> {
  45. accessibilityLabel = 'toolbar.accessibilityLabel.raiseHand';
  46. label = 'toolbar.raiseYourHand';
  47. toggledLabel = 'toolbar.lowerYourHand';
  48. /**
  49. * Initializes a new {@code RaiseHandButton} instance.
  50. *
  51. * @param {IProps} props - The React {@code Component} props to initialize
  52. * the new {@code RaiseHandButton} instance with.
  53. */
  54. constructor(props: IProps) {
  55. super(props);
  56. // Bind event handlers so they are only bound once per instance.
  57. this._onClick = this._onClick.bind(this);
  58. this._toggleRaisedHand = this._toggleRaisedHand.bind(this);
  59. this._getLabel = this._getLabel.bind(this);
  60. }
  61. /**
  62. * Handles clicking / pressing the button.
  63. *
  64. * @returns {void}
  65. */
  66. _onClick() {
  67. this._toggleRaisedHand();
  68. this.props.onCancel();
  69. }
  70. /**
  71. * Toggles the rased hand status of the local participant.
  72. *
  73. * @returns {void}
  74. */
  75. _toggleRaisedHand() {
  76. const enable = !this.props._raisedHand;
  77. sendAnalytics(createToolbarEvent('raise.hand', { enable }));
  78. this.props.dispatch(raiseHand(enable));
  79. }
  80. /**
  81. * Gets the current label, taking the toggled state into account. If no
  82. * toggled label is provided, the regular label will also be used in the
  83. * toggled state.
  84. *
  85. * @returns {string}
  86. */
  87. _getLabel() {
  88. const { _raisedHand, t } = this.props;
  89. return t(_raisedHand ? this.toggledLabel : this.label);
  90. }
  91. /**
  92. * Renders the "raise hand" emoji.
  93. *
  94. * @returns {ReactElement}
  95. */
  96. _renderRaiseHandEmoji() {
  97. return (
  98. <Text>✋</Text>
  99. );
  100. }
  101. /**
  102. * Implements React's {@link Component#render()}.
  103. *
  104. * @inheritdoc
  105. * @returns {ReactElement}
  106. */
  107. render() {
  108. const { _enabled } = this.props;
  109. if (!_enabled) {
  110. return null;
  111. }
  112. return (
  113. <Button
  114. accessibilityLabel = { this.accessibilityLabel }
  115. icon = { this._renderRaiseHandEmoji }
  116. labelKey = { this._getLabel() }
  117. onClick = { this._onClick }
  118. style = { styles.raiseHandButton }
  119. type = { BUTTON_TYPES.SECONDARY } />
  120. );
  121. }
  122. }
  123. /**
  124. * Maps part of the Redux state to the props of this component.
  125. *
  126. * @param {Object} state - The Redux state.
  127. * @private
  128. * @returns {IProps}
  129. */
  130. function _mapStateToProps(state: IReduxState) {
  131. const _localParticipant = getLocalParticipant(state);
  132. const enabled = getFeatureFlag(state, RAISE_HAND_ENABLED, true);
  133. return {
  134. _enabled: enabled,
  135. _localParticipant,
  136. _raisedHand: hasRaisedHand(_localParticipant)
  137. };
  138. }
  139. export default translate(connect(_mapStateToProps)(RaiseHandButton));