2022-04-08 12:24:58 +00:00
|
|
|
import * as React from 'react';
|
2019-01-28 14:55:37 +00:00
|
|
|
import { Text, View } from 'react-native';
|
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState } from '../../../app/types';
|
2019-01-28 14:55:37 +00:00
|
|
|
import {
|
2020-06-12 10:15:16 +00:00
|
|
|
getParticipantById,
|
2022-10-07 12:30:57 +00:00
|
|
|
getParticipantDisplayName,
|
|
|
|
isScreenShareParticipant
|
2022-04-08 12:24:58 +00:00
|
|
|
} from '../../../base/participants/functions';
|
|
|
|
import { connect } from '../../../base/redux/functions';
|
2019-01-28 14:55:37 +00:00
|
|
|
|
2022-07-18 13:16:08 +00:00
|
|
|
// @ts-ignore
|
2019-01-28 14:55:37 +00:00
|
|
|
import styles from './styles';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The name of the participant to render.
|
|
|
|
*/
|
2022-04-08 12:24:58 +00:00
|
|
|
_participantName: string;
|
2019-01-28 14:55:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* True of the label needs to be rendered. False otherwise.
|
|
|
|
*/
|
2022-04-08 12:24:58 +00:00
|
|
|
_render: boolean;
|
2019-04-11 10:04:50 +00:00
|
|
|
|
2022-02-14 10:13:18 +00:00
|
|
|
/**
|
2022-07-14 07:10:08 +00:00
|
|
|
* Whether or not the name is in a container.
|
2022-02-14 10:13:18 +00:00
|
|
|
*/
|
2022-04-08 12:24:58 +00:00
|
|
|
contained?: boolean;
|
2022-02-14 10:13:18 +00:00
|
|
|
|
2019-04-11 10:04:50 +00:00
|
|
|
/**
|
|
|
|
* The ID of the participant to render the label for.
|
|
|
|
*/
|
2022-04-08 12:24:58 +00:00
|
|
|
participantId: string;
|
2022-09-08 09:52:36 +00:00
|
|
|
};
|
2019-01-28 14:55:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders a label with the display name of the on-stage participant.
|
|
|
|
*/
|
2022-04-08 12:24:58 +00:00
|
|
|
class DisplayNameLabel extends React.Component<Props> {
|
2019-01-28 14:55:37 +00:00
|
|
|
/**
|
|
|
|
* Implements {@code Component#render}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
if (!this.props._render) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-02-14 10:13:18 +00:00
|
|
|
<View style = { this.props.contained ? styles.displayNamePadding : styles.displayNameBackdrop }>
|
|
|
|
<Text
|
|
|
|
numberOfLines = { 1 }
|
|
|
|
style = { styles.displayNameText }>
|
2019-01-28 14:55:37 +00:00
|
|
|
{ this.props._participantName }
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps part of the Redux state to the props of this component.
|
|
|
|
*
|
2022-04-08 12:24:58 +00:00
|
|
|
* @param {any} state - The Redux state.
|
2019-04-11 10:04:50 +00:00
|
|
|
* @param {Props} ownProps - The own props of the component.
|
2022-04-08 12:24:58 +00:00
|
|
|
* @returns {Props}
|
2019-01-28 14:55:37 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
function _mapStateToProps(state: IReduxState, ownProps: Partial<Props>) {
|
2022-09-06 17:32:20 +00:00
|
|
|
const participant = getParticipantById(state, ownProps.participantId ?? '');
|
2019-01-28 14:55:37 +00:00
|
|
|
|
|
|
|
return {
|
2022-09-06 17:32:20 +00:00
|
|
|
_participantName: getParticipantDisplayName(state, ownProps.participantId ?? ''),
|
2022-10-07 12:30:57 +00:00
|
|
|
_render: participant && (!participant?.local || ownProps.contained)
|
|
|
|
&& (!participant?.fakeParticipant || isScreenShareParticipant(participant))
|
2019-01-28 14:55:37 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(_mapStateToProps)(DisplayNameLabel);
|