2021-08-04 08:51:05 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { Text, View } from 'react-native';
|
|
|
|
import { Divider } from 'react-native-paper';
|
|
|
|
|
|
|
|
import { Avatar } from '../../../base/avatar';
|
2022-06-20 14:53:19 +00:00
|
|
|
import { BottomSheet, hideSheet } from '../../../base/dialog';
|
2022-06-14 10:20:16 +00:00
|
|
|
import { bottomSheetStyles } from '../../../base/dialog/components/native/styles';
|
2021-08-04 08:51:05 +00:00
|
|
|
import {
|
|
|
|
getParticipantById,
|
|
|
|
getParticipantDisplayName
|
|
|
|
} from '../../../base/participants';
|
|
|
|
import { connect } from '../../../base/redux';
|
|
|
|
import { SharedVideoButton } from '../../../shared-video/components';
|
|
|
|
|
|
|
|
import styles from './styles';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Size of the rendered avatar in the menu.
|
|
|
|
*/
|
|
|
|
const AVATAR_SIZE = 24;
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Redux dispatch function.
|
|
|
|
*/
|
|
|
|
dispatch: Function,
|
|
|
|
|
|
|
|
/**
|
2021-08-20 23:32:38 +00:00
|
|
|
* The ID of the participant for which this menu opened for.
|
2021-08-04 08:51:05 +00:00
|
|
|
*/
|
2021-08-20 23:32:38 +00:00
|
|
|
participantId: string,
|
2021-08-04 08:51:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* True if the menu is currently open, false otherwise.
|
|
|
|
*/
|
|
|
|
_isOpen: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the participant is present in the room or not.
|
|
|
|
*/
|
|
|
|
_isParticipantAvailable?: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display name of the participant retrieved from Redux.
|
|
|
|
*/
|
|
|
|
_participantDisplayName: string,
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class to implement a popup menu that opens upon long pressing a fake participant thumbnail.
|
|
|
|
*/
|
|
|
|
class SharedVideoMenu extends PureComponent<Props> {
|
|
|
|
/**
|
|
|
|
* Constructor of the component.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this._onCancel = this._onCancel.bind(this);
|
|
|
|
this._renderMenuHeader = this._renderMenuHeader.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements {@code Component#render}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
_isParticipantAvailable,
|
2021-08-20 23:32:38 +00:00
|
|
|
participantId
|
2021-08-04 08:51:05 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const buttonProps = {
|
|
|
|
afterClick: this._onCancel,
|
|
|
|
showLabel: true,
|
2021-08-20 23:32:38 +00:00
|
|
|
participantID: participantId,
|
2022-06-14 10:20:16 +00:00
|
|
|
styles: bottomSheetStyles.buttons
|
2021-08-04 08:51:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BottomSheet
|
|
|
|
renderHeader = { this._renderMenuHeader }
|
|
|
|
showSlidingView = { _isParticipantAvailable }>
|
|
|
|
<Divider style = { styles.divider } />
|
|
|
|
<SharedVideoButton { ...buttonProps } />
|
|
|
|
</BottomSheet>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to hide the {@code SharedVideoMenu}.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_onCancel() {
|
2022-06-20 14:53:19 +00:00
|
|
|
this.props.dispatch(hideSheet());
|
2021-08-04 08:51:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to render the menu's header.
|
|
|
|
*
|
|
|
|
* @returns {React$Element}
|
|
|
|
*/
|
|
|
|
_renderMenuHeader() {
|
2022-06-14 10:20:16 +00:00
|
|
|
const { participantId } = this.props;
|
2021-08-04 08:51:05 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<View
|
|
|
|
style = { [
|
2022-06-14 10:20:16 +00:00
|
|
|
bottomSheetStyles.sheet,
|
2021-08-04 08:51:05 +00:00
|
|
|
styles.participantNameContainer ] }>
|
|
|
|
<Avatar
|
2021-08-20 23:32:38 +00:00
|
|
|
participantId = { participantId }
|
2021-08-04 08:51:05 +00:00
|
|
|
size = { AVATAR_SIZE } />
|
|
|
|
<Text style = { styles.participantNameLabel }>
|
|
|
|
{ this.props._participantDisplayName }
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that maps parts of Redux state tree into component props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @param {Object} ownProps - Properties of component.
|
|
|
|
* @private
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state, ownProps) {
|
2021-08-20 23:32:38 +00:00
|
|
|
const { participantId } = ownProps;
|
|
|
|
const isParticipantAvailable = getParticipantById(state, participantId);
|
2021-08-04 08:51:05 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
_isParticipantAvailable: Boolean(isParticipantAvailable),
|
2021-08-20 23:32:38 +00:00
|
|
|
_participantDisplayName: getParticipantDisplayName(state, participantId)
|
2021-08-04 08:51:05 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-20 14:53:19 +00:00
|
|
|
export default connect(_mapStateToProps)(SharedVideoMenu);
|