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.

RaiseHandButton.js 4.2KB

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