2021-07-13 06:50:08 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { Component } from 'react';
|
2022-07-07 12:29:18 +00:00
|
|
|
import { Text } from 'react-native-paper';
|
2021-07-13 06:50:08 +00:00
|
|
|
import { type Dispatch } from 'redux';
|
|
|
|
|
|
|
|
import {
|
|
|
|
createToolbarEvent,
|
|
|
|
sendAnalytics
|
|
|
|
} from '../../../analytics';
|
2022-05-05 09:57:05 +00:00
|
|
|
import { RAISE_HAND_ENABLED, getFeatureFlag } from '../../../base/flags';
|
2021-07-13 06:50:08 +00:00
|
|
|
import { translate } from '../../../base/i18n';
|
|
|
|
import {
|
|
|
|
getLocalParticipant,
|
2021-10-21 09:40:57 +00:00
|
|
|
hasRaisedHand,
|
2021-07-13 06:50:08 +00:00
|
|
|
raiseHand
|
|
|
|
} from '../../../base/participants';
|
2022-07-07 12:29:18 +00:00
|
|
|
import Button from '../../../base/react/components/native/Button';
|
|
|
|
import { BUTTON_TYPES } from '../../../base/react/constants';
|
2021-07-13 06:50:08 +00:00
|
|
|
import { connect } from '../../../base/redux';
|
|
|
|
import { type AbstractButtonProps } from '../../../base/toolbox/components';
|
|
|
|
|
2022-07-07 12:29:18 +00:00
|
|
|
import styles from './styles';
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link RaiseHandButton}.
|
|
|
|
*/
|
|
|
|
type Props = AbstractButtonProps & {
|
|
|
|
|
2022-05-05 09:57:05 +00:00
|
|
|
/**
|
|
|
|
* Whether this button is enabled or not.
|
|
|
|
*/
|
|
|
|
_enabled: boolean,
|
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
/**
|
|
|
|
* The local participant.
|
|
|
|
*/
|
|
|
|
_localParticipant: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the participant raused their hand or not.
|
|
|
|
*/
|
|
|
|
_raisedHand: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The redux {@code dispatch} function.
|
|
|
|
*/
|
|
|
|
dispatch: Dispatch<any>,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Used for translation.
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
|
|
|
t: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to close the overflow menu after raise hand is clicked.
|
|
|
|
*/
|
2022-07-07 12:29:18 +00:00
|
|
|
onCancel: Function
|
2021-07-13 06:50:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An implementation of a button to raise or lower hand.
|
|
|
|
*/
|
|
|
|
class RaiseHandButton extends Component<Props, *> {
|
|
|
|
accessibilityLabel = 'toolbar.accessibilityLabel.raiseHand';
|
|
|
|
label = 'toolbar.raiseYourHand';
|
|
|
|
toggledLabel = 'toolbar.lowerYourHand';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new {@code RaiseHandButton} instance.
|
|
|
|
*
|
|
|
|
* @param {Props} props - The React {@code Component} props to initialize
|
|
|
|
* the new {@code RaiseHandButton} instance with.
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once per instance.
|
|
|
|
this._onClick = this._onClick.bind(this);
|
|
|
|
this._toggleRaisedHand = this._toggleRaisedHand.bind(this);
|
|
|
|
this._getLabel = this._getLabel.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onClick: () => void;
|
|
|
|
|
|
|
|
_toggleRaisedHand: () => void;
|
|
|
|
|
|
|
|
_getLabel: () => string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles clicking / pressing the button.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onClick() {
|
|
|
|
this._toggleRaisedHand();
|
|
|
|
this.props.onCancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggles the rased hand status of the local participant.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_toggleRaisedHand() {
|
|
|
|
const enable = !this.props._raisedHand;
|
|
|
|
|
|
|
|
sendAnalytics(createToolbarEvent('raise.hand', { enable }));
|
|
|
|
|
|
|
|
this.props.dispatch(raiseHand(enable));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the current label, taking the toggled state into account. If no
|
|
|
|
* toggled label is provided, the regular label will also be used in the
|
|
|
|
* toggled state.
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
_getLabel() {
|
|
|
|
const { _raisedHand, t } = this.props;
|
|
|
|
|
|
|
|
return t(_raisedHand ? this.toggledLabel : this.label);
|
|
|
|
}
|
|
|
|
|
2022-07-07 12:29:18 +00:00
|
|
|
/**
|
|
|
|
* Renders the "raise hand" emoji.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderRaiseHandEmoji() {
|
|
|
|
return (
|
|
|
|
<Text>✋</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2022-07-07 12:29:18 +00:00
|
|
|
const { _enabled } = this.props;
|
2022-05-05 09:57:05 +00:00
|
|
|
|
|
|
|
if (!_enabled) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
return (
|
2022-07-07 12:29:18 +00:00
|
|
|
<Button
|
|
|
|
accessibilityLabel = { this.accessibilityLabel }
|
|
|
|
icon = { this._renderRaiseHandEmoji }
|
|
|
|
label = { this._getLabel() }
|
2021-07-13 06:50:08 +00:00
|
|
|
onPress = { this._onClick }
|
2022-07-07 12:29:18 +00:00
|
|
|
style = { styles.raiseHandButton }
|
|
|
|
type = { BUTTON_TYPES.SECONDARY } />
|
2021-07-13 06:50:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps part of the Redux state to the props of this component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state): Object {
|
|
|
|
const _localParticipant = getLocalParticipant(state);
|
2022-05-05 09:57:05 +00:00
|
|
|
const enabled = getFeatureFlag(state, RAISE_HAND_ENABLED, true);
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
return {
|
2022-05-05 09:57:05 +00:00
|
|
|
_enabled: enabled,
|
2021-07-13 06:50:08 +00:00
|
|
|
_localParticipant,
|
2022-07-07 12:29:18 +00:00
|
|
|
_raisedHand: hasRaisedHand(_localParticipant)
|
2021-07-13 06:50:08 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps)(RaiseHandButton));
|